////---------------------------------------------------------------------------------------- //// //// OKI V4 Class Driver : USB Bidi JavaScript //// //// Copyright (C) 2011 Oki Data Corporation //// ////---------------------------------------------------------------------------------------- /// 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. /// function getSchemas( driverProperties, printerStream, schemaRequests, printerBidiSchemaResponses ) { var retVal = 0; // Loop through all the QueryKeys provided in the schemaRequests object for (var index = 0; index < schemaRequests.length; index++) { var key = schemaRequests[index]; // Process the "Configuration" Query key if (key === "Configuration") { var arrayUEL = [0x1B, 0x25, 0x2D, 0x31, 0x32, 0x33, 0x34, 0x35, 0x58]; var strQueryPJL = "@PJL INFO CONFIG\r\n"; var writeBuffer = []; var bytesWritten = 0; var i = 0; var strDuplex = "DUPLEX\r\n"; var strTray2 = "\tINTRAY3\r\n"; var strTray3 = "\tINTRAY5\r\n"; var strTray4 = "\tINTRAY6\r\n"; var strTray5 = "\tINTRAY7\r\n"; var boolDuplexInstalled = false; var boolTray2Installed = false; var boolTray3Installed = false; var boolTray4Installed = false; var boolTray5Installed = false; for (i = 0; i < arrayUEL.length; i++) { // Copy UEL data to Write Buffer writeBuffer[i] = arrayUEL[i]; } for (i = 0; i < strQueryPJL.length; i++) { // Convert String to Character Code (Byte Data) writeBuffer.push(strQueryPJL.charCodeAt(i)); } writeBuffer = writeBuffer.concat(arrayUEL); // Send Commands bytesWritten = printerStream.write(writeBuffer); if (bytesWritten === writeBuffer.length) { // Get Result var readBuffer = printerStream.read(1024); var bytesRead = readBuffer.length; var strReadData = ""; for (i = 0; (bytesRead > 0) && (i < bytesRead); i++) { // Convert Character Code to String strReadData += String.fromCharCode(readBuffer.shift()); } if (strReadData.length > 0) { // Update "Duplex" Setting if (strReadData.indexOf(strDuplex, 0) >= 0) { boolDuplexInstalled = true; } printerBidiSchemaResponses.addBool("\\Printer.Configuration.DuplexUnit:Installed", boolDuplexInstalled); // Update "2nd Tray" Setting if (strReadData.indexOf(strTray2, 0) >= 0) { boolTray2Installed = true; } printerBidiSchemaResponses.addBool("\\Printer.Layout.InputBins.Tray2:Installed", boolTray2Installed); // Update "3rd Tray" Setting if (strReadData.indexOf(strTray3, 0) >= 0) { boolTray3Installed = true; } printerBidiSchemaResponses.addBool("\\Printer.Layout.InputBins.Tray3:Installed", boolTray3Installed); // Update "4th Tray" Setting if (strReadData.indexOf(strTray4, 0) >= 0) { boolTray4Installed = true; } printerBidiSchemaResponses.addBool("\\Printer.Layout.InputBins.Tray4:Installed", boolTray4Installed); // Update "5th Tray" Setting if (strReadData.indexOf(strTray5, 0) >= 0) { boolTray5Installed = true; } printerBidiSchemaResponses.addBool("\\Printer.Layout.InputBins.Tray5:Installed", boolTray5Installed); } } } } return retVal; } /// /// Set a requested Bidi Schema Value in the device /// /// @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 printerBidiSchemaElement - Contains all the data associated with the Bidi Schema Value to set /// /// @return Integer value - currently only JavaScript exceptions are expected for failures /// /// The script can interpret the incoming Bidi Schema value to either set data in the device or perform an action on the device. /// /// The scriptContext object provides access to the Driver and Queue prorperty bags associated with the current device. These property bags support read-only access. /// function setSchema( driverProperties, printerStream, printerBidiSchemaElement ) { var retVal = 0; return retVal; } /// /// Retrieve unsolicited Bidi Schema value updates from the USB device during printing /// /// @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 printerBidiSchemaResponses - Object the script will use to store all responses to query keys /// /// @return Integer value - currently only JavaScript exceptions are expected for failures /// /// This function is only called when a job is printing. A device can provide data on the read channel which this script can interpret into /// Bidi Schema values and returned to USBMon. /// /// This function will be called repeatedly during printing. It is expected the device will only return data if it is available and the script can understand it. /// /// Calling the write function on the printerStream object will fail. This device is opened read-only for this function. /// /// The scriptContext object provides access to the Driver and Queue prorperty bags associated with the current device. These property bags support read-only access. /// function getStatus( driverProperties, printerStream, printerBidiSchemaResponses ) { var retVal = 0; return retVal; }