COM Port Command
ARAP can use the Nova Astronomics COM Port Driver to communicate with RS232 serial devices connected to a COM port. Up to 10 COM ports can be used simultaneously.
All COM Port related commands are accessed using the single ARAP command 'comport' with one or more parameters added. All commands set the boolean variable COMPORTERROR to "true" if an error occurs or "false" if no error occurs.
Syntax: comport command <option1> <option2>
Most COM Port commands update the following variables:
- COMPORTERROR - "true" if an error occurs or if serial data was not received.
- COMPORTCONNECTED - "true" when ARAP is connected to the COM Port driver.
- COMPORTOUTPUT - information returned from many 'comport' commands.
In general, the operational steps are:
- before using any other COM Port commands, comport on must be used to connect to the driver
- then select an active port using the activeport command (1 to 10). The default is 1.
- set the COM Port parameters with the port, baudrate, parity, and/or stopbits commands
- then use the open command to open the port
- use the putbyte, putstring, getbyte, getchar, and/or getstring commands
- and finally close the port with the close command and disconnect from the driver with the off command
The available COM Port commands are below:
- on and off
- activeport
- open and close
- port
- baudrate
- parity
- databits
- logging
- putbyte
- putstring
- getbyte
- getchar
- getstring
- getcomports
Syntax: comport on
This command connects to the COM Port driver software. If this operation is successful, the variable COMPORTCONNECTED is set to "true". All commands in this section must be preceded by this command.
Syntax: comport off
This command disconnects from the COM Port driver software. If this operation is successful, the variable COMPORTCONNECTED is set to "false".
Syntax: comport active port_no
This command sets active driver port to "port_no" (1 to 10). The default is 1. After this command is done, all subsequent commands use this active port. This allows up to 10 COM ports to be open at the same time and with different communication parameters. If the specified port is not valid, COMPORTERROR is "true".
Syntax: comport open
This command opens the COM port using the current settings (as set by the port, baudrate, parity, and databits commands below). If the port fails to open, COMPORTERROR is "true".
Syntax: comport close
This command closes the COM port. If the port fails to close, COMPORTERROR is "true".
Syntax: comport port comport_no
This command sets the COM port used to "comport_no" (1 to 254). The default is COM1. This command cannot be used when the COM port is "open". If the specified port is not valid, COMPORTERROR is "true".
Syntax: comport baudrate baud_rate
This command sets the baud rate to "baud_rate". The default is 9600. This command cannot be used when the COM port is "open". If the specified baud rate is not valid, COMPORTERROR is "true".
Syntax: comport parity parity_code
This command sets the parity to "parity_code". The valid parity codes are:
0 - None (default)
1 - Odd
2 - Even
3 - Mark
4 - Space
This command cannot be used when the COM port is "open". If the specified parity code is not valid, COMPORTERROR is "true".
Syntax: comport databits bits
This command sets the data bits to "bits" (5 to 8). The default is 8 bits. This command cannot be used when the COM port is "open". If the specified data bits is not valid, COMPORTERROR is "true".
Syntax: comport logging on|off
This command sets the logging of serial data and errors, in the COM Port driver software "on" or "off". This can be used to diagnose serial communication problems.
Syntax: comport putbyte byte
This command sends a single character "byte" (by its numeric value - 0 to 255 are valid) to the COM port. This command cannot be used when the COM port is not "open".
Syntax: comport putstring string
This command sends the character string "string" to the COM Port. This command cannot be used when the COM port is not "open".
Syntax: comport getbyte
This command receives a single character from the COM Port and returns its numeric value (0 to 255) in the variable COMPORTOUTPUT. It does not wait for a character to be received, so if no character was received, COMPORTERROR is "true". This command cannot be used when the COM port is not "open".
Syntax: comport getchar
This command receives a single character from the COM Port and returns it as a string in the variable COMPORTOUTPUT. It does not wait for a character to be received, so if no character was received, COMPORTERROR is "true". This command cannot be used when the COM port is not "open".
Syntax: comport getstring timeout termchar
This command receives a string from the COM Port, terminated by the character "termchar" and returns it as a string in the variable COMPORTOUTPUT. It waits up to "timeout" milli-seconds (max is 60 seconds) for "termchar" to be received. If the "termchar" was not received in time, COMPORTERROR is "true". This command cannot be used when the COM port is not "open".
Syntax: comport flush
This command flushes (empties) all received characters from the COM Port's input buffer. This command cannot be used when the COM port is not "open".
Syntax: comport getcomports
This command sets the variable COMPORTOUTPUT to a comma separated list of the COM Ports that exist on the system, for example "COM1,COM4,COM10". If an error occurs retrieving the list, COMPORTERROR is "true".