nTotalCharacters COM_COUNT(<nComPort>) lOldDTRStatus COM_DTR(<nComPort>,[<lNewDTRStatus>]) lClear COM_FLUSH(<nComPort>) lOldHandshake COM_HARD(<nComPort>,<lNewHandshake>,[<lDTR/DSR>]) lInitialized COM_INIT(<nComPort>,[<nBaudRate>],[<cParity>], [<nDataLength>],[<nStopBits>]) nMaxCom COM_NUM() lStatus COM_OPEN(<nComPort>,<notused>,<notused>,<notused>, [<lRTSCTS>],[<lXONXOFF>],[<lDebug>]) cData COM_READ(<nComPort>,[<nLength>]) lOldRTSStatus COM_RTS(<nComPort>,[<lNewRTSStatus>]) nLength COM_SEND(<nComPort>,<cString>) lDeleted COM_SFLUSH(<nComPort>) lOldHandshake COM_SOFT(<nComPort>,[<lNewHandshake>],[<cXONchar>],[<cXOFFchar>]) nOldTimeout COM_TIMEOUT(<nComPort>[,<nTimeout>])
Category Serial I/O include description of functions for using communication over COM-ports. This function based on multiplatform library EZV24 http://libezV24.sourceforge.net/.
For using need linking clip-com library:
clip -e test.prg -lclip-com
COM_COUNT(<nComPort>) --> nTotalCharacters
This function allows you to determine the number of characters in recieve buffer. This lets you determine how many characters can be read with the COM_READ() function.
If an attempt is made to read the number of characters available in a closed port, the function returns a value of -1.
<nComPort> | - Designates the port (1 to N) for which the number of characters in the input buffer is determined. |
Returns : | Return the number of characters in the selected buffer. |
See also : | COM_DTR() COM_RTS() COM_SOFT() COM_TIMEOUT() COM_HARD() COM_NUM() |
COM_DTR(<nComPort>,[<lNewDTRStatus>]) --> lOldDTRStatus
COM_DTR() queries the DTR signal status. If the second parameter is not supplied, the signal status does not change.
The COM_CLOSE() function resets DTR (to inactive). By contrast, COM_OPEN does not automatically make DTR active!
<nComPort> | - Designates the port (1 to N) for which the number of characters in the input buffer is determined. |
<lNewDTRStatus> | - Designates the status of DTR. .T. designates that the DTR signal is active, and .F. designates that the signal is inactive. If the parameter is not specified, does not affect the DTR exit signal. |
Returns : | The returned value corresponds to the DTR signal status prior to the new setting, or in the absence of <lNewDTRStatus>, the returned value corresponds to the current DTR. A return of .T. indicates that the DTR is active (MCR bit 1 = 1). A return of .F. indicates that the DTR is inactive (MCR bit 1 = 0). |
See also : | COM_SOFT() COM_RTS() COM_TIMEOUT() COM_HARD() COM_NUM() COM_COUNT() |
COM_FLUSH(<nComPort>) --> lClear
This function allows you to flush all the characters in a receiving buffer. This makes it unnecessary to tediously determine how many characters are currently in the buffer in order to remove them with a read procedure.
COM_FLUSH() guarantees a truly empty buffer. However, a new character can be received between the time that you call a COM_COUNT() and a COM_READ().
<nComPort> | - Designates the port (1 to N). |
Returns : | If the receiving buffer can be cleared successfully, the function returns .T.. |
See also : | COM_INIT() COM_OPEN() COM_READ() COM_SEND() COM_SFLUSH() |
COM_HARD(<nComPort>,<lNewHandshake>,[<lDTR/DSR>]) --> lOldHandshake
The size of a receiving buffer is always limited. To avoid overflow, and thereby a loss of characters, software or hardware handshakes are usually implemented. During a hardware handshake, the port monitors the RTS signal. If you use this function to switch this handshake on, the signal is activated as soon as the buffer is 75% full. As soon as the buffer content is once again reduced to 50% or less, the port (the RTS signal) is once again released. Some printers use the port signals, DTR (output like RTS) and DSR (entry like CTS) instead of RTS/ CTS, to avoid buffer overflow. In this case, <lDTR/DSR> can be passed with .T..
This function works for data input as well as output.
If you use a hardware handshake, then the RTS signal should no longer be affected by COM_RTS() or COM_MCR().
<nComPort> | - Designates the number of the port (1 to N). |
<lNewHandshake> | - Designates whether the handshake is on (.T.) or off (.F.). |
<lDTR/DSR> | - Designates whether the function uses the DTR/DSR handshake or the RTS/CTS handshake. When passed as .T., the function uses the DTR/DSR handshake instead of the RTS/CTS handshake. |
Returns : | When called only with <nComPort>, the COM_HARD() returns .T. if the hardware handshake is on and .F. if the hardware handshake is off. When <lNewHandshake> is passed, the function returns the status prior to the new setting. |
See also : | COM_DTR() COM_RTS() COM_SOFT() COM_TIMEOUT() COM_NUM() COM_COUNT() |
COM_INIT(<nComPort>,[<nBaudRate>],[<cParity>], [<nDataLength>],[<nStopBits>]) --> lInitialized
In order to use the serial port after you open it, four operating parameters must have been passed to this function. These operating parameters are the transmission speed (baud rate), the data length, the parity, and the number of stop bits. Tht defaul configuration is "9600 baud, 8N1". This configuration means eight data bits, no parity, and one stop bit. What is important is that all these parameters can be changed while the port is closed. Neither the data buffer or the modem status register (DTR, etc.) are affected.
The port must have been opened previously. It is impossible to initialize a port prior to opening it.
If any or all of the four operating parameters are not designated, or are designated incorrectly, the standard arguments of 9600 baud, no parity, eight data bits, and one stop bit is used.
<nComPort> | - Designates the port (1 to N) that is initialized. |
<nBaudRate> | - Designates the selected baud rate for the port. Settings of 300, 600, 1200, 2400, 4800, 9600 and 19200 baud are possible. The default value is 300 baud. |
<cParity> | - Designates parity in the following form: (E)ven, (O)dd, (M)ark, (S)pace, or (N)one. The default value is (N)one. |
<nDataLength> | - Designates the data length; seven or eight bits are possible. The default value is eight bits. |
<nStopBits> | - Designates the number of stop bits, one or two. The default value is one stop bit. |
Returns : | If the com port is initialized successfully, the function returns .T. |
See also : | COM_FLUSH() COM_OPEN() COM_READ() COM_SEND() COM_SFLUSH() |
COM_NUM() --> nMaxCom
This function returns the number of the serial interface port available. This is not to say that a return value of 3 necessarily means that ports 1 through 3 are available; for example, COM2 could be missing. Whether or not a serial port can actually be used can be tested using the COM_OPEN() or COM_INIT() functions.
Returns : | Return the number of the highest available serial interface port |
See also : | COM_DTR() COM_RTS() COM_SOFT() COM_TIMEOUT() COM_HARD() COM_COUNT() |
COM_OPEN(<nComPort>,<notused>,<notused>,<notused>, [<lRTSCTS>],[<lXONXOFF>],[<lDebug>]) --> lStatus
This function allows you to open a serial interface port.
<nComPort> | - Designates the number of the port (1 to N). |
<lRTSCRS> | - Enable or disable use of hardware flow control. |
<lXONXOFF> | - Enable or disable use of software flow control. |
<lDebug> | - True value enable com port debug output |
Returns : | Returns .T. when the port has been successfully opened and you can select the buffer. |
See also : | COM_FLUSH() COM_INIT() COM_READ() COM_SEND() COM_SFLUSH() |
COM_READ(<nComPort>,[<nLength>]) --> cData
All characters arriving at the serial port are stored in the appropriate buffer under interrupt control. It is possible to determine the number of characters in the buffer and to read one, several, or all of the characters. If the <nLength> parameter is not specified, then all the characters in the buffer are read.
Remember that you can receive additional characters between calling COM_COUNT() and COM_READ().
<nComPort> | - Designates the port (1 to N) that is read. |
<nLength> | - Designates the number of the characters in the buffer that are read. The default value reads all characters. |
Returns : | The returned string contains the corresponding characters from the receiving buffer. |
See also : | COM_FLUSH() COM_INIT() COM_OPEN() COM_SEND() COM_SFLUSH() |
COM_RTS(<nComPort>,[<lNewRTSStatus>]) --> lOldRTSStatus
COM_RTS() queries the RTS signal status. If the second parameter is not supplied, the signal status does not change.
The COM_CLOSE() function resets RTS (to inactive). By contrast, COM_OPEN does not automatically make RTS active!
<nComPort> | - Designates the port (1 to N) for which the number of characters in the input buffer is determined. |
<lNewRTSStatus> | - Designates the status of RTS. .T. designates that the RTS signal is active, and .F. designates that the signal is inactive. If the parameter is not specified, does not affect the RTS exit signal. |
Returns : | The returned value corresponds to the RTS signal status prior to the new setting, or in the absence of <lNewRTSStatus>, the returned value corresponds to the current RTS. A return of .T. indicates that the RTS is active (MCR bit 1 = 1). A return of .F. indicates that the RTS is inactive (MCR bit 1 = 0). |
See also : | COM_SOFT() COM_DTR() COM_TIMEOUT() COM_HARD() COM_NUM() COM_COUNT() |
COM_SEND(<nComPort>,<cString>) --> nLength
Transmits one or more characters from one of four ports.
<nComPort> | - Designates the port (1 to N) from which transmission occurs. |
<cString> | - Designates the string that is transmitted by the selected port. If you only need to transmit a single character, then the second parameter can also be numeric and thereby pass the ASCII character code directly. |
Returns : | When transmission is successful, a 0 is returned. If transmission is not successful, the number of characters that have not been transmitted or could not be placed in the sending buffer is returned. |
See also : | COM_FLUSH() COM_INIT() COM_OPEN() COM_READ() COM_SFLUSH() |
COM_SFLUSH(<nComPort>) --> lDeleted
This function remove all characters from sending buffer not yet transmitted.
<nComPort> | - Designates the port (1 to N). |
Returns : | On success returns .T.. |
See also : | COM_FLUSH() COM_INIT() COM_OPEN() COM_READ() COM_SEND() |
COM_SOFT(<nComPort>,[<lNewHandshake>],[<cXONchar>],[<cXOFFchar>]) --> lOldHandshake
With modem connections, a hardware handshake is impossible, which is why we are making a software handshake available with this function. When a buffer is 75% full, an XOFF character (Ctrl-Q) is transmitted to the remote station. As soon as the buffer has again been emptied to 50% or less, the XON character (Ctrl-S) is transmitted. You can use characters other than Ctrl-S or Ctrl-Q for individual protocols, which would then be taken into account in the situations described above.
When you want to transmit binary data, the software handshake must always be turned off.
<nComPort> | - Designates the port (1 to N) for which the software handshake is set. |
<lNewHandshake> | - Designates whether the handshake is on (.T.) or off (.F.). If this parameter is omitted, the function returns the current setting. |
<cXONchar> | - Designates any character you choose as an XON character. The default character is ASCII 19 - Ctrl-S. |
<cXOFFchar> | - Designates any character you choose as an XOFF character. The default value is ASCII 17 - Ctrl-Q. |
Returns : | The function returns the previously set value. |
See also : | COM_DTR() COM_RTS() COM_TIMEOUT() COM_HARD() COM_NUM() COM_COUNT() |
COM_TIMEOUT(<nComPort>[,<nTimeout>]) --> nOldTimeout
All read functions may use a timeout mechanism while waiting for characters. If this time limit is exceeded the function abort reading.
The timeout duration is specified by the parameter TenthOfSeconds. This value is given as a multiple of a thenth of a second.
<nComPort> | - Designates the number of the port (1 to N). |
<nTimeout> | - Designates operation timeout in tenth (1/10) seconds. |
Returns : | Return previous value of operation timeout. |
See also : | COM_DTR() COM_RTS() COM_SOFT() COM_HARD() COM_NUM() COM_COUNT() |