Professional Documents
Culture Documents
E-mail: sales@deepseaelectronics.com
Website: www.deepseaelectronics.com
The DSE logo and the name DSEControl® are UK registered trademarks of Deep Sea Electronics Ltd.
Any reference to trademarked product names used within this publication is owned by their respective
companies.
Deep Sea Electronics reserves the right to change the contents of this document without prior notice.
TABLE OF CONTENTS
Section Page
1 INTRODUCTION .................................................................................................. 6
1.1 CLARIFICATION OF NOTATION ............................................................................................ 6
1.2 GLOSSARY OF TERMS .......................................................................................................... 7
1.3 RELATED INFORMATION ...................................................................................................... 8
1.3.1 SAMPLE PROJECT FILES ............................................................................................... 8
1.3.2 TECHNICAL INFORMATION ............................................................................................ 9
1.4 LIBRARY COMPATIBILITY AND VERSION NUMBERING ................................................. 10
1.5 SAFETY INSTRUCTIONS ..................................................................................................... 11
1.5.1 GENERAL ....................................................................................................................... 11
2 INSTALLATION ................................................................................................. 12
2.1 DSE_UTILS ............................................................................................................................ 12
3 LIBRARY USAGE.............................................................................................. 13
3.1 ADD TO LIBRARY MANAGER ............................................................................................. 13
3.2 DSE CAN FUNCTIONS LIBRARY ONLINE HELP ............................................................... 15
3.3 INITIALISE / DEINITIALISE THE CAN PORT(S) .................................................................. 16
3.3.1 INITIALISE....................................................................................................................... 16
3.3.2 DE-INITIALISE ................................................................................................................ 16
3.4 CAN RAW .............................................................................................................................. 17
3.4.1 RECEIVING MESSAGES ............................................................................................... 18
3.4.1.1 CANRECEIVE .......................................................................................................... 19
3.4.1.2 CANRECEIVEMASK ................................................................................................ 19
3.4.1.3 CANRECEIVESINGLE............................................................................................. 20
3.4.2 TRANSMITTING MESSAGES ........................................................................................ 21
3.4.2.1 CANTRANSMIT ....................................................................................................... 21
3.4.3 ADDING A WATCHDOG TO CAN RAW ........................................................................ 22
3.5 CAN J1939 ............................................................................................................................. 23
3.5.1 RECEIVING MESSAGES ............................................................................................... 23
3.5.1.1 J1939_RECEIVE ...................................................................................................... 24
3.5.1.2 READ_XXXX ............................................................................................................ 25
3.5.1.3 J1939_DM1_DM2 .................................................................................................... 27
3.5.2 TRANSMITTING MESSAGES ........................................................................................ 29
3.5.2.1 J1939_TRANSMIT ................................................................................................... 29
3.5.2.2 J1939_REQUEST .................................................................................................... 30
3.5.3 ADDING A WATCHDOG TO CAN J1939 ....................................................................... 31
3.5.4 HELPER FUNCTIONS .................................................................................................... 32
3.5.4.1 SLOT ........................................................................................................................ 32
3.5.4.2 J1939_DTCSCROLLER ........................................................................................... 33
3.5.4.3 J1939_DTCSCROLLER FUNCTION PARAMETERS ............................................. 34
3.5.4.4 J1939_BUILDTSC1 .................................................................................................. 35
3.6 CANDIAGNOSIS .................................................................................................................... 37
3.6.1 BUSSTATE...................................................................................................................... 38
3.6.1.1 DSEM640 & DSEM643 ............................................................................................ 38
3.6.1.2 DSEM840 ................................................................................................................. 39
3.6.1.3 DSEM870 & DSEM812 ............................................................................................ 39
4 LIBRARY APPLICATIONS ................................................................................ 40
4.1 DATA TRANSMISSION ......................................................................................................... 40
4.1.1 J1939 ............................................................................................................................... 40
4.1.2 CAN RAW........................................................................................................................ 40
4.1.3 REAL VALUES ................................................................................................................ 41
4.1.3.1 ADVANCED ............................................................................................................. 41
4.1.4 BOOL ............................................................................................................................... 42
4.1.5 STRING ........................................................................................................................... 42
4.2 LITTLE ENDIAN? ................................................................................................................... 43
4.2.1 DSE_UTILS ..................................................................................................................... 44
1 INTRODUCTION
This document details the CODESYS DSE CAN Functions Library. This provides CODESYS
functions to aid the use of the CAN port integrated with DSEControl® CODESYS range of products.
This document is not intended to detail the specification of CAN or associated protocols and
knowledge of these is assumed.
Prior knowledge of CODESYS and DSEMSeries devices is assumed.
Functions are provided to allow the DSE MSeries device to operate as a fully functional CAN Node
with both transmission and reception functions. Helper functions are also available to provide high-
level J1939 functionality such as reception of DM1 and DM2 (diagnostic messages) and transmission
of TSC1 (torque and speed control) messages.
The manual forms part of the product and should be kept for the entire life of the product. If the
product is passed or supplied to another party, ensure that this document is passed to them for
reference purposes.
This is not a controlled document. DSE do not automatically inform on updates. Any future updates of
this document are included on the DSE website at www.deepseaelectronics.com
These instructions and examples are for authorised persons and intended as a guide to using the
library. They do not form a complete application. The device must be programmed, tested, installed,
connected, and put into operation by qualified Engineers.
This document is supplied in a Zip file along with all program listings. These are supplied as is, as
examples, and do not constitute a complete working application. The principle described in the project
may be copy/pasted or exported/imported into your own application from where they must be fully
tested. It is the programmer’s responsibility to ensure all project operate safely, as expected, and as
required.
The supplied examples use device descriptor DSEM840-02 V4.1, however the code within functions
on all DSEMSeries CODESYS devices. To convert the project to suit other devices/versions:
Select Update
Device…
Click Update
Device after
selections
above
Click Close
when finished
NOTE: Operator Manuals also include CODESYS Software instructions except for
DSEM870 and DSEM812 whose CODESYS manuals are provided separate from the Operator
manual and listed separately.
NOTE: It is strongly recommended to use DSE CAN Functions Library V1.5 and above.
Change notes are listed elsewhere in this document.
Library version numbering is used to indicate compatibility and is in the form X.Y.Z
Example1:
Example2:
1.5.1 GENERAL
• These instructions and examples are for authorised persons and intended as a guide to using the
library. They do not form a complete application. The device must be programmed, tested,
installed, connected, and put into operation by qualified Engineers.
• The customer is responsible for performing risk analysis of the mobile working machine and
determining the possible safety related functions.
• The user is responsible for the safe function of the application programs created. If necessary,
they must additionally carry out an approval test by corresponding supervisory and test
organisations according to the national regulations.
2 INSTALLATION
NOTE: If you have an older version of DSE CODESYS Package, you do not need to
uninstall it before installing a newer version. Simply click Install and allow CODESYS to install
the new one.
Within
CODESYS
V3.5, select
Tools |
Package
Manager…
Click Close
when
finished
2.1 DSE_UTILS
Installation of the DSE CODESYS PACKAGE installs other DSE Compiled Libraries, including
DSE_UTILS. This includes a suite of conversion functions, useful for packing and unpacking data to
and from CAN messages. Online help for DSE_UTILS is included within CODESYS Library Manager.
3 LIBRARY USAGE
NOTE: For a full list of struct members, enumerations, function blocks and functions, see
CODESYS Online Help within the Library Manager. For further details, see section entitled DSE
CAN Functions Library Online Help elsewhere in this manual.
Click Add
Library
Click Advanced…
NOTE: Select Company: All Companies to allow selection of DSE Libraries produced prior
to the change of company name. All DSE Libraries are now produced under the name Deep
Sea Electronics. Legacy versions may appear with the suffix Ltd or PLC.
CODESYS libraries are self-documenting within the library manager. To browse available functions,
function blocks, and type definitions, browse the tree as shown below.
Click the
library the help
information
appears in the
pane below…
Using Library Help we can see the input/output requirements of functions and function blocks and
note if any have default (initial) values. In the following example, Priority and Timeout inputs can be
omitted, the values used by the function block is indicated in the Initial column. All other inputs are
required. Outputs are always optional. Do not map them if you don’t need them in your application.
Example:
Browse the tree
Select the
to locate the item
Documentatio
to learn about…
n tab
NOTE: If using CAN to receive messages with 29-bit headers, set Extended Mode to
TRUE. A port cannot be used receive messages with both 11 bit headers and 29 bit headers at
the same time.
3.3.1 INITIALISE
NOTE: DSEMSeries devices are fitted with either 1,2,3, or 4 CAN ports depending upon
product type.
NOTE: An individual port is initiailsed for reception of EITHER 11-bit headers (CAN2.0A)
or 29-bit headers (CAN2.0B).
Before use, the CAN port must be initialised. This is usually one off operation, usually executed at the
beginning of the application execution but is also required after a deinitialisation of the port.
Example:
FALSE: 11-bit headers (CAN2.0A)
TRUE: 29-bit headers (CAN2.0B)
3.3.2 DE-INITIALISE
NOTE: After calling the CANDeinit function the port cannot be used by DSE_CAN
functions. Transmit and Receive functions report NO_DRIVER when calling them if set to use a
port that is not initialised. Receivers must then be ‘destroyed’ by calling them with
RxID:=16#FFFFFFFF before the port is reinitialised and the receivers recreated by calling them
again as usual.
Where it is required to de initialise the CAN port, for example to change baud rate,
First delete any receivers in use on this port in the application, for example:
NOTE: Ensure CAN port is initialised with DSE_CAN.CANInit before use. Attempting to
use an uninitialized port results in NO_DRIVER error being reported.
Functions for CAN Raw are found in the applicable library tree:
Click the
library the help
information
appears in the
pane below…
Click +
alongside
Raw
CAN Raw provides a medium level interface to the CAN hardware and allows CAN messages to be
sent and received. The name Raw is used as there are no restrictions governing the message ID
and/or message data bytes (sometimes called payload).
CAN 2.0A (11-bit message header) and CAN 2.0B (29-bit message header) are supported.
At the lowest level, CAN Raw functions are used to send messages between devices. For example,
sending messages from DSEM64x device to a DSEM8xx device to allow the display of values
measured by DSEM64x. Conversely, DSEM8xx may send messages to M64x as control messages
indicating button presses, user touchscreen commands, and other control information.
Additionally, CAN Raw functions are used to provide support for higher level CAN protocols such as
S.A.E. J1939, used extensively in off-highway diesel engines and other industrial machinery in
addition to transducers, and expansion devices including remote keypads and displays.
J1939 functions found within DSE CAN Functions Library also make use of the CAN Raw functions.
For further details of J1939 functions, see section entitled CAN J1939 elsewhere in this document.
NOTE: It is recommended that each message to be received has a function block instance
dedicated to it.
NOTE: Each function block receiver has its own incoming message buffer. This allows
multiple function blocks to receive the same message if required.
NOTE: Once a receiver has been instantiated, it continues to buffer messages with
matching ID. To handle the buffer, call the receiver function regularly. Failure to do so may
cause buffer overflow should the buffer fill with unhandled messages. Call a receiver with ID
16#FFFFFFFF to destroy the receiver if no longer required.
DSE CAN Functions Library includes function blocks to read CAN messages.
A summary is given below, with examples in the following subsections.
Advanced.
Used where multiple messages of the same ID are
received between function calls, and it is necessary
to receive them all, and not just the latest one.
During the task cycle, we must analyse the buffer
and retrieve messages until no more remain, before
moving to the next task cycle.
CANReceiveMask
NOTE: Care must be taken to ensure that
excessive numbers of messages are not
received. Ensure the mask is not ‘too loose’.
Advanced.
An AND mask is provided to mask bits within the
message ID. This is used (for example) in J1939 to
receive all messages of a specified PGN while
ignoring message priority, or sender node ID.
Bits in input Mask are applied to the input RxID when
looking for an ID match with the incoming messages.
3.4.1.1 CANRECEIVE
3.4.1.2 CANRECEIVEMASK
Example receiving a message with 29-bit ID. The mask is used to mask the last byte of the ID so that
any message with ID matching the rest of the ID is received, with the last byte ignored.
3.4.1.3 CANRECEIVESINGLE
NOTE: Care must be taken not to block program operation if the transmission frequency
of the received message is excessive. A simple method is to employ a timer as shown in
example 2.
If a new task starts before the last one completes, an Exception Error occurs, application
execution ceases, device LED (where fitted) shows Static RED, and the device event log
registers Processor Overload.
Example 1: Showing minimal usage that will cause blocking if the message is placed on the bus by
the transmitting device at too high a frequency.
Example 2: Showing the use of a timer to ensure the receiver does not block the continuation of
program execution for an excessive time.
3.4.2.1 CANTRANSMIT
NOTE: Consider the time between function calls (usually the task cycle time). This implies
both the minimum time, and resolution of the timing, between messages from the same
function block.
NOTE: A message sent over CAN is always Acknowledged by another CAN node (any
CAN node can Acknowledge when it sees a message on the bus). Should an Acknowledge not
be received by a sending node, this is counted as a Transmission Failure.
DSE_CAN.CANDiagnosis function is used to check the BUSSTATE to determine such failures.
For further details, see section entitled Helper Functions | CANDiagnosis elsewhere in this
manual.
Allows CAN messages to be sent with a parameter Frequency to prevent the message being sent
more often than specified. Typical usage scenarios are:
1. Call the function block once per task cycle. Set Frequency to ensure messages are sent no
more often than (example) once every 100 ms.
2. Call the function block when required. For example, upon change of a value. Set Frequency
to 0 to ensure the message sent every time the function block is called. Set Frequency to
value to prevent messages being sent too often.
3. Using a combination philosophy, monitor a variable. If it changes, call the function block with
Frequency set to 0. The message is sent immediately. If the variable does not change, call
the function block with Frequency set to 1 s. The message is now sent upon change and
every second if there is no change.
Upon the call to the CANTransmit block, the time is checked. If the elapsed time since the last call is
less than Frequency, the message is not sent and NewMessage is set to FALSE. If the elapsed time
is greater than, or equal to, Frequency, the message is sent, and NewMessage is set to TRUE.
NewMessage allows us to check if the message was sent during this cycle. For example, we can use
this to implement counters, incrementing each time the message is sent and unchanging if the call did
not result in message being sent as the elapsed time did not require it.
Individual programmers have their own requirements for what should occur given a failure of either
the complete CAN system, or failure of a specific incoming message.
Typically, a timer is used (TON) that is reset upon reception of one or more messages. Multiple timers
are used to provide detection of multiple failures.
Example:
NOTE: J1939 functions are available in DSE CAN Functions Library V1.6 onwards.
While CAN Raw functions are available to be used with J1939, use with this higher level protocol is
aided by the provision of function blocks specifically related to it.
Functions for CAN J1939 are found in the applicable library tree:
Click the
library the help
information
appears in the
pane below… Click +
alongside
J1939
DSE CAN Functions Library includes function blocks to read J1939 messages.
A summary is given below, with examples in the following subsections.
3.5.1.1 J1939_RECEIVE
NOTE: J1939_Receive obtains the data in the last message matching the input
requirements. If you wish to receive all matching messages seen on the bus since the last call
to the function block, use CAN Raw function DSE_CAN.CANReceiveSingle instead.
NOTE: If you don’t know the values required for Priority, DataPage, PGN, and
SourceAddress you can determine these from the 29-bit ID of the message, or use the CAN
RAW function DSE_CAN.CANReceive instead.
Example showing how to receive PropB_21 (PGN 16#FF21) with Priority 6 from SourceAddress
16#03.
This example uses T#5s for Timeout. In practice we should set this value to at least 2.5 times the
transmission period. (eg if the message is transmitted by the sender every 50 ms, use Timeout of at
least 125 ms). Datapage is often 0, however check this against the 29-bit message ID or consult the
manufacturer of the equipment transmitting the message.
3.5.1.2 READ_XXXX
NOTE: Common J1939 PGNs are provided, readymade, for your convenience. If a
particular PGN is not available, or additionally functionality is required, use
DSE_CAN.CANReceive to receive the data and apply the scaling and offset within your own
custom function. This provides full flexibility for the full range of J1939 PGNs.
For commonly required J1939 messages, a collection of readers is provided. Browse the folder
structure in the library manager to see the functions available in the latest version of the library.
Example: Showing how to read typical parameters from a CAN J1939 engine.
Advanced
A hidden array is available, containing the raw contents of the CAN message. This is useful if you
want to retransmit the raw data, perform other calculations on the raw data, for diagnostic functions,
and more.
Example:
3.5.1.3 J1939_DM1_DM2
NOTE: For J1939 ‘Multipart’ messages, this function block supports Broadcast Announce
Messages (BAM).
NOTE: The use of text lists is not supported by DSEM835. When using with M835, inputs
SPNList, FMIList and bGetStrings are ignored and conversion to strings is not available.
NOTE: For suitable text lists to pass as inputs to SPNList and FMIList, see DSE_UTILS
library.
Used to listen for and receive DM1 or DM2 messages from a specified node address. Where both
DM1 and DM2 reception is required, two function blocks must be used. Input PGN specifies which
messages are to be received.
Basic example using the default settings of the function block. This is the common way to use the
function block, where the remaining inputs take on the defaults values as indicated in the table below.
3.5.2.1 J1939_TRANSMIT
NOTE: Consider the time between function calls (usually the task cycle time). This implies
both the minimum time, and resolution of the timing, between messages from the same
function block.
NOTE: A message sent over CAN is always Acknowledged by another CAN node (any
CAN node can Acknowledge when it sees a message on the bus). Should an Acknowledge not
be received by a sending node, this is counted as a Transmission Failure.
DSE_CAN.CANDiagnosis function is used to check the BUSSTATE to determine such failures.
For further details, see section entitled Helper Functions | CANDiagnosis elsewhere in this
manual.
Allows CAN messages to be sent with a parameter Frequency to prevent the message being sent
more often than specified. Typical usage scenarios are:
1. Call the function block once per task cycle. Set Frequency to ensure messages are sent no
more often than (example) once every 100 ms.
2. Call the function block when required. For example, upon change of a value. Set Frequency
to 0 to ensure the message sent every time the function block is called. Set Frequency to
value to prevent messages being sent too often.
3. Using a combination philosophy, monitor a variable. If it changes, call the function block with
Frequency set to 0. The message is sent immediately. If the variable does not change, call
the function block with Frequency set to 1 s. The message is now sent upon change and
every second if there is no change.
Upon the call to the J1939_Transmit block, the time is checked. If the elapsed time since the last call
is less than Frequency, the message is not sent and NewMessage is set to FALSE. If the elapsed
time is greater than, or equal to, Frequency, the message is sent, and NewMessage is set to TRUE.
NewMessage allows us to check if the message was sent during this cycle. For example, we can use
this to implement counters, incrementing each time the message is sent and unchanging if the call did
not result in message being sent as the elapsed time did not require it.
3.5.2.2 J1939_REQUEST
NOTE: As a request message header to a specific node is the same, regardless of what
PGN is being requested, only one request message can be sent to that node per task cycle. If
multiple requests are made inadvertently, only the last one is sent.
Builds a request message for the specified PGN. You must also provide a listener to receive the
requested message.
Example: Showing sending a request every 60 seconds for node 00 (typically the engine ECU) to
transmit HOURS PGN (containing Running Hours of the engine).
Individual programmers will have their own requirements for what should occur given a failure of
either the complete CAN system, or failure of a specific incoming message.
Consider failure of the DD (Dash Display) message. This is carrying instrumentation data for the dash,
including Fuel Level. If this message is not seen on the bus, it could be considered as a ‘minor’
failure. The instrumentation value should be changed on the display, to alert the user that it is not
current data (hide the value or change it to ####). However, we can allow the engine to continue
running.
DSERead_xxxx function blocks include the Timeout input and Valid output to assist with this, seen in
use in the example in the section entitled Receiving Messages | J1939_Receive and Receiving
Messages | Read_xxxx elsewhere in this document.
Depending upon requirements we can use OR to consider the failure of one or more messages or
handle them all individually. This is the decision of the programmer and ultimately the specifier of the
finished application.
In addition to Transmission and Reception functions, DSE CAN Functions Library provides a
collection of helper functions to assist with common requirements within a J1939 ECU.
3.5.4.1 SLOT
NOTE: Commonly used SLOTs are included within DSE_CAN. Where other conversions
are required, you can add a custom UnitConversion object to your project and insert your own
conversions and additional SLOTs for use within your project.
Conversion from J1939 data to/from actual instrumentation values is specified by J1939 SLOT
entries.
SLOT is an acronym from Scaling, Limits, Offset, Transfer and describes how to perform the data
conversion.
DSE CAN Functions Library contains a CODESYS Conversion object for the most used SLOTs. While
they are used internally by the Read_xxxx function blocks, they are available for programmers to use
in their own applications.
J1939_SLOT
within the
library help.
3.5.4.2 J1939_DTCSCROLLER
J1939 DTC Scroller is used in conjunction with a previously acquired list of DTCs (Diagnostic Trouble
Codes) to provide a method of automatically or manually scrolling through the list of DTCs to allow
one of them to be shown on the device display.
A typical use of this is to scroll through active DTCs every two seconds, displaying only one at a time.
The user can be (optionally) provided with a method to pause this automatic scrolling and (again
optionally) cycle manually through the available DTCs. This is particularly useful for applications
where the visualisation area available for DTCs is limited, or to provide a method of sending DTCs
one at a time to another device for display.
This function is designed to be used in conjunction with the DTCList output returned from the
J1939_DM1_DM2 function block.
Example 1 showing DM1 reception and the use of the DTCScroller utilising the DM1 DTCList.
Example 2, showing DM1 reception and the use of the DTCScroller utilising the DM1 DTCList. M840
buttons UP and DOWN are used to manually scroll the active DTC list.
3.5.4.4 J1939_BUILDTSC1
NOTE: Only call BuildTSC1 when necessary. Each time it’s called, the message counter is
incremented so must only be called after a previous transmit. The example below shows how
to achieve this, using the .NewMessage output from the transmitter function.
Builds the TSC1 (Torque and Speed Control) message data necessary to send to an ECU. This
includes the message counter and checksum.
Example1: Showing how to send TSC1 message every 10 ms within a faster task. Ensure the task
containing this is set to 10 ms or faster. This may require you to create a high priority dedicated task
for this, not slowed or affected by the main (slower) task handling the visualisation and non-time-
critical functions. See Example2 below for how to do this in a dedicated task.
Example2: Showing how to send TSC1 message every 10 ms within a small task. This sends the
TSC1 message every cycle so the task cycle time must be set to match the TSC1 transmission rate.
The advantage with this method is that this task is used exclusively for the TSC1 message so has a
more ‘regular’ cycle time, not affected by other code.
3.6 CANDIAGNOSIS
3.6.1 BUSSTATE
BusState comes from the CL2 (CAN Low Level) library and differs slightly between controllers.
BusState Description
UNKNOWN TransmitCounter increasing upon messages being sent means the CAN network is OK.
Sent messages are not being acknowledged. Ensure the receiver is correctly connected
and configured.
Upon correction of the fault, TransmitErrorCounter decrements with each sent message
that is correctly acknowledged.
BUSOFF Bus is disconnected from the network. Check connections, cable, termination etc.
3.6.1.2 DSEM840
BusState Description
ERR_FREE CAN network is OK
ACTIVE CAN network is operating; however, errors are/were present. If the fault has been
corrected, the state will change when enough messages are received to bring down the
error count.
BUSOFF Bus is disconnected from the network. Check connections, cable, termination etc.
BusState Description
ACTIVE CAN network is OK
WARNING Sent messages are not being acknowledged. Ensure the receiver is correctly connected
and configured.
Upon correction of the fault, TransmitErrorCounter decrements with each sent message
that is correctly acknowledged.
BUSOFF Bus is disconnected from the network. Check connections, cable, termination etc.
4 LIBRARY APPLICATIONS
4.1 DATA TRANSMISSION
NOTE: When transmitting data between DSE MSeries devices, consider using functions
within DSE_UTILS library. Examples include CANTransmit_REAL and CANReceive_REAL
which transmit the REAL values as IEE754 format with no loss of precision.
A CAN message contains 8 bytes of data. To transmit information between devices the programmers
of the device must specify the data contents of each message. This allows them both to convert the
data correctly.
J1939 is one such specification that defines the conversion method of thousands of data entries and
provides Proprietary areas allowing programmers to define their own data structure within those
areas.
4.1.1 J1939
J1939 is useful to allow us to use this data specification for our own needs.
Example 1: DSEM8xx could be programmed to listen for CI (Cab Illumination) messages and use
the value to adjust the display backlight.
Example 2: DSEM64x could be programmed to send its measured battery voltage within a VEP1
(Vehicle Electrical Power) message for reception and display by a DSEM8xx display.
With CAN Raw, the programmers must define all data themselves.
While this manual does not describe the data structure of CAN messages, the following examples
show some methods than can be used to transmit non integer data.
The simplest way to transmit REAL (floating point) numbers over can is to decide upon the resolution
of the data to be sent.
By choosing larger multipliers we can increase resolution. However, this increases the magnitude of
the value so we may have to convert the value into different integer types.
4.1.3.1 ADVANCED
Experienced programmers will know that REAL variables are 32 bits, and LREAL are 64 bits. As a
CAN message holds 64 bits of data, we can UNION REAL and DWORD and transmit two of these in
one CAN message, or UNION LREAL and LWORD and transmit one of these in a CAN message.
Use another UNION in the receiver to convert back. This method is ‘lossless’.
4.1.4 BOOL
Each BYTE in the CAN message holds 8 bits. This can hold 8 BOOL values meaning one CAN
message holds up to 64 BOOL variables (!).
Example:
4.1.5 STRING
STRING types are not suitable for sending over CAN. There are two main options.
1. (Recommended): Decide upon a fixed STRING list. Instead of transmitting a string over
CAN, transmit the string number. This will consume only one or two bytes in a single CAN
message. The receiving device uses the received value to know what string to display.
2. (Not Recommended): STRING type. A CODESYS STRING is ASCII (values 0 to 255). Each
character is one BYTE. Copy the characters into the CAN message BYTEs. A CAN message
carries 8 BYTES. Multiple messages are required if the word (STRING) is longer than 8
characters.
3. (Not Recommended): WSTRING type. A CODESYS STRING is UNICODE (values 0 to
65535). Each character is two BYTEs. Copy the characters into the CAN message BYTEs. A
CAN message carries 8 BYTES. Multiple messages are required if the word (WSTRING) is
longer than 4 characters.
Example1, the following message contains four 16 bit numbers, they are displayed below in
hexadecimal for convenience.
Example2, the following message contains two 32 bit numbers, they are displayed below in
hexadecimal for convenience.
Value 1 Value 2
0x6C211BA5 0x2E35A635
Converting the Bytes to the actual Values is performed in one of several ways, detailed below. Which
method you choose is down to personal preference and listed overleaf in order of ‘ease of
programming’.
4.2.1 DSE_UTILS
DSE_UTILS compiled library provides several functions for data conversion. These include, but are
not limited to BYTES_TO_WORD, BYTES_TO_LWORD, WORD_TO_BYTES, LWORD_TO_BYTES.
Example, the following message contains four 16 bit numbers, they are displayed below in
hexadecimal for convenience.
The 4th Value, in Bytes 5 and 6 is converted using Structured Text and placed into a WORD as
follows.
The 4th Value, in Bytes 5 and 6 is converted by shifting the Byte 6 into the Most Significant Byte of a
WORD and then putting Byte 5 into the Least Significant Byte of the same WORD.
myWord:=SHL(Byte6,8) + Byte5;
5 TROUBLESHOOTING
The below are suggestions answering frequently asked questions about the device.
Symptom Suggestion
Function Blocks return This means that the CAN port has not been initialised using
NO_DRIVER error DSE_CAN.CANinit.
Symptom Suggestion
DM2, HOURS or ATIS These messages are usually (not always) sent On Request.
messages are not being You will need to setup a request message to request them.
received. It is recommended to request them only when necessary, for
example when opening a Visualisation page that displays them.
DM2 requests must not be sent too often as the DM2 message
reply is likely to be a multipart message, taking up bus
bandwidth.
I need to send fast CAN • Split the task into smaller tasks.
messages, every 10 ms, but a • If possible, keep CAN transmission to a separate, faster
fast task cycle is not possible task with higher priority than the other tasks.
due to the amount of code in the • Set the CAN task to priority 17, and your other tasks
task. priority 18 or lower. (Higher number=lower priority). This
keeps the internal CAN receiver task (fixed at priority
16) higher priority than your other tasks.