//// //// Copyright (c) Ricoh Corporation. All rights reserved //// //// File Name: //// //// rcUsbBidi.js //// //// Abstract: //// //// Ricoh USBMON Javascript extension file for v4 printer class drivers. //// //// Get the requested Schema(s) //// //// @param scriptContext - Script context object which allows access to IPrinterScriptablePropertyBag for printer driver and queue properties //// @param printerStream - Allows the script to Write/Read data from the attached USB device //// @param schemaRequests - Contains all the requested Query Keys. //// @param printerBidiSchemaResponses - Object the script will use to store all responses to query keys //// //// @return Integer value - currently only JavaScript exceptions are expected for failures //// //// The script can use the schemaRequests object to iterate through the Query Keys requested by the user. Based on the query keys //// the script should use the printerStream object to communicate with the USB print device and determine the values of one or more Bidi //// Schema elements. For each Bidi Schema element the new value can be returned to the caller by using functions of the printerBidiSchemaResponses //// object. //// //// The scriptContext object provides access to the Driver and Queue prorperty bags associated with the current device. These property bags support read-only access. //// /*jslint unparam: true, sloppy: true, vars: true, white: true, plusplus: true, maxerr: 50, indent: 4 */ function getSchemas(scriptContext, printerStream, schemaRequests, printerBidiSchemaResponses) { var retVal = 0; var index = 0; for (index = 0; index < schemaRequests.length; index++) { var key = schemaRequests[index]; if (key === "Configuration") { var queryDuplexStr = "@PJL INQUIRE DUPLEX\r\n"; var queryColorStr = "@PJL INQUIRE DATAMODE\r\n"; var queryStapleStr = "@PJL INQUIRE STAPLE\r\n"; var queryPunchStr = "@PJL INQUIRE PUNCH\r\n"; var unknownStr = "\"?\"\r\n"; var i = 0; ////Build "%-12345X@PJL\r\n@PJL INQUIRE DUPLEX\r\n@PJL INQUIRE DATAMODE\r\n@PJL INQUIRE STAPLE\r\n@PJL INQUIRE PUNCH\r\n%-12345X"; ////header: %-12345X@PJL\r\n var writeData = [0x1B, 0x25, 0x2D, 0x31, 0x32, 0x33, 0x34, 0x35, 0x58, 0x40, 0x50, 0x4A, 0x4C, 0x0D, 0x0A]; var queryStr = queryDuplexStr + queryColorStr + queryStapleStr + queryPunchStr; for (i = 0; i < queryStr.length; i++) { writeData.push(queryStr.charCodeAt(i)); } ////tail: %-12345X writeData = writeData.concat(0x1B, 0x25, 0x2D, 0x31, 0x32, 0x33, 0x34, 0x35, 0x58); ////Write data to Device var bytesWritten = printerStream.write(writeData); var duplexInstalled = true; var colorSupported = true; var punchSupported = true; var stapleSupported = true; if (bytesWritten === writeData.length) { ////Read from Device var readBuffer = printerStream.read(1024); var bytesRead = readBuffer.length; var readString = ""; for (i = 0; (bytesRead > 0) && (i < bytesRead); i++) { readString += String.fromCharCode(readBuffer.shift()); } ////Detect supported features if (readString.length > 0) { if (readString.indexOf(queryDuplexStr + unknownStr, 0) >= 0) { duplexInstalled = false; } if (readString.indexOf(queryColorStr + unknownStr, 0) >= 0) { colorSupported = false; } if (readString.indexOf(queryPunchStr + unknownStr, 0) >= 0) { punchSupported = false; } if (readString.indexOf(queryStapleStr + unknownStr, 0) >= 0) { stapleSupported = false; } } } printerBidiSchemaResponses.addBool("\\Printer.Configuration.DuplexSupport:Installed", duplexInstalled); printerBidiSchemaResponses.addBool("\\Printer.Configuration.ColorSupport:Installed", colorSupported); printerBidiSchemaResponses.addBool("\\Printer.Finishing.PunchingSupport:Installed", punchSupported); printerBidiSchemaResponses.addBool("\\Printer.Finishing.StaplingSupport:Installed", stapleSupported); } } return retVal; }