Beijer ELECTRONICS X2-BoX2 Serial comms FBs Codesys Library User Guide

October 30, 2023
Beijer ELECTRONICS

Beijer-ELECTRONICS-LOGO

Beijer ELECTRONICS X2-BoX2 Serial comms FBs Codesys Library

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-PRODUCT-IMG

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 terminating characters or receiving a predefined 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:

  1. Install the library file (*.compiled-library) to the CODESYS software on your PC.
  2. Access the FBs as any blocks by following guidelines and descriptions.
  3. Set most parameters using ENUMs to reduce errors.
  4. Select whether the FB should act as a manager for send/receive or just cause the port to listen.
  5. Select message termination by termination characters or receiving a predefined number of characters.
  6. Use all three serial ports of an X2 / BoX2 control (COM1, COM2and COM3) for serial communication.

Quick start guide

Serial comms FBs – CODESYS library

  • SER0001 – Quick start Serial communication

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-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.

About this document

  • This quick-start document should not be considered a complete manual. It is an aid to be able to start up 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 system, for whatever application, 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 the 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 support.europe@beijerelectronics.com for feedback.

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 terminating characters or receiving a predefined 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 on the CODESYS software on your PC and the FBs be accessed as any blocks, please follow the guidelines and description.

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-2

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’ and 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 the System path may differ depending if using BCS Tools or CODESYS software tool and what version of the software.

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-3

Add the library to your project

  • The new library is now available for you to include in your specific project (example screenshot):

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-4

  • The selected library is now visible in the Library Manager. Its public objects and supplementary help is available here.

Description of function blocks

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.

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-5

Name Scope Type Comment
Execute VAR_IN BOOL Configures the port’s parameters on the rising edge
PortNumber VAR_IN report number Choose the serial port
Baud VAR_IN ecaudate
DataBits VAR_IN data bits
Parity VAR_IN parity
StopBits VAR_IN eStopBits
IncompatibleHardware VAR_OUT BOOL Target is not an X2Control or BoX2Control

device

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 weigh scale). Listening simply waits for an unsolicited incoming message (typically a barcode reader).
  • The incoming message can be terminated in one of two ways:
    • Receiving a termination character (for example CRLF)
    • After receiving a predefined number of characters.
  • BothTransactionTypes can be used with either TerminationTypes.
  • It won’t execute until that port’s parameters have been set.

Examples

  • This configuration will wait (as long as Execute is high) for an un-prompted frame which is terminated with special characters:

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-6

  • This configuration will (on the Execute rising edge) make a request and wait for a response, which is always padded to 10 characters.

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-7

  • * This configuration will (on the Execute rising edge) send a message and not wait for a reply.![Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-FIG-8](https://manuals.plus/wp-content/uploads/2023/06/Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-FIG-8.png)

fbdGenericSendReceive (datatypes)

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-9

Input Type Initial Comment
PortNumber report number   Choose the serial port
Execute BOOL   If the transaction type is ‘Polling’ this rising edge

initiates the send/receive. In ‘Listening’ mode, the port listens for as long as the flag

is high

InhibitTimeout| BOOL|  | For debugging comms only.

Normally FALSE

SendThis| STRING(255)|  | In ‘Polling’ mode, this is the

request sent to the device

TransactionType| transaction type| eTransactionTyp

e.Polling

| Used to choose the

transaction type.

TerminationType| eTerminationType| determination

pe.Character

| Used to choose the

termination type

TerminationCharacter| STRING(255)| ‘$R$N’| Valid if TerminationType is eTerminationType.Charact

er

CharactersToReceive| INT|  | Valid if TerminationType is

eTerminationType.Count

Output Type Initial Comment
Done BOOL   Indicates completion
Success BOOL   Indicate a successful completion i.e. the termination

character has been received
SuccessCount| UDINE|  |
PortIsOpen| BOOL|  |
WhatIJustRead| STRING(255)|  | The received string available for subsequent processing
StatusText| STRING(255)|  | See below for possibilities
Status Text| Meaning
---|---
Idle| Waiting for instruction
Opening port| Opening the port. This would indicate the port is already in use by another application
Clearing buffer| Removing old characters from the buffer
Sending| Sending the ‘SendThis’ string
Looking for a termination character| When the TerminationType is ‘Character’
Waiting for 10 characters| When the TransactionType is ‘Count’
Done, request high| For TransactionTypes ‘Polling’ or ‘NoReply’ this indicates the sequence is finished and waiting for a new rising edge
Invalid parameters| In TerminationMode ‘Character’, no termination character has been specified. In TerminationMode ‘Count’, the count is 0 or greater than 255

Special characters

  • Codesys identifies special characters (non-printable) with escape sequences.
  • This is a snippet from Codesys Help Online.

Beijer-ELECTRONICS-X2-BoX2-Serial-comms-FBs-Codesys-Library-
FIG-10

About Beijer Electronics

  • 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 sales of over 1.6 billion SEK in 2021 and is listed on the Nasdaq Stockholm Main Market under the ticker BELE. www.beijergroup.com.

Contact us

Global offices and distributors.

References

Read User Manual Online (PDF format)

Read User Manual Online (PDF format)  >>

Download This Manual (PDF format)

Download this manual  >>

Beijer ELECTRONICS User Manuals

Related Manuals