X2-BoX2 Serial comms FBs Codesys Library
Product Information
The Serial comms FBs – CODESYS library is a library for serial
communication that is compatible with X2Control and BoX2Control
devices with embedded CODESYS runtime. This library simplifies
serial communications from the X2 Control to serial devices such as
barcode readers, weigh scales, and printers. Most parameters are
set with ENUMs to reduce errors. The FB can act as a manager for
send/receive (for devices that need a prompt) or just cause the
port to listen (for unsolicited messages). Message termination can
be by termination character or receiving a pre-defined number of
characters. All three serial ports of an X2 / BoX2 control can be
used (COM1, COM2 and COM3).
Product Usage Instructions
To use the Serial comms FBs – CODESYS library:
- Install the library file (*.compiled-library) to the CODESYS
software on your PC. - Access the FBs as any blocks by following guidelines and
description. - Set most parameters using ENUMs to reduce errors.
- Select whether the FB should act as a manager for send/receive
or just cause the port to listen. - Select message termination by termination character or
receiving a pre-defined number of characters. - Use all three serial ports of an X2 / BoX2 control (COM1, COM2
and COM3) for serial communication.
Quick start guide
Serial comms FBs – CODESYS library
SER0001 Quick st art Serial communicat ion
Serial comms FBs – CODESYS library
SER0001_V1. 0. 7 2022-04
1 Function and area of use
This document explains the CODESYS library for serial communication. Target device X2 / BoX2 control series, with embedded CODESYS runtime.
2 About this document
This quick start document should not be considered as a complete manual. It is an aid to be able to startup a normal application quickly and easily.
Copyright © Beijer Electronics, 2022 This documentation (below referred to as `the material’) is the property of Beijer Electronics. The holder or user has a non-exclusive right to use the material. The holder is not allowed to distribute the material to anyone outside his/her organization except in cases where the material is part of a system that is supplied by the holder to his/her customer. The material may only be used with products or software supplied by Beijer Electronics. Beijer Electronics assumes no responsibility for any defects in the material, or for any consequences that might arise from the use of the material. It is the responsibility of the holder to ensure that any systems, for whatever applications, which is based on or includes the material (whether in its entirety or in parts), meets the expected properties or functional requirements. Beijer Electronics has no obligation to supply the holder with updated versions.
Use the following hardware, software, drivers and utilities in order to obtain a stable application:
In this document we have used following software and hardware · BCS Tools 3.34 or CODESYS 3.5 SP13 patch 3 · X2 control and BoX2 control devices
For further information refer to · CODESYS online help · Installation manual X2 control (MAxx202) · Beijer Electronics knowledge database, HelpOnline
This document and other quick start documents can be obtained from our homepage. Please use the address [email protected] for feedback.
Normal.dotm, 2020-07-01
2 (11)
Serial comms FBs – CODESYS library
SER0001_V1. 0. 7 2022-04
3 Table of Cont ents
1 Function and area of use. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 About this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3 Table of Contents. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 Serial communications with CODESYS function blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
5 Preparing your editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Inst al l at ion of t he l i br ar y t o your edit or . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Add t he l i br ar y int o your pr oj ect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
6 Description of function blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 f bdConf igur ePor t . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 f bdGener icSendReceive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
7 Special characters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
8 About Beij er Electronics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 Cont act us . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Normal.dotm, 2020-07-01
3 (11)
Serial comms FBs – CODESYS library
SER0001_V1. 0. 7 2022-04
4 Serial communications with CODESYS function blocks
This library is compatible with X2Control and BoX2Control devices (DeviceId 0x1024)
This library simplifies serial communications from the X2 Control to serial devices such as barcode readers, weigh scales, and printers.
Most parameters are set with ENUMs to reduce errors.
The FB can act as a manager for send/receive (for devices that need a prompt) or just cause the port to listen (for unsolicited messages).
Message termination can be by termination character or receiving a pre-defined number of characters.
All three serial ports of an X2 / BoX2 control can be used (COM1, COM2 and COM3).
The library file (*.compiled-library) can be installed to the CODESYS software on your PC and the FBs be accessed as any blocks, please follow guidelines and description.
Normal.dotm, 2020-07-01
4 (11)
Serial comms FBs – CODESYS library
SER0001_V1. 0. 7 2022-04
5 Preparing your editor
The following chapter describes important procedures and settings needed for a well functioning system.
Installation of the library to your editor
The *.compiled-library needs to be made available in your system so it can be included in projects. This is done by accessing the `Library Manager”Library Repository’ then `Install’.
Navigate to the folder where you have put the *.compiled-library. This procedure will need to be repeated if you use a new PC.
Note, the location of System path may differ depending if using BCS Tools or CODESYS software tool and what version of the software.
Add the library into your proj ect
The new library is now available for you to include in your specific project (example screenshot):
The selected library is now visible in the Library Manager. Its public objects and supplementary help is available here.
5 (11)
Normal.dotm, 2020-07-01
Serial comms FBs – CODESYS library
6 Description of function blocks
SER0001_V1. 0. 7 2022-04
fbdConfigurePort
The FB fbdConfigurePort is required to set the port’s parameters.
Match the port settings to the device you’re talking to. Simply invoke and enter the appropriate port, baud, data bits, parity and stop bits.
All parameters are ENUMs.
Name Execute
PortNumber Baud DataBits Parity StopBits IncompatibleHardware
Scope VAR_IN
VAR_IN VAR_IN VAR_IN VAR_IN VAR_IN VAR_OUT
Type BOOL
ePortNumber eBaudRate eDatabits eParity eStopBits BOOL
Comment Configures the port’s parameters on the rising edge Choose the serial port
Target is not an X2Control or BoX2Control device
Normal.dotm, 2020-07-01
6 (11)
Serial comms FBs – CODESYS library
SER0001_V1. 0. 7 2022-04
fbdGenericSendReceive
This FB provides functionality to interact via a com port to a device.
The type can be ‘Polled’ or ‘Listening’. Polled is used to send a request to a device and wait for a response (typically a weighscale). Listening simply waits for an unsolicited incoming message (typically a barcode reader).
The incoming message can be terminated one of two ways:
· Receiving a termination character (for example CRLF)
· After receiving a pre-defined number of characters.
BothTransactionTypes can be used with either TerminationTypes.
It won’t execute until that port’s parameters have been set.
Examples:
a) This configuration will wait (as long as Execute is high) for an un-prompted frame which is terminated with special characters: <CR><LF>
b) This configuration will (on the Execute rising edge) make a request and wait for a response, which is always padded to 10 characters.
Normal.dotm, 2020-07-01
7 (11)
Serial comms FBs – CODESYS library
SER0001_V1. 0. 7 2022-04
c) This configuration will (on the Execute rising edge) send a message and not wait for a reply.
fbdGenericSendReceive (datatypes)
Input PortNumber Execute
InhibitTimeout SendThis TransactionType TerminationType TerminationCharacter
CharactersToReceive
Type ePortNumber BOOL
BOOL STRING(255)
eTransactionType eTerminationType STRING(255)
INT
Initial
eTransactionTyp e.Polling eTerminationTy pe.Character ‘$R$N’
Comment Choose the serial port If transactionType is ‘Polling’ this rising edge initiates the send/receive. In ‘Listening’ mode, the port listens for as long as the flag is high For debugging comms only. Normally FALSE In ‘Polling’ mode, this is the request sent to the device Used to choose the transaction type. Used to choose the termination type Valid if TerminationType is eTerminationType.Charact er Valid if TerminationType is eTerminationType.Count
8 (11)
Normal.dotm, 2020-07-01
Serial comms FBs – CODESYS library
Output Done Success
Type BOOL BOOL
SuccessCount PortIsOpen WhatIJustRead
StatusText
UDINT BOOL STRING(255)
STRING(255)
Initial
SER0001_V1. 0. 7 2022-04
Comment Indicates completion Indicate a successful completion i.e. the termination character has been received
The received string available for subsequent processing See below for possibilities
Status Text Idle Opening port
Clearing buffer Sending Looking for termination character Waiting for 10 characters Done, request high
Invalid parameters
Meaning Waiting for instruction Opening the port. This would indicate the port is already in use by another application Removing old characters from the buffer Sending the `SendThis’ string When the TerminationType is `Character’
When the TransactionType is `Count’
For TransactionTypes `Polling’ or `NoReply’ this indicates the sequence is finished and waiting a new rising edge In TerminationMode `Character’, no termination character has been specified. In TerminationMode `Count’, the count is 0 or greater than 255
Normal.dotm, 2020-07-01
9 (11)
Serial comms FBs – CODESYS library
7 Special charact ers
Codesys identifies special characters (non-printable) with escape sequences. This is a snippet from the Codesys Help Online.
SER0001_V1. 0. 7 2022-04
Normal.dotm, 2020-07-01
10 (11)
Serial comms FBs – CODESYS library
8 About Beij er Electronics
SER0001_V1. 0. 7 2022-04
Beijer Electronics is a multinational, cross-industry innovator that connects people and technologies to optimize processes for business-critical applications. Our offer includes operator communication, automation solutions, digitalization, display solutions and support. As experts in user-friendly software, hardware and services for the Industrial Internet of Things, we empower you to meet your challenges through leading-edge solutions.
Beijer Electronics is a BEIJER GROUP company. Beijer Group has a sale over 1.6 billion SEK in 2021 and is listed on the Nasdaq Stockholm Main Market under the ticker BELE. www.beijergroup.com
China
Denmark
France
Germany
India
Norway
South Korea
Sweden HQ
Taiwan
Turkey
United Kingdom
USA
BeNeLux
Contact us
Global offices and distributors
Normal.dotm, 2020-07-01
11 (11)


















