ph_comopen PowerHome formula function
Description
Opens the specified COM control. PowerHome provides the user with 5 COM controls that can be opened and characters received and written to.
Syntax
ph_comopen ( comnum, comport, bps, parity, databits, stopbits, rthreshold, sthreshold, handshaking, inputmode, nulldiscard, rtsenable, dtrenable, parityreplace, id )
Argument |
Description |
comnum
|
The number of the COM control you are referencing. Valid values are 1 thru 5.
|
comport
|
The COM port you wish to open. Typically a number from 1 to 8 but can be higher.
|
bps
|
The speed at which the port should be opened. A typically value would be 9600.
|
parity
|
The parity the port should be opened. Valid values are "E", "O", and "N".
|
databits
|
The number of bits within a byte that represent data. Typical values would be 7 with even or odd parity and 8 with no parity.
|
stopbits
|
The number of stop bits. Typically 1.
|
rthreshold
|
The number of bytes to receive in the incoming buffer before the receive macro is fired. A value of 1 will cause the receive macro to execute every time a character is received (Assuming the characters are read as soon as they are received).
|
sthreshold
|
The number of bytes to store in the outgoing buffer before actually being sent out the COM port. A value of 0 will force bytes to be sent immediately.
|
handshaking
|
The value to use for handshaking. Use 0 for no handshaking, 1 for XON/OFF handshaking, 2 for RTS/CTS handshaking, and 3 for both XON/OFF and RTS/CTS handshaking.
|
inputmode
|
The manner in which to receive data. Use 0 for text data, 1 for binary data.
|
nulldiscard
|
Use a 0 to include null characters (ASCII 0) in the incoming buffer. Any other value will cause null characters to be discarded.
|
rtsenable
|
Use a 0 to disable the RTS line. Any other value will enable the RTS line.
|
dtrenable
|
Use a 0 to disable the DTR line. Any other value will enable the DTR line.
|
parityreplace
|
The character to be used to replace an invalid character when a parity error occurs. Typically this would be set to "?".
|
id
|
The ID of a macro to be called when characters are received.
|
Return value
Integer. Returns 0 if successful. Returns 1 if a comnum < 1 or > 5 is specified. Returns 2 if the specified COM is already open.
Usage
Allows the user to easily implement serial communications from within PowerHome. The COM control has an internal incoming buffer of 2048 characters. There are also two internal variables that track status of the incoming buffer. The buffercount variable keeps track of how many total characters are in the incoming buffer. The bufferptr variable points to the position of the last read character. Both these values start at zero. As characters arrive at the buffer, the buffercount variable is increased. If this value was zero and the ID parameter is not blank, the macro represented by the ID will be placed in the execution queue. As you read characters from the incoming buffer, the bufferptr variable is increased. When the bufferptr is equal to the buffercount (all characters have been read) both variables are reset to 0. If more characters are received, the macro will again be fired.