Type | Format | Description |
Function | ClosePort(PortNo.) | Closes the serial port. |
Subroutine | EnableDriver(“DeviceName”, “StationName”, Enable/Disable) | Controls the selected station’s communication. |
Function | GetCommStatus(“DeviceName”, “StationName”) | Checks the selected station’s communication status. |
Function | OpenPort(PortNo., BaudRate, Parity, Data Bit, Stop Bit) | Opens the serial port. |
Function | ReceiveByte(PortNo., Data) | Receives data with the selected port. |
Function | SendByte(PortNo., Data) | Sends byte data with the selected port. |
Function | SendString(PortNo., Data) | Sends string data with the selected port. |
| - EnableDriver() command only supports MODBUS RTU. (XpanelDesigner V2.52) - GetCommStatus() command can only be used in the XpanelDesigner V2.52 or above. |
PortNo., BaudRate, Parity, Stop Bit use predefined constants. Refer to the table shown below for the details.
Constant Name | Value | Usage |
_COM232_ | 0 | Uses COM1 port as RS232C mode. |
_COM422_ | 1 | Uses COM1 port as RS422 mode. |
_COM485_ | 2 | Uses COM1 port as RS485 mode. |
_COMAUX_ | 3 | Uses COM2 port as RS232C mode only. |
_BPS300_ |
| 300 bps (Baudrate) |
_BPS600_ |
| 600bps (Baudrate) |
_BPS1200_ |
| 1200bps (Baudrate) |
_BPS2400_ |
| 2400bps (Baudrate) |
_BPS4800_ |
| 4800bps (Baudrate) |
_BPS9600_ |
| 9600bps (Baudrate) |
_BPS19200_ |
| 19200bps (Baudrate) |
_BPS38400_ |
| 38400bps (Baudrate) |
_BPS56000_ |
| 56000bps (Baudrate) |
_BPS57600_ |
| 57600bps (Baudrate) |
_BPS115200_ |
| 115200bps (Baudrate) |
_BPS128000_ |
| 128000bps (Baudrate) |
_BPS256000_ |
| 256000bps (Baudrate) |
_PARITY_NONE_ |
| No parity bit |
_PARITY_EVEN_ |
| Even parity |
_PARITY_ODD_ |
| Odd parity |
_PARITY_MARK_ |
| Mark parity |
_PARITY_SPACE_ |
| Space Parity |
_STOPBIT_ONE_ |
| 1 STOP bit |
_STOPBIT_TWO_ |
| 2 STOP bits |
_STOPBIT_ONE5_ |
| 1.5 STOP bit |
ClosePort | Closes the serial port. |
Function | n=ClosePort(PortNo.) |
Description | PortNo. (use predefined constant, _COMxxx_) Closes the assigned serial port which was previously opened by the OpenPort() function. If an error occurs during the port closing, the script will return 0. If the port closed successfully, the script would return a value other than 0. |
Example | Closes COM1 port. ClosePort(_COM485_); |
EnableDriver | Controls the selected station’s communication. |
Subroutine | EnableDriver(“DeviceName”, “StationName”, Enable/Disable) |
Description | Controls the communication of the assigned StationName of the DeviceName. You may Enable/Disable the communication with: 0: Disable 1: Enable This function only supports MODBUS RTU at XpanelDesigner V2.52 and versions above. |
Example | Enables the station “STATION” of the “MODBUS” device. EnableDriver(“MODBUS”, “STATION”, 1); |
GetCommStatus | Checks the selected station’s communication status. |
Function | GetCommStatus(“DeviceName”, “StationName”) |
Description | Returns the status of the assigned DeviceName ‘s StationName. If the communication is normal, the script will return 1. If there is an error with the communication, the script will return 0. |
Example | Checks the communication status of the “PLC” device’s station: “STATION”. CommStatus = GetCommStatus(“PLC”,”STATION”); |
OpenPort | Opens the serial port. |
Function | n=OpenPort(PortNo., BaudRate, Parity, Data Bit, Stop Bit) |
Description | PortNo. (use predefined constant, _COMxxx_) BaudRate (use predefined constant, _BPSxxx_) Parity (use predefined constant, _PARITY_xxx_) Data Bit (7 or 8) Stop Bit (use predefined constant, _STOPBIT_xxx_) This function opens the assigned serial port. You cannot use this function if the port has already been opened. Once you opened the COM port with the script, it must be closed with ClosePort() function. If an error occurs during the port opening, the script will return 0. If the port opened successfully, the script would return a value other than 0. |
Example | Opens COM1 port with the following options; RS485, 19200bps, No Parity, Data Bit 8, Stop Bit 1. OpenPort(_COM485_, _BPS19200_, _PARITY_NONE_, 8, _STOPBIT_ONE_); |
ReceiveByte | Receives data with the selected port. |
Function | ReceiveByte(PortNo., Data) |
Description | PortNo. (use predefined constant, _COMxxx_) Data (0~255) This function is used when you wish to receive data with the COM port that was previously opened by the OpenPort() function. Once you receive the data successfully, the Data (0~255) will be stored in the variable. If there is no received data until the timeout, the script will return 256. The OpenPort() function must be used before the execution of the ReceiveByte() function. |
Example | Receives byte data through the COM1 port which uses RS485 communication. Saves the received data at the variable ‘RxData’. VAR RxData; OpenPort(_COM485_, _BPS19200_, _PARITY_NONE_, 8, _STOPBIT_ONE_); RxData = ReceiveByte(_COM485_, 1000); If(RxData < 256) { } …… |
SendByte | Sends byte data through the selected port. |
Function | n=SendByte(PortNo., Data) |
Description | PortNo. (use predefined constant, _COMxxx_) Data (0~255) This function is used when you wish to transmit data with the COM port that was previously opened by the OpenPort() function. Data must be byte data in the range of 0(0x00) to 255(0xFF). If the data is greater than 255(0xFF), only the lower byte will be transmitted. For example, if you assign Data with 0x1234, only 0x34 will be transmitted. The OpenPort() function must be used before the execution of the SendByte() function. If an error occurs during the data transmission, the script will return 0. If the data transmitted successfully, the script would return a value other than 0. |
Example | Transmits byte data “2” through COM1 port which uses RS485 communication. SendByte(_COM485_, 2); |
SendString | Sends string data through the selected port. |
Function | SendString(PortNo., Data) |
Description | PortNo. (use predefined constant, _COMxxx_) Data (Enter the String Tag or “String”) This function is used when you wish to transmit data with the COM port that was previously opened by the OpenPort() function. The Data must be assigned with a string tag or string data. If you use the string data, it must be used with double quotation marks (“ “). The OpenPort() function must be used before the execution of the SendString() function. If an error occurs during the data transmission, the script will return 0. If the data transmits successfully, the script will return a value other than 0. |
Example | Transmits string data “TEXT” through COM1 port which uses RS485 communication. SendString(_COM485_, “TEXT”); |