//// //// Canon Inkjet Printer Driver for Microsoft Windows //// Version 3.00 //// Copyright CANON INC. 2013 All Rights Reserved //// function getSchemas(driverProperties, printerStream, schemaRequests, printerSchemaResponses) { var nRetVal = 0; var index = 0; var bFlagStatus = false; var statusResponse = ''; var key = ''; var requestSchema = ''; if( printerStream === null || schemaRequests === null || printerSchemaResponses === null ) { return nRetVal; } for ( index = 0; index < schemaRequests.length; index++ ) { key = schemaRequests[index]; if (key === '\\Printer.Canon.IJ.Info.ReadData:Value' || key === '\\Printer.Canon.IJ.Info.GetStatus:Value' || key === '\\Printer.Status.Summary:State' || key === '\\Printer.Status.Summary:StateReason' ) { bFlagStatus = true; } if (bFlagStatus) { break; } } if(bFlagStatus) { statusResponse = getStatusResponse(printerStream); } else { return nRetVal; } for ( index = 0; index < schemaRequests.length; index++ ) { requestSchema = schemaRequests[index]; if ( requestSchema === '\\Printer.Canon.IJ.Info.ReadData:Value' || requestSchema === '\\Printer.Canon.IJ.Info.GetStatus:Value' || requestSchema === '\\Printer.Status.Summary:State' || requestSchema === '\\Printer.Status.Summary:StateReason' ) { setStatusSchemaResponse(requestSchema, statusResponse, printerSchemaResponses); } } return nRetVal; } function setSchema( driverProperties, printerStream, printerSchemaElement ) { var nRetVal = 0; var writeData = []; if( printerStream === null || printerSchemaElement === null ) { return nRetVal; } if( printerSchemaElement.name === '\\Printer.Canon.IJ.Info.SendRAWData:Value' ) { var receiveData = printerSchemaElement.value; var nMaxSize = 3145728; if ( receiveData.length > 0 && receiveData.length <= nMaxSize ) { var anTempData =[]; var nValue = 0; var nCounter = 0; var nCodeValue = 0; for ( nCounter = 0; nCounter < receiveData.length; nCounter++ ) { nCodeValue = receiveData.charCodeAt( nCounter++ ); if ( nCodeValue >= 48 && nCodeValue <= 57 ) { nValue = ( nCodeValue - 48 ) << 4; } else if ( nCodeValue >= 65 && nCodeValue <= 70 ) { nValue = ( nCodeValue - 55 ) << 4; } else if ( nCodeValue >= 97 && nCodeValue <= 102 ) { nValue = ( nCodeValue - 87 ) << 4; } else { nRetVal = -1; break; } nCodeValue = receiveData.charCodeAt( nCounter ); if ( nCodeValue >= 48 && nCodeValue <= 57 ) { nValue += ( nCodeValue - 48 ); } else if ( nCodeValue >= 65 && nCodeValue <= 70 ) { nValue += ( nCodeValue - 55 ); } else if ( nCodeValue >= 97 && nCodeValue <= 102 ) { nValue += ( nCodeValue - 87 ); } else { nRetVal = -1; break; } anTempData.push( nValue ); } if( nCounter === receiveData.length ) { printerStream.write( writeData.concat( anTempData ) ); } } } else if( printerSchemaElement.name === '\\Printer.Canon.IJ.Command:CL' ) { writeData = [0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x4d, 0x6f, 0x64, 0x65, 0x3d, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0xa, 0x24, 0x4a, 0x6f, 0x62, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4d, 0x6e, 0x74, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa, 0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x40, 0x43, 0x6c, 0x65, 0x61, 0x6e, 0x69, 0x6e, 0x67, 0x3d, 0x31, 0x41, 0x4c, 0x4c, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa]; printerStream.write(writeData); } else if( printerSchemaElement.name === '\\Printer.Canon.IJ.Command:NC' ) { writeData = [0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x4d, 0x6f, 0x64, 0x65, 0x3d, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0xa, 0x24, 0x4a, 0x6f, 0x62, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4d, 0x6e, 0x74, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa, 0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x40, 0x54, 0x65, 0x73, 0x74, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x3d, 0x4e, 0x6f, 0x7a, 0x7a, 0x6c, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa]; printerStream.write(writeData); } else if( printerSchemaElement.name === '\\Printer.Canon.IJ.Command:NCFR' ) { writeData = [0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x4d, 0x6f, 0x64, 0x65, 0x3d, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0xa, 0x24, 0x4a, 0x6f, 0x62, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4d, 0x6e, 0x74, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa, 0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x40, 0x54, 0x65, 0x73, 0x74, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x3d, 0x4e, 0x6f, 0x7a, 0x7a, 0x6c, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x42, 0x69, 0x6e, 0x32, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa,]; printerStream.write(writeData); } else if( printerSchemaElement.name === '\\Printer.Canon.IJ.Command:NCRE' ) { writeData = [0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x4d, 0x6f, 0x64, 0x65, 0x3d, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0xa, 0x24, 0x4a, 0x6f, 0x62, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4d, 0x6e, 0x74, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa, 0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x40, 0x54, 0x65, 0x73, 0x74, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x3d, 0x4e, 0x6f, 0x7a, 0x7a, 0x6c, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x42, 0x69, 0x6e, 0x31, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa]; printerStream.write(writeData); } else if( printerSchemaElement.name === '\\Printer.Canon.IJ.Command:AR' ) { writeData = [0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x4d, 0x6f, 0x64, 0x65, 0x3d, 0x44, 0x72, 0x69, 0x76, 0x65, 0x72, 0xa, 0x24, 0x4a, 0x6f, 0x62, 0x54, 0x79, 0x70, 0x65, 0x3d, 0x4d, 0x6e, 0x74, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa, 0x1b, 0x5b, 0x4b, 0x2, 0x0, 0x0, 0x1f, 0x42, 0x4a, 0x4c, 0x53, 0x54, 0x41, 0x52, 0x54, 0xa, 0x40, 0x54, 0x65, 0x73, 0x74, 0x50, 0x72, 0x69, 0x6e, 0x74, 0x3d, 0x52, 0x65, 0x67, 0x69, 0x5f, 0x41, 0x75, 0x74, 0x6f, 0x31, 0xa, 0x42, 0x4a, 0x4c, 0x45, 0x4e, 0x44, 0xa]; printerStream.write(writeData); } return nRetVal; } function getStatus( driverProperties, printerStream, printerSchemaResponses ) { var nRetVal = 0; var statusResponse = ''; if( printerStream === null || printerSchemaResponses === null ) { return nRetVal; } statusResponse = getStatusResponse(printerStream); setStatusSchemaResponse('\\Printer.Canon.IJ.Info.ReadData:Value', statusResponse, printerSchemaResponses); setStatusSchemaResponse('\\Printer.Status.Summary:State', statusResponse, printerSchemaResponses); setStatusSchemaResponse('\\Printer.Status.Summary:StateReason', statusResponse, printerSchemaResponses); return nRetVal; } function readStream(printerStream) { var readString = ''; var anReadBuffer = []; var nReadBytes = 0; var nReadSize = 4097; anReadBuffer = printerStream.read(nReadSize); anReadBuffer.shift(); anReadBuffer.shift(); nReadBytes = anReadBuffer.length; for (var i = 0; i < nReadBytes; i++) { readString += String.fromCharCode(anReadBuffer.shift()); } if (readString !== '') { return readString.replace(/\n|\r|\t|\b/g, ''); } else { return ''; } } function getStatusResponse( printerStream ) { var response = ''; response = readStream(printerStream); return response; } function setStatusSchemaResponse( requestSchema, statusResponse, printerSchemaResponses ) { var nRetVal = 0; var state = 'Idle'; var stateReason = 'None'; var statusVal = ''; var stsDOC = ''; var stsDSC = ''; var stsDJS = ''; var stsDBS = ''; var stsDWS = ''; if ( typeof requestSchema !== 'string' || requestSchema === '' || typeof statusResponse !== 'string' || statusResponse === '' ) { return nRetVal; } if (requestSchema === '\\Printer.Canon.IJ.Info.GetStatus:Value') { printerSchemaResponses.addString('\\Printer.Canon.IJ.Info.GetStatus:Value', ""); } else if ( requestSchema === '\\Printer.Canon.IJ.Info.ReadData:Value' ) { statusVal = statusResponse; printerSchemaResponses.addString('\\Printer.Canon.IJ.Info.ReadData:Value', statusVal); } else if ( requestSchema === '\\Printer.Status.Summary:State' ) { statusVal = statusResponse; stsDOC = getStateVal(statusVal, 'DOC'); stsDSC = getStateVal(statusVal, 'DSC'); stsDJS = getStateVal(statusVal, 'DJS'); stsDBS = getStateVal(statusVal, 'DBS'); stsDWS = getStateVal(statusVal, 'DWS'); state = getState( stsDOC, stsDSC, stsDJS, stsDBS, stsDWS ); printerSchemaResponses.addString('\\Printer.Status.Summary:State', state); } else if ( requestSchema === '\\Printer.Status.Summary:StateReason' ) { statusVal = statusResponse; stsDWS = getStateVal(statusVal, 'DWS'); stsDOC = getStateVal(statusVal, 'DOC'); stsDSC = getStateVal(statusVal, 'DSC'); stateReason = getStateReason(stsDWS, stsDOC, stsDSC); printerSchemaResponses.addString('\\Printer.Status.Summary:StateReason', stateReason); } return nRetVal; } function getStateVal( statusVal, key ) { var retString = ''; var tempString = ''; var sub = ''; var pos1 = 0; var pos2 = 0; if( typeof key !== 'string' || key === '' || typeof statusVal !== 'string' || statusVal === '' ) { return ''; } if( key === 'DWS' ) { pos1 = statusVal.indexOf( key + ':' ); if( pos1 !== -1 ) { sub = statusVal.substring(pos1 + key.length + 1, statusVal.length); pos2 = sub.indexOf(';'); tempString = sub.substring(0, pos2); if( tempString.indexOf( '1900' ) !== -1) { retString = '1900'; } else { retString = 'NO'; } } else { retString = ''; } } else if (key === 'DOC') { pos1 = statusVal.indexOf( key + ':' ); if( pos1 !== -1 ) { sub = statusVal.substring(pos1 + key.length + 1, statusVal.length); pos2 = sub.indexOf(';'); sub = sub.substring(0, pos2); pos2 = sub.indexOf(',/,'); if (pos2 !== -1) { sub = sub.substring(0, pos2); } pos2 = sub.indexOf(','); sub = sub.substring(pos2 + 1, sub.length); pos2 = sub.indexOf(','); retString = sub.substring(pos2 + 1, sub.length); } else { retString = ''; } } else if (key === 'DJS' || key === 'DBS' || key === 'DSC') { pos1 = statusVal.indexOf( key + ':' ); if( pos1 !== -1 ) { sub = statusVal.substring(pos1 + key.length + 1, statusVal.length); pos2 = sub.indexOf(';'); retString = sub.substring(0, pos2); } else { retString = ''; } } else { retString = ''; } return retString; } function getState( stsDOC, stsDSC, stsDJS, stsDBS, stsDWS ) { var retState = ''; if( typeof stsDOC !== 'string' || stsDOC === '' || typeof stsDSC !== 'string' || stsDSC === '' || typeof stsDJS !== 'string' || stsDJS === '' || typeof stsDBS !== 'string' || stsDBS === '' || typeof stsDWS !== 'string' || stsDWS === '' ) { return ''; } if (stsDOC !== 'NO' || stsDSC !== 'NO' || stsDWS !== 'NO') { retState = 'Stopped'; } else if( (stsDOC === 'NO' && stsDSC === 'NO') && (stsDJS !== 'NO' || stsDBS !== 'NO') ) { retState = 'Processing'; } else { retState = 'Idle'; } return retState; } function getStateReason( stsDWS, stsDOC, stsDSC ) { var stateReason = ''; if( typeof stsDWS !== 'string' || stsDWS === '' || typeof stsDOC !== 'string' || stsDOC === '' || typeof stsDSC !== 'string' || stsDSC === '' ) { return ''; } if (stsDSC !== 'NO' || stsDOC !== 'NO') { stateReason = 'AttentionRequired'; } else if (stsDSC === 'NO' && stsDOC === 'NO' && stsDWS === '1900') { stateReason = 'Paused'; } else if (stsDSC === 'NO' && stsDOC === 'NO' && stsDWS === 'NO') { stateReason = 'None'; } else { stateReason = ''; } return stateReason; }