background image

    

 

Ref: "Ap1400ProgGuide1_2.docx"  

 

Page 37 of 42 

Document Revision: “1.2”  

 

Document Date: “9 Apr. 2013”

 

SendData

 

Send data to a device 

Prototype 
 

int

   

WINAPI SendData(

int

  

iHandle, 

 

 

 

 

 

  LPCTSTR 

pData, 

 

 

 

 

 

  LPINT 

pDataLen, 

 

 

 

 

 

  

int

   

iTimeout); 

 
Description. 

Sends data to a device with flow control. There is no practical limit on the amount of 
data that can be sent, but the call is synchronous and will not return until either the 
data send is completed, a timeout occurs, or an error occurs. Data is sent over a 
bulk endpoint which has a buffer size of 64 bytes. Data longer than this is 
transmitted in full 64 byte packets and flow control is checked between each 
packet. Where the receiver buffer is full the function will wait for a CTS signal for a 
period not exceeding the value in iTimeout. When CTS is set then the timeout value 
is reset to zero. 
 

Arguments  

ihandle – The handle of an open device. This handle must have been issued by a 

previous call to OpenDevice. 

pData -  Pointer to a buffer containing the data to transmit. All data in the buffer up 

to pDataLen is transmitted including any NULL characters. 

pDataLen- 
 

Pointer to an integer containing the length of the data to transmit. 

 

This value is modified to show the actual amount of data that was 
successfully transmitted. If a timeout(or other error) occurs during 
transmission, this value can be used to establish a restart point. 

 

 

iTimeout- 

The timeout value in milliseconds. The timeout countdown will only start 
when a buffer full, or other blocking condition occurs. Should this condition 
clear during the timeout period, then the period is reset. 

 
Returns 

ERROR_SUCCESS if successful, otherwise the value is set to the system error 
code. 

 

Example 

 

 

CString 

m_csData=_T(“This is a data packet”); 

 

 

TRACE(_T(

"Sending %d bytes of data.\n"

),m_csData.GetLength()); 

 

 

int

   

iLen=m_csData.GetLength(); 

 

 

DWORD   

m_dwStatusCode=SendData(m_iPrinterHandle, 

m_csData,&iLen,1000); 

 

 

//Check return

 

 

 

if

(m_dwStatusCode!=ERROR_SUCCESS) 

 

 

 

 

 

CString 

 

csError; 

 

 

 

csError.Format(_T(

"SendData Failed - Reason=%d."

), 

m_dwStatusCode)); 

 

 

 

AfxMessageBox(csError,MB_ICONSTOP|MB_OK); 

 

 

 

 
 

 

Summary of Contents for Ap1400

Page 1: ...xperts in Small Printer Solutions Programmer Guide Ap1400 Thermal Printer Able Systems Limited Denton Drive Northwich Cheshire CW9 7TU England Tel 44 0 1606 48621 Fax 44 0 1606 44903 Web www able systems com ...

Page 2: ...es Received 9 Graphics Commands 10 Formatting Commands 11 Formatting Commands Continued 12 Initialise and Request Status Commands 13 Initialise and Request Status Commands Continued 14 Barcode Commands 15 Mark Sense Operation 15 Reserved Commands 15 Codes Transmitted 16 5 Settings and Configuration 17 Setting Configuration Information 17 Saving Configuration Information 19 Querying Configuration I...

Page 3: ...r Notes on Printer Firmware Revisions Including Flash Able Systems reserves the right to modify and improve the firmware in its products at any time Whilst every effort is made to ensure backward compatibility no guarantee in this respect is given or implied These products include a flash re programmable microcontroller This allows firmware upgrades under customer control A Flash Programming Utili...

Page 4: ...ers idle mode Double clicking means pressing and releasing twice in quick succession in a similar manner to a PC mouse Some functions of the paper feed button can be invoked or disabled by the host The button is also disabled for 0 25 seconds after each data byte is received to prevent the user from prematurely printing partial lines Data from the host will generally be continuous Printing Method ...

Page 5: ...er can be pre configured to operate in 32 48 42 or 24 Char Line modes as applicable If required Font Mode changes may be disabled See the section on SETTING INTERNAL CONFIGURATION INFORMATION for details User Font This mode gives access to a single User Font programmed into the printer s non volatile memory using the Flash Programming Utility The format of the characters in the User Font is define...

Page 6: ...12V to indicate a reset condition or wait state Some battery powered host equipment present the same output signal when they go to sleep By default the printer will interpret this condition as a repetitive receive error and will print multiple characters to indicate the fault If required the printer may be set to ignore this condition Data Buffer and Flow Control The printer has a nominal 10k byte...

Page 7: ...rinter command set is available to the user allowing much tighter tailoring of the printed output to suit this form of printer application combination To use the API Interface you will need to install the following LIBUSB USBPrintDLL Please refer to section 7 for details on how to install the correct driver for your application Paper Out Paper Low and Head Up Sensors The Ap1400 series printers typ...

Page 8: ...n settings Newly set values for the Baud rate parity data and stop bit parameters are not implemented until the printer has been cycled Command Description Format In the explanations that follow commonly recognised labels have been used e g LF CR FF ESC command parameters are given as equivalent ASCII characters e g J or as hexadecimal hex values e g 4AH or decimal numbers e g 74 or n which are si...

Page 9: ...double click demo mode default condition Other bits are ignored the double click demo mode only functions if the paper feed button is enabled ESC X 1BH 58H m eXtended Commands special to Able N See the section SETTING INTERNAL CONFIGURATION INFORMATION below for format ESC 1BH 21H n Select printing mode N The third byte n is interpreted as follows bit 0 Select Font Mode 0 to 4 bit 1 Mode 0 is fact...

Page 10: ...drupled in both axes to 0 5 mm square Successive rows of 8 dot graphics can be printed contiguously in the vertical direction only in Font Modes 0 1 or 2 or a User Font which is 32 dots high When the third byte m 32 20H Plain 24 dot graphics k 3 x n1 256 n2 Each 24 dot vertical column is encoded as three successive bytes Bytes d1 d4 d7 etc are at the top of the 24 dot vertical columns The printed ...

Page 11: ...until cleared or the printer is powered off ESC J 1BH 4AH n Print and feed extra paper n is the count of notional 1 20th print lines to be fed This command terminates the current line n is divided by 20 remainder discarded and the quotient used as a count of additional blank single height character lines ESC 1BH 24H n1 n2 Set absolute print position Position n1 256 n2 dots from start of line If pr...

Page 12: ...ed Works in an either or way with CR CR LF pairs are treated as a single line terminator Line terminators immediately following full lines are ignored FF 0CH Real time Form Feed Exit spooling mode and print buffer contents Ignored if the printer is not already in spooling mode or an error condition exists CR 0DH Carriage Return Line terminator works in an either or way with LF CR LF pairs are trea...

Page 13: ...l mode confirmation of the number of bytes sent whilst in spool mode will be returned The sequence on exiting spool mode is i Transmit initial confirmation string with data packet information ii Exit Spool Mode iii Print all spooled data from buffer iv Transmit final confirmation string When the GS L command is received a 4 byte confirmation string is transmitted by the printer as follows STX Byte...

Page 14: ...ee CODES TRANSMITTED for format A value of n 00H disables automatic reporting and is the default condition ESC u 1BH 75H n Transmit peripheral device status Transmit STATUS byte when decoded n is discarded this command is exactly the same as ESC v This command is in the buffer when the response is sent so the buffer will not be reported as empty See the section CODES TRANSMITTED below for format E...

Page 15: ...meric ASCII data variable length Max 22 00H 5 Int2 of 5 Numeric only ASCII data variable length Max 23 00H 6 Code 128A Alphanumeric ASCII data 0x00 to 0x5F variable length Max 14 FFH 7 Code 128B Alphanumeric ASCII data 0x20 to 0x7F variable length Max 14 FFH 8 Code 128C Numeric only ASCII data 30H to 39H variable length Max 14 bytes FFH 9 Code 93 Alphanumeric ASCII data 0x00 to 0x7F variable lengt...

Page 16: ...S byte which should be monitored and result in the STATUS byte being automatically transmitted if a change of state is detected STATUS Status Report The STATUS byte is encoded bitwise bit 0 Head Up Sensor Active 0 head OK 1 head up bit 1 Mechanism running 0 stopped 1 running bit 2 Data buffer completely empty 0 not empty 1 empty bit 3 Paper Out Sensor Active 0 paper OK 1 paper out bit 4 Reserved b...

Page 17: ...e Period 52 n1 n2 Report Auto Save Period 66 n1 Set print darkness 66 n1 Report print darkness 110 Produce test print Setting Configuration Information N B This section contains details of how to modify some of the basic operating functions of the printer Do NOT attempt to modify any parameter unless you fully understand the potential consequences The command ESC X m may be used to set various int...

Page 18: ... Sensor when fitted optional The standard setting for this value is E1H for the Ap1400 m 20 Set MarkFeed and EjectFeed values The command ESC X 14H n1 n2 sets the values of MarkFeed and EjectFeed These parameters are used in Mark Sense operation See MARK SENSE OPERATION section for details m 23 Set AUXFLAGS value The command ESC X 17H n sets the internal values according to individual bits in the ...

Page 19: ...and ESC X 42H n sets the value of print darkness This value controls the operation of the printing process to suit different paper types Valid values are in the range 55H to 90H Increasing the value causes the printed output to become darker 55H suits standard thermal paper 90H suits Linerless paper Saving Configuration Information All configuration information must be saved to Flash if it is to b...

Page 20: ...tring of up to 10 ASCII characters terminated by a CR character eg 123456 CR This is the Unit Serial Number as set by the factory during printer test setup m 9 Report Internal Defaults In response to the command GS I 09H the printer transmits 3 bytes The first byte contains the current values of the flags set using the ESC X 09H n command The following 2 bytes are for Able diagnostics only m 15 Re...

Page 21: ...tion and Paper Feed LF CR ESC J n ESC d n Dot Addressable Bit Graphics ESC Entering and exiting Spooling Mode ESC L FF Extra inter character and inter line spacing ESC n ESC 2 ESC 3 n Set HTAB positions ESC D Request Printer STATUS BYTE ESC u n ESC v GS ENQ real time Select Barcode Size and Format GS H n GS h n GS w n Print Barcode GS k Summary of Real Time Status Information Information How repor...

Page 22: ...f Test Disable Feed Switch ESC c5 Coded In Self Test Disable Demo Mode ESC c5 Coded In Self Test Swap 23H 9CH chars ESC X 23 n GS I 23 Use ø Ø 9BH 9DH ESC X 23 n GS I 23 Use Ç 80H ESC X 23 n GS I 23 Enable Black Mark Operation ESC X 19 GS I 19 Also Coded In Self Test Black Mark parameters detail ESC X 20 GS I 20 Black Mark parameters more detail ESC X 42 GS I 42 Paper Out LED Pattern ESC X 19 GS I...

Page 23: ...e containing all of the files needed to install the library on Win32 32bit and x64 64bit architecture machines Contained within the zip file is a document detailing the install process Please read and follow these instructions to install LIBUSB When using files obtained from http sourceforge net projects libusb win32 Download the latest LIBUSB from the website Extract libusb win32 bin 1 2 6 0 zip ...

Page 24: ...nually as follows Visual Studio Example 1 Identify the Visual Studio install directory For 32 bit installs this will normally be BootDrive Program Files Microsoft Visual Studio version For 64 bit installs this will normally be BootDrive Program Files X86 Microsoft Visual Studio version 2 Identify the language compiler directory for C C this would be VC 3 Identify the include library directories fo...

Page 25: ... simple single dialog utility which will show the status of all devices for which LIBUSB filter drivers have been installed The dialog displayed dynamically refreshes allowing the connection and disconnection of devices to be tested Connect the printer to the USB and run the utility When run a dialog similar to the one shown will be displayed This dialog shows the bus enumeration for the Ap1400 pr...

Page 26: ...ount Gets the number of printers currently in an enumerated state 28 ClearEnumList Clears all enumerations of printer on the USB 29 GetVendor Gets the vendor ID of an enumerated device 30 GetProduct Gets the product ID of an enumerated device 31 GetName Gets the enumerated name of an enumerated device 32 OpenDevice Opens a device and prepares it to send receive data 33 CloseDevice Closes and relea...

Page 27: ...intVersion structure describing the major minor version numbers and the build number If an error occurs then the system error code is set Use GetLastError to retrieve this The SUSBPrintVersion structure is defined as SUSBPrintVersion typedef struct SUSBPrintVersion UINT m_uiMajor1 UINT m_uiMajor2 UINT m_uiMin1 UINT m_uiMin2 UINT m_uiBuild SUSBPrintVersion Define pointers to this type typedef SUSBP...

Page 28: ...n this call is best placed in the InitInstance function of the CWinApp class Arguments None Returns Integer value 0 or 1 to indicate success or failure where 0 is a failure If a failure occurs then DllInitialise will display a dialog explaining the problem In addition the system error code is set which can be retrieved by calling GetLastError Example Initialise the Support DLL if DllInitialise Dec...

Page 29: ...on is called more than once then each call should be preceded with a call to ClearEnumList Arguments None Returns Integer value representing the number of printers successfully enumerated If an error occurs then the number returned will be 0 and the system error code will be set If the return indicates 0 printers and the system error code is ERROR_SUCCESS then no error has occurred there are just ...

Page 30: ...does not guarantee that the number of printers enumerated are still active A call to EnumPrinters must first be made for this function to return any value other than 0 Arguments None Returns Integer value representing the number of printers successfully enumerated by a previous call to EnumPrinters No error condition exists for this function and the system error code is not modified Example Enumer...

Page 31: ...rs are terminated and communication to any active printer will be lost If it is required to re enumerate the USB then this function should be called first Although any open handles will be closed and freed it is good practice to close all open printer handles prior to calling this function thus terminating communications with the printers in a controlled fashion Arguments None Returns Integer valu...

Page 32: ...EnumPrinters must have been made prior to calling this function Arguments iIndex The index of the device This must be an integer value 0 GetEnumPrinterCount If this value is outside of this range then an exception will be thrown Returns DWORD representing the vendor id The system error code will be set to ERROR_SUCCESS regardless of whether the vendor id is valid or not Example Check range prior t...

Page 33: ...A call to EnumPrinters must have been made prior to calling this function Arguments iIndex The index of the device This must be an integer value 0 GetEnumPrinterCount If this value is outside of this range then an exception will be thrown Returns DWORD representing the product id The system error code will be set to ERROR_SUCCESS regardless of whether the product id is valid or not Example Check r...

Page 34: ...ll to EnumPrinters must have been made prior to calling this function Arguments iIndex The index of the device This must be an integer value 0 GetEnumPrinterCount If this value is outside of this range then an exception will be thrown Returns An LPSTR pointer value pointing to the null terminated string representing the enumerated name The system error code will be set to ERROR_SUCCESS regardless ...

Page 35: ...x Pointer to the index of the device This must be an integer value 0 GetEnumPrinterCount If this value is outside of this range then an exception will be thrown Returns An int representing the handle of the device or INVALID_HANDLE_VALUE if the device open failed If the returned handle is set to INVALID_HANDLE_VALUE then the system error code will be set to fully describe the problem This can be r...

Page 36: ...idated and should be discarded Arguments phandle Pointer to the handle of an open device This handle must have been issued by a previous call to OpenDevice Returns ERROR_SUCCESS if successfully closed otherwise the value is set to the system error code Example Check range prior to call if CloseDevice ihandle ERROR_SUCCESS CString csError csError Format _T Close device failed R C d GetLastError Afx...

Page 37: ...ious call to OpenDevice pData Pointer to a buffer containing the data to transmit All data in the buffer up to pDataLen is transmitted including any NULL characters pDataLen Pointer to an integer containing the length of the data to transmit This value is modified to show the actual amount of data that was successfully transmitted If a timeout or other error occurs during transmission this value c...

Page 38: ...iately and any remaining data remains pending This data can be read by further calls to ReadData Arguments ihandle Handle of an open device This handle must have been issued by a previous call to OpenDevice pData Pointer to a suitable buffer to receive the data This buffer must be at least the size of the value held in pLen pLen Pointer to an int value containing the number of bytes to read This v...

Page 39: ...Arguments ihandle Handle of an open device This handle must have been issued by a previous call to OpenDevice iReqtype The request type For the Ap1400 this value will always be USB_TYPE_CLASS USB_RECIP_DEVICE USB_ENDPOINT_IN iRequest The high level command request Supported user requests are USB_GS_COMMAND and USB_BUFFERSTATE iValue The sub command This value identifies the actual command from wit...

Page 40: ...UFFERSTATE 0 0 iRetLen cReturn if dwStatusCode ERROR_SUCCESS TRACE _T Buffer state get Failed n CString csError csError Format _T GetBufferState failed Reason d dwStatusCode AfxMessageBox csError MB_ICONSTOP MB_OK bError TRUE continue if the error code is OK the check the return if cReturn BUFFER_BUSY TRACE _T Buffer state reports BUFFER_BUSY n Wait for a small period and retry iMaxTime BUFFER_WAI...

Page 41: ...ious call to OpenDevice Returns An unsigned character representing either the printer status byte or 0xFF if an error occurs If the value returned is 0xFF then the system error code will be set to indicate the error This can be retrieved via a call to GetLastError If the value returned is not 0xFF then the byte represents the printer statuis byte and is formatted as follows Bit 0 Head Up sensor if...

Page 42: ... Handle of an open device This handle must have been issued by a previous call to OpenDevice pData Pointer to the buffer containing the data to be sent The data must be terminated with a NULL character Returns ERROR_SUCCESS if successful otherwise the system error code is returned Example Get the status byte CString csLine _T This is a line of data r n dwStatusCode KrnlSendData m_iOpenHandle csLin...

Reviews: