Serial port functions

Serial port functions. More...

Functions

 enumports ()
 Finds and enumerates ports on the PC.

 openport (port, baudrate, databits, parity, stopbits)
 Opens a serial port.

 closeport (port)
 Closes a serial port.

 showterm (port, width, height, chars)
 Shows a terminal window.

 hideterm (port)
 Hides a terminal window.

 receive (port)
 Get received data from a port.

 send (port, mydata)
 Send data to port.

 flush (port)
 Flush receive buffer.

 flush (port, char_no)
 Partially flush receive buffer.

 setrts (port)
 Set RTS signal.

 clearrts (port)
 Clear RTS signal.

 setdtr (port)
 Set DTR signal.

 cleardtr (port)
 Clear DTR signal.

 getcts (port)
 Returns CTS line state.

 getdsr (port)
 Returns DSR line state.

 getring (port)
 Returns RING line state.

 getrlsd (port)
 Returns RLSD line state.


Detailed Description

Serial port functions.


Function Documentation

cleardtr port   ) 
 

Clear DTR signal.

Puts in inactive state the DTR (data-terminal-ready) signal, that is, puts the RTS line of the port if open in logic 0 state (3...25 V).

Parameters:
port Which port to apply command to

clearrts port   ) 
 

Clear RTS signal.

Puts in inactive state the RTS (request-to-send) signal, that is, puts the RTS line of the port if open in logic 0 state (3...25 V).

Parameters:
port Which port to apply command to

closeport port   ) 
 

Closes a serial port.

Closes port, if open, and its terminal window.

Parameters:
port Port to be closed
Example:
closeport ("com3")

enumports  ) 
 

Finds and enumerates ports on the PC.

Returns a string containing the names of serial ports available on server. There are shown only free ports. The format of the string is as follows (name space name space...):
COM1 COM2 ...COMx
The split and extract string functions can be used to extract individual names from the strings.

Example:
echo (enumports ())
has the following result on a PC with 2 free serial ports, 1 and 2:
COM1 COM2

flush port  ,
char_no 
 

Partially flush receive buffer.

Flushes only first char_no characters (bytes) of Easy Control's input buffer of the serial port.
This is useful when making decisions based on received data, for example when waiting for CRLF terminated strings. Also is useful when working with lot of data, to prevent data loss, because Easy Control's buffer will roll over at about 8 kBytes.

Parameters:
port From which input buffer's port to delete data
char_no How many characters (bytes) to delete
Note:
Use this version of flush to prevent data loss between receive and flush actions.

flush port   ) 
 

Flush receive buffer.

Flushes Easy Control's input buffer of the serial port.
This is useful when making decisions based on received data, for example when waiting for CRLF terminated strings. Also is useful when working with lot of data, to prevent data loss, because Easy Control's buffer will roll over at about 8 kBytes.

Parameters:
port Which input buffer's port to be flushed
Note:
Use flush(port,char_no) instead.

getcts port   ) 
 

Returns CTS line state.

Returns 1 if CTS line of the port (if open) is in active state (logic 1, -3...-25 V) or 0 if is in inactive state (logic 0, 3...25 V).

Parameters:
port Which port to apply command to

getdsr port   ) 
 

Returns DSR line state.

Returns 1 if DSR line of the port (if open) is in active state (logic 1, -3...-25 V) or 0 if is in inactive state (logic 0, 3...25 V).

Parameters:
port Which port to apply command to

getring port   ) 
 

Returns RING line state.

Returns 1 if RING line of the port (if open) is in active state (logic 1, -3...-25 V) or 0 if is in inactive state (logic 0, 3...25 V).

Parameters:
port Which port to apply command to

getrlsd port   ) 
 

Returns RLSD line state.

Returns 1 if RLSD (aka CD) line of the port (if open) is in active state (logic 1, -3...-25 V) or 0 if is in inactive state (logic 0, 3...25 V).

Parameters:
port Which port to apply command to

hideterm port   ) 
 

Hides a terminal window.

Hides terminal window of a port, if open.
This does not close the port.

Parameters:
port For which port to hide its terminal window

openport port  ,
baudrate  ,
databits  ,
parity  ,
stopbits 
 

Opens a serial port.

Opens port with specified settings.

Parameters:
port Port to open, such as COM1, COM4
baudrate Baudrate, such as 2400, 9600
databits Databits, such as 7, 8
parity Parity, such as n (none), e (even)
stopbits Stobits, such as 1, 2
Note:
The terminal window is not visible until you supply a showterm () command.
Example:
openport ("com3",33600,8,"n",1)

receive port   ) 
 

Get received data from a port.

Get received data from a port. The return value will contain all data received since port was opened or it was flushed. The call to the function must be done exactly when data is needed.

Parameters:
port From which port to get data
Note:
Some sort of protocol must be implemented, if not is possible to loose data.
Example:
mydata=receive("com3")
writelog (mydata)

send port  ,
mydata 
 

Send data to port.

Send data to a serial port, if open.

Parameters:
port On which port to send data
Example:
myport="com3"
mydata="hello there"
openport (myport,9600,8,"n",1)
send (myport,mydata)

setdtr port   ) 
 

Set DTR signal.

Puts in active state the DTR (data-terminal-ready) signal, that is, puts the DTR line of the port if open in logic 1 state (-3...-25 V).

Parameters:
port Which port to apply command to

setrts port   ) 
 

Set RTS signal.

Puts in active state the RTS (request-to-send) signal, that is, puts the RTS line of the port if open in logic 1 state (-3...-25 V).

Parameters:
port Which port to apply command to

showterm port  ,
width  ,
height  ,
chars 
 

Shows a terminal window.

Shows a terminal window for a serial port, if open.
Terminal window is a window to watch data flow. Received data will have a (R) mark, sent data will have a (S) mark. On every line are displayed chars characters, first in hexa representation, then in clear text.

Parameters:
port For which port to show the terminal window
width Window width
height Window height
chars How many characters to show on a line (first hex formatted, then clear text)
Note:
If terminal window is hidden data is not printed on it.


Generated on Wed Dec 3 10:18:42 2003 for Easy Control