Y_CO_CommunicationChannel
Parameters
| * | Parameter | Data Type | Description | Default |
|---|---|---|---|---|
| VAR_IN_OUT | ||||
| V | CircularByteBuffer | Yt_CO_CircularBufferStruct | Structure containing a data buffer and other operational information required to manage the CircularByteBuffer. | |
| V | CommConfig | Yt_CO_CommStruct | Structure containing information to be used in establishing socket or serial communication. | |
| VAR_INPUT | ||||
| V | Enable | BOOL | The function will continue to execute every scan while Enable is held high and there are no errors. | FALSE |
| V | ClearBuffer | BOOL | Resets the StorePointer and UsePointer, which logically clears the contents of the circular buffer, but any existing data is not actually cleared. | FALSE |
| V | Timeout | TIME | This input is used only for fixed mode Command Type specified in Yt_CO_CommStruct. If the specified packet sizes does not arrive within the timeout specified , a packet size error is generated. The timeout period starts only after a successful connection is established. | TIME#0s |
| VAR_OUTPUT | ||||
| V | Valid | BOOL | Indicates that the function is operating normally and the outputs of the function are valid. | |
| V | Busy | BOOL | Set high upon the rising edge of the Execute input, and reset when Done, CommandAborted, or Error is true. In the case of a function block with an Enable input, a Busy output indicates the function is operating, but not ready to provide Valid information. (No Error) | |
| V | Error | BOOL | Set high if an error has occurred during the execution of the function block. This output is cleared when 'Execute' or 'Enable' goes low. | |
| V | ErrorID | UINT | If Error is true, this output provides the Error ID. This output is reset when 'Execute' or 'Enable' goes low. | |
| V | Socket | DINT |
File handle to be used when writing to device connected to the socket. Only valid when non-zero.
|
|
| V | PacketCount | UDINT | Total packet count since this function block was enabled. | |
| V | BytesReceived | UDINT | Total bytes received since this function was enabled. | |
| V | BytesPerSec | DINT | Bytes received per second. | |
Notes
-
Busy output will turn on for an additional scan after enable is set false due to cleaning up the internal communication function blocks.
-
In "Fixed" Command Type the timeout will Reset after a valid set of data is received. If bad data or no data is received before the timeout occurs then a 12033 error will occur. It will automatically reset when the correct is received.
-
In "Fixed" command type, if invalid data is received it will not get added to the circular buffer. Only data with the valid length is added to the circular buffer.
Error Description
Example 1
The example below shows how to use Y_CO_CommunicationChannel function block for variable length packets. Initialize the CommConfig structure of Y_CO_CommunicationChannel with the following example values.
Set the datatype of the 'TransmitionData' variable to a Yt_CO_CircularBufferStruct. Set the enable input high on the CommunicationChannel Function Block.
We use the same iC9200 as the sender (client device) in this example. Add the following additional function blocks to the same project. The TLS_Socket FB creates a handle from the client side that will be used to send data to the port used by the Y_CO_CommunicationChannel FB (server). The Destination port on the client side will be the local port on the server side. The TLS_SEND FB is used to send data using the handle created by the TLS_SOCKET FB.
Populate the "TransmitData" variable using the watch window as shown below.
If the data is sent successfully by the TLS_SEND FB, the data will appear in the 'TransmitionData' circular buffer variable on the Y_CO_CommunicationChannel FB.
Example 2
The example below shows how to use Y_CO_CommunicationChannel function block for fixed length packets. Initialize the CommConfig structure of Y_CO_CommunicationChannel with the following example values.
Set the "TransmitData" Datatype toByteArray40 and Populate the "TransmitData" variable using the Init Value Configuration window as shown below. Then Write and Warm
Set the datatype of the 'TransmitionData' variable to a CircularByteBuffer.Set the enable input high on the CommunicationChannel Function Block.
Set the Timeout input to 30s. This specifies that the correct data needs to be received every "30s" otherwise and error will occur.
We use the same iC9200 as the sender (client device). Add the following additional function blocks to the same project. The TLS_Socket FB creates a handle from the client side that will be used to send data to the port used by the Y_CO_CommunicationChannel FB (server). The Destination port on the client side will be the local port on the server side. The TLS_SEND FB is used to send data using the handle created by the TLS_SOCKET FB.
If the data is sent successfully by the TLS_SEND FB, the data will appear in the 'TransmitionData' circular buffer variable on the Y_CO_CommunicationChannel FB.