SerialPort uses a command and response protocol. Commands are issued by the application interface. Every command receives a response from the server. Commands that trigger immediate actions, such as opening a connection, setting its operating conditions or querying its state, are carried out when they are received and the result of the command is returned in the response. Commands that may take some time to complete generate an immediate response showing whether the command was accepted while the associated activity, such as sending a block of data to the remote host, continues asynchronously until it completes. The server supports queries that allow the progress of asynchronous activities to be monitored.
In the interest of maximising throughput there are no wait states in the server apart from the per-character transmission delay, a configurable pause to allow a slow remote host to deal with each character before it is sent the next one. SerialPort implements functions that calculate and apply a waiting time to allow for data to be transferred to the remote host and for it to transmit a block of data in reply. This is implemented entirely within the interface code, so the application that has requested the transfers is the only process that is suspended during the waiting time.
Each message has a common format:
C,nnnn,value
where:
C |
is the command code:
|
|||||||||||||||||||||||||||||||||
nnnn | is the length of the following value, max 1500 bytes. | |||||||||||||||||||||||||||||||||
value |
is dependent on the command mnemonic.
|
[1]: | The force value is a string. If the first character starts with T, t or 1 the port will be forced closed regardless of whether there is still data in the server's buffers. Any other value or a zero value length will cause a normal close if the buffers are empty but will leave the port open and return an error if there is still data in the buffers. |
[2]: | The command returns three comma-separated numbers. These are the number of bytes in the input buffer, the number of bytes in the output buffer and the buffer size. Both buffers are the same size. |
[3]: |
These parameters are three fixed length single byte values.
They are concatenated to form a three byte command
parameter. All are boolean and may be T/F, t/f or 1/0. Each
controls whether a set of control variables are reset ot
not.
|
[4]: |
These parameters are three fixed length single byte values.
They are concatenated to form a three byte command
parameter. active and external are boolean
and may be T/F, t/f or 1/0.
marker can be any ASCII character code.
|
Every command generates a response. The command code in the response is set according to the following rules:
Output is sent to the port with a P command. The response is returned immediately. The data has been buffered for transmission but nothing has been transmitted to the remote host when the response is sent. If external separators are enabled the P command causes a separator to be appended to the output byte list.
Input is retrieved with the G command. All immediately available characters up the the requested maximum are returned. If no data is available a G response with a zero length value is returned. If separators are enabled the current separator character will terminate the retrieval if it is encountered within the available characters. If the terminator is external it is not returned as part of the retrieved bytes list, but if it is internal then the terminator is the last character in value.