Serial port API: Difference between revisions

From wizarPOS
(Created page with "== Functions == The calling sequence is open>set_baudrate>read/write>fulsh_io>close === open === in...")
 
Line 11: Line 11:
| ''pDeviceName'' || Device name
| ''pDeviceName'' || Device name
|}
|}
'''pDeviceName'''
if using the fiscal module, the device name is SERIAL_EXT. Others are as follows:
* W1/W1V2
** SLAVE MODE: DB9
** HOST_MODE: GS0_Q1
* Q1
** SLAVE MODE: WIZARHANDQ1
** HOST_MODE: Q1_USB_SERIAL or USB_SERIAL
* Q1V2
** SLAVE MODE: USB_SLAVE_SERIAL
** HOST_MODE: USB_HOST_SERIAL or USB_SERIAL
* Q2/K2/M2
** SLAVE MODE: USB_SLAVE_SERIAL
** HOST_MODE: USB_HOST_SERIAL or USB_SERIAL
'''Returns'''
'''Returns'''


The result code, >= 0, handle of this device; <0 [[Error_code|error code]].
The result code, >= 0, handle of this device; <0 [[Error_code|error code]].
 
=== close ===
=== close ===
   int esp_close(int nHandle)
   int esp_close(int nHandle)

Revision as of 08:31, 13 April 2018

Functions

The calling sequence is open>set_baudrate>read/write>fulsh_io>close

open

int esp_open(char* pDeviceName)

Open the serial port by the specified device name. This operation should be used before other operations.

Parameters

pDeviceName Device name

pDeviceName

if using the fiscal module, the device name is SERIAL_EXT. Others are as follows:

  • W1/W1V2
    • SLAVE MODE: DB9
    • HOST_MODE: GS0_Q1
  • Q1
    • SLAVE MODE: WIZARHANDQ1
    • HOST_MODE: Q1_USB_SERIAL or USB_SERIAL
  • Q1V2
    • SLAVE MODE: USB_SLAVE_SERIAL
    • HOST_MODE: USB_HOST_SERIAL or USB_SERIAL
  • Q2/K2/M2
    • SLAVE MODE: USB_SLAVE_SERIAL
    • HOST_MODE: USB_HOST_SERIAL or USB_SERIAL

Returns

The result code, >= 0, handle of this device; <0 error code.

close

 int esp_close(int nHandle)

Close the serial port opened before. The open and close apis are pair operations. If you don’t want to use this device, you should call the close api to release this device.

Parameters

nHandle Handle of this device, returned from open

Returns

The result code, >= 0, success; <0 error code.

set_baudrate

 int esp_set_baudrate(int nHandle, unsigned int nBaudrate)

Set the baud rate of the serial port so that this device can read and write in the same baud rate. This api should be used before read and write.

Parameters

nHandle Handle of this device, returned from open
nBaudrate Baud rate

Returns

The result code, >= 0, success; <0 error code.

read

 int esp_read(int nHandle, unsigned char* pDataBuffer, int nExpectedDataLength, int nTimeout_MS)

Get information from the serial port.


Parameters

nHandle Handle of this device, returned from open
pDataBuffer Data buffer
nExpectedDataLength Data length to read
nTimeout_MS Time in milliseconds. 0 : read and return immediately; <0: read until got data.

Returns

The result code, >= 0, success; <0 error code.

write

 int esp_write(int nHandle, unsigned char* pDataBuffer, int nDataLength)

Send information from the serial port.


Parameters

nHandle Handle of this device, returned from open
pDataBuffer Data buffer
nDataLength Data length

Returns

The result code, >= 0, written data length; <0 error code.

flush_io

 int esp_flush_io(int nHandle)

Flush the IO buffer of the serial port.


Parameters

nHandle Handle of this device, returned from open

Returns

The result code, >= 0, success; <0 error code.