Serial port API: Difference between revisions
(→write) |
No edit summary |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 9: | Line 9: | ||
! scope="row" colspan="2" | Parameters | ! scope="row" colspan="2" | Parameters | ||
|- | |- | ||
| pDeviceName || ''' | | pDeviceName || The alias for serial port. Available values: DB9, GS0_01, WIZARHANDQ1, Q1_USB_SERIAL, USB_SERIAL, SERIAL_EXT, USB_SLAVE_SERIAL, USB_HOST_SERIAL<br> | ||
* '''in W1/W1V2:''' | |||
** '''DB9''': works for DB9 port at the back side of the terminal. | |||
** '''GS0_Q1''': works for USB host port at the right side of terminal to connect with Q1 via USB cable in master mode. | |||
* '''in Q1 3g:''' | |||
** '''WIZARHANDQ1''': works for USB serial port in slave mode. | |||
** '''Q1_USB_SERIAL''' or '''USB_SERIAL''': works for USB serial port in master mode. | |||
** '''SERIAL_EXT''': works for internal fiscal module. | |||
* '''in Q1 4g and Q2, Q3, QD4/5 series:''' | |||
** '''USB_SLAVE_SERIAL''': works for USB serial port in slave mode. | |||
** '''USB_HOST_SERIAL''' or '''USB_SERIAL''': works for USB serial port in master mode. | |||
** '''SERIAL_EXT''': works for internal fiscal module. | |||
|} | |} | ||
{| | {| | ||
|- | |- | ||
Line 40: | Line 36: | ||
<syntaxhighlight lang="c">int esp_close(int nHandle)</syntaxhighlight > | <syntaxhighlight lang="c">int esp_close(int nHandle)</syntaxhighlight > | ||
Close the serial port opened before. | Close the serial port opened before. | ||
The open and close | The open and close API are pair operations. If you don’t want to use this device, you should call the close API to release this device. | ||
{|class="wizarpostable" | {|class="wizarpostable" | ||
|- | |- | ||
Line 62: | Line 58: | ||
<syntaxhighlight lang="c">int esp_set_baudrate(int nHandle, unsigned int nBaudrate)</syntaxhighlight > | <syntaxhighlight lang="c">int esp_set_baudrate(int nHandle, unsigned int nBaudrate)</syntaxhighlight > | ||
Set the baud rate of the serial port so that this device can read and write in the same baud rate. | Set the baud rate of the serial port so that this device can read and write in the same baud rate. | ||
This | This API should be used before read and write. | ||
{|class="wizarpostable" | {|class="wizarpostable" | ||
|- | |- | ||
Line 108: | Line 104: | ||
| int || The result code, >= 0, success, the data length of read; <0 [[Error_code|error code]]. | | int || The result code, >= 0, success, the data length of read; <0 [[Error_code|error code]]. | ||
|} | |} | ||
=== <big>write</big>=== | === <big>write</big>=== | ||
Line 132: | Line 129: | ||
| int || The result code, >= 0, data length of written; <0 [[Error_code|error code]]. | | int || The result code, >= 0, data length of written; <0 [[Error_code|error code]]. | ||
|} | |} | ||
=== <big>flush_io</big>=== | === <big>flush_io</big>=== |
Latest revision as of 05:40, 25 September 2019
API Overview
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 | The alias for serial port. Available values: DB9, GS0_01, WIZARHANDQ1, Q1_USB_SERIAL, USB_SERIAL, SERIAL_EXT, USB_SLAVE_SERIAL, USB_HOST_SERIAL
|
Returns | |
---|---|
int | 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 API are pair operations. If you don’t want to use this device, you should call the close API to release this device.
Parameters | |
---|---|
nHandle | int: Handle of this device, returned from open |
Returns | |
---|---|
int | 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 | int: Handle of this device, returned from open |
nBaudrate | int: Baud rate |
Returns | |
---|---|
int | 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 | int: Handle of this device, returned from open |
pDataBuffer | unsigned char*: Data buffer |
nExpectedDataLength | int: Data length to read |
nTimeout_MS | int: Time in milliseconds. 0 : read and return immediately; <0: read until got data. |
Returns | |
---|---|
int | The result code, >= 0, success, the data length of read; <0 error code. |
write
int esp_write(int nHandle, unsigned char* pDataBuffer, int nDataLength)
Send information from the serial port.
Parameters | |
---|---|
nHandle | int: Handle of this device, returned from open |
pDataBuffer | unsigned char*: Data buffer |
nDataLength | int: Data length |
Returns | |
---|---|
int | The result code, >= 0, data length of written; <0 error code. |
flush_io
int esp_flush_io(int nHandle)
Flush the IO buffer of the serial port.
Parameters | |
---|---|
nHandle | int: Handle of this device, returned from open |
Returns | |
---|---|
int | The result code, >= 0, written data length; <0 error code. |