Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

In this section, you can find functions and subroutines frequently used for controlling I/O devices. For more detailed information, please refer to the next section.

(blue star)

All functions must be used with brackets.

Command

Description

Communication

Function

OpenPort

Opens the serial port.

Function

ClosePort

Closes the serial port.

Function

SendByte

Sends byte data with the selected port.

Function

SendString

Sends string data with the selected port.

Function

ReceiveByte

Receives data with the selected port.

Function

GetCommStatus

Checks the selected station’s communication status.

Subroutine

EnableDriver

Controls the selected station’s communication.

(blue star)

- EnableDriver() command only supports MODBUS RTU (XpanelDesigner V2.53).

- GetCommStatus() command can only be used in XpanelDesigner V2.53 or above.

PortNo., BaudRate, Parity, and Stop Bit use predefined constants. Refer to the table shown below for 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.

_BPS300_

 

300 bps

_BPS600_

 

600bps

_BPS1200_

 

1200bps

_BPS2400_

 

2400bps

_BPS4800_

 

4800bps

_BPS9600_

 

9600bps

_BPS19200_

 

19200bps

_BPS38400_

 

38400bps

_BPS56000_

 

56000bps

_BPS57600_

 

57600bps

_BPS115200_

 

115200bps

_BPS128000_

 

128000bps

_BPS256000_

 

256000bps

_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

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 has to be closed with ClosePort() function.

When an error occurs during the port opening, the script will return 0. If the port is successfully opened, the script will return the value other than 0.

Example

Opens COM1 port with following options; RS485, 19200bps, No Parity, Data Bit 8, Stop Bit 1.

OpenPort(_COM485_, _BPS19200_, _PARITY_NONE_, 8, _STOPBIT_ONE_);

ClosePort

Closes the serial port.

Function

n=ClosePort(PortNo.)

Description

PortNo. (use predefined constant, _COMxxx_)

Closes the assigned serial port which is opened by the OpenPort() function.

When an error occurs during the port closing, the script will return 0. If the port is successfully closed, the script will return the value other than 0.

Example

Closes COM1 port.

ClosePort(_COM485_);

SendByte

Sends byte data with 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 a data with the COM port which is opened by OpenPort() function.

Data must be a 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.

OpenPort() function must be used before the execution of SendByte() function.

If an error occurs during the data transmission, the script will return 0.

If the data is successfully transmitted, the script will return the value other than 0.

Example

Transmits byte data “2” through COM1 port which uses RS485 communication.

SendByte(_COM485_, 2);

SendString

Sends string data with 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 a data with the COM port which is opened by OpenPort() function.

The Data must be assigned with string tag or string data. If you use the string data, it must be used with double quotation marks. (“ “)

OpenPort() function must be used before the execution of SendString() function.

If an error occurs during the data transmission, the script will return 0.

If the data is successfully transmitted, the script will return the value other than 0.

Example

Transmits byte data “TEXT” through COM1 port which uses RS485 communication.

SendString(_COM485_, “TEXT”);

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 a data with the COM port which is opened by 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.

OpenPort() function must be used before the execution of 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 = RecieveByte(_COM485_, 1000);

If(RxData < 256)

{

}

……

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 at the communication, the script will return 0.

Example

Checks the communication status of the device “PLC”’s station “STATION”.

CommStatus = GetCommStatus(“PLC”,”STATION);

EnableDriver

Controls the selected station’s communication.

Subroutine

EnableDriver(“DeviceName”, “StationName”, Enable/Disable)

Description

Controls the communication of the assigned DeviceName ‘s StationName.

Enter 1 to Enable/Disable to enable the communication. Enter 0 to disable the communication.

This function only supports MODBUS RTU at XpanelDesigner V2.52.

Example

Enables the station “STATION “ of “MODBUS” device.

EnableDriver(“MODBUS”, “STATION”, 1);

  • No labels