ComSerialConfig

This input structure defines which COM port is to be used and opened with which parameters.

If a parameter is changed during cyclic calls of SerialLineControlADS, the existing COM port connection is closed automatically, and the serial COM port is opened with the new parameter. It is not necessary to close the port explicitly by resetting the input Connect.

(* contains the configuration parameters of the com port to be opened. *)
TYPE ComSerialConfig :
STRUCT
    ComPort  : UDINT :=1;         (* Serial port number [1..255] *)
    Baudrate : UDINT :=9600;
    Parity   : ComParity_t :=PARITY_NONE;
    DataBits : INT :=8;           (* [4..8] *)
    StopBits : ComStopBits_t :=STOPBITS_ONE;

    DTR      : ComDTRCtrl_t :=DTR_CTRL_HANDSHAKE; (* 'Data Terminal Ready' signal *)
    RTS      : ComRTSCtrl_t :=RTS_CTRL_HANDSHAKE; (* 'Request to Send' signal (= RFR 'Ready for Receiving') *)
    CTS      : BOOL :=FALSE;      (* 'Clear to Send' signal *)
    DSR      : BOOL :=FALSE;      (* 'Dataset Ready' signal *)

    TraceLevel : BYTE     :=0;     (* None=0;Error=1,Warning=2,Info=3,Verbose=4,Noise=5 *)

    Reserved1  : BYTE;
    Reserved2  : BYTE;
    Reserved3  : BYTE;
END_STRUCT
END_TYPE

Name

Description

ComPort

Windows operating system:
Any COM port (COM1, ..., COM255) can be selected. The Windows hardware device manager indicates which number a driver (e.g. a USB-to-virtual-COM-port driver) has assigned.

TwinCAT/BSD® operating system:
Serial ports with the device names 'ttyU0' (or 'ttyu0') to 'ttyU255' (or 'ttyu255') can be chosen. The number assigned to a driver (e.g. a USB-To-Virtual-Com-Port driver) can be found in the /dev/ folder. A device name 'ttyU2' (USB device) is preferred over 'ttyu2' (serial HW port).

Baud rate

All standard baud rates can be set, from 150 baud up to 128000 baud. The default is 9600 baud. 115200 baud is also a common transfer rate.

Parity

The parity check for the serial data transmission is set here. Possible values are summarized in the enumeration ComParity_t.

DataBits

The number of data bits for the serial data transmission is set here. Possible values are 4, 5, 6, 7 and 8.
Although complete data bytes are still transferred to the PLC buffer if the value is smaller than 8 bits, not all 8 bits of a byte are transferred via the serial interface. The most significant bits are truncated before transmission, which reduces the amount of bits per byte of data to be transmitted.
This setting was mainly useful in earlier times if you knew that the most significant bits in each byte would never be used and you wanted to increase the data transfer rate. Nowadays it is rarely used, so that it is recommended to leave the number of data bits at 8 [default].

StopBits

The number of stop bits for the serial data transmission is set here. Possible values are summarized in the enumeration ComStopBits_t.

RTS

The 'Request to Send' signal ( = RFR 'Ready for Receiving' ) for the serial data transmission is set here. Possible values are summarized in the enumeration ComRTSCtrl_t.

DTR

The 'Data Terminal Ready' signal for the serial data transmission is set here. Possible values are summarized in the enumeration ComDTRCtrl_t.

CTS

The 'Clear to Send' signal for the serial data transmission is set here. If the value is TRUE, no data are sent if the CTS input signal for the data transmission is not set.

DSR

The 'Dataset Ready' signal for the serial data transmission is set here. If the value is TRUE, no data are sent if the DSR input signal for the data transmission is not set. If DSR is TRUE, received data bytes are ignored, if the DSR input signal for the data transmission is not set.

TraceLevel

This input can be used to configure the output of messages (debug traces) by the TcAdsSerialCommServer.
This does not affect the error messages at the output of the PLC function block SerialLineControlADS. This is therefore an additional diagnostic option.

The following trace levels are possible:
None: 0 (default)
Error: 1
Warning: 2
Info: 3
Verbose: 4
Noise: 5

All messages with a level less than or equal to the specified level are output. If level 'None' is selected, no messages are output.

With level 'Noise', even data received at the serial port and data sent to the serial port are output in the messages. This option requires considerable system resources and should therefore only be selected for temporary testing purposes.

Debug traces are used as output. Under Big Windows operating systems, error/warning/information messages are also output as log events (application log).

Note: If the DebugView Windows tool (from SysInternals) is used, the setting CaptureGlobalWin32 must be active in order to receive the messages.

Under TwinCAT/BSD operating systems the messages are stored in /var/log/messages.

ComSerialConfig 1:

Invalid parameterization

Not all parameter settings for serial data transmission may be available in all cases. Some settings or combinations are not supported by the operating system (Windows, TwinCAT/BSD) or by COM port drivers or the hardware.

Example: In some cases the 1.5 stop bits or the 4 data bits options, or the combination of 5 data bits & 2 stop bits are not supported. Or the baud rate may be limited to a maximum of 115200 baud. Please also check the interface description of the respective embedded PC / IPC (e.g. Interface description of the CX52x0).

Further information on the parameters of a serial data transmission under Windows can be found in the Microsoft MSDN description of the DCB structure.

Requirements

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4016

PC or CX (x86, x64)

Tc2_SerialCom