SerialLineControlADS
The function block SerialLineControlADS
handles the communication between a virtual serial interface and the PLC. The function block is called cyclically, and places received data into the RxBuffer
. Data made available in the transmit buffer TxBuffer
is sent to the interface at the same time.
Since the function is handled independent of the application, it is referred to as background communication. Just like the function block SerialLineControl
, it can also be handled in a fast task. Normally, however, the function block can be called in the standard task and a separate second, faster task can be dispensed with. (see communication concept and assisted hardware).
When the function block is called cyclically and the input Connect
is set, the parameterized serial COM port is opened automatically.
This means that this COM port is blocked for other applications. To enable the COM port for access from another application, you can reset the input Connect. The current port is then closed. If a different COM port or a different parameterization is selected in the input structure SerialCfg, the previous port is closed automatically and the new port is opened.
Inputs
VAR_INPUT
Connect : BOOL; (* connect to serial port [TRUE=connect, FALSE=disconnect] *)
SerialCfg : ComSerialConfig;
NetId : T_AmsNetId := ''; (* host NetId *)
Timeout : TIME := DEFAULT_ADS_TIMEOUT; (* Timeout for ADS calls *)
END_VAR
Name | Type | Description |
---|---|---|
Connect | BOOL | To initialize a connection to a serial port, Connect TRUE must be applied to the function block. If Connect is FALSE, an opened port is closed again. |
SerialCfg | This input structure defines which COM port is to be used and opened with which parameters. | |
NetId | T_AmsNetId | To execute the query on the local device, it is not necessary to specify this input variable. Alternatively, an empty string can be specified. To direct the request to another TwinCAT target device, the corresponding AMS Net Id can be specified here. |
Timeout | TIME | Specifies a maximum duration of time for the execution of the function block. The default value is 5 seconds. (A value of at least 1000 ms should be specified) |
Inputs/outputs
VAR_IN_OUT
TxBuffer : ComBuffer;
RxBuffer : ComBuffer;
END_VAR
Name | Type | Description |
---|---|---|
TxBuffer | Buffer with send data for the serial interface being used. The transmit buffer is filled by functions such as SendByte, SendData or SendString. | |
RxBuffer | Buffer into which received data is placed. The receive buffer is read by functions such as ReceiveByte, ReceiveData or ReceiveString. |
Outputs
VAR_OUTPUT
PortOpened : BOOL; (* Indicates if selected serial port is opened *)
Error : BOOL; (* 'TRUE' if an error occurred *)
ErrorID : UDINT; (* Displays the error code; 0 = no error *)
Busy : BOOL; (* 'TRUE' if internal ADS communication is busy *)
TxBufCount : UDINT; (* number of bytes in internal Tx buffer *)
RxBufCount : UDINT; (* number of bytes in internal Rx buffer *)
END_VAR
Name | Type | Description |
---|---|---|
PortOpened | BOOL | This output indicates whether the selected serial port is opened and linked. |
Error | BOOL | This output Error goes TRUE as soon as an error occurs. |
ErrorID | UDINT | The ErrorID output provides an error code when an error occurs. A list of possible values and notes on troubleshooting can be found in section Error codes. |
Busy | BOOL | This output is TRUE as long as the internal ADS communication of the function block is active. |
TxBufCount | UDINT | The output TxBufCount indicates whether the internal PLC buffer still contains data bytes that have not yet been sent. |
RxBufCount | UDINT | The output RxBufCount can be used to determine whether there are still received data bytes in the internal PLC buffer that have not yet been transferred to the RxBuffer. |
Requirements
Development environment |
Target platform |
PLC libraries to include |
---|---|---|
TwinCAT v3.1.4016 |
PC or CX (x86, x64) |
Tc2_SerialCom |