Hi everyone,
I have been doing a project where I have to send CAN messages from WAGO plc pf200 in BYtes. The signed integer needs to be unpacked into two bytes. so far I have tried Union but that has not worked with me
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi
A SINT is a short (signed) integer. It is already only 1 byte - so you should have no problem casting it to a byte like so: bMyByte := TO_BYTE(sintMyShortInt);
If you have a regular INT you want to put in 2 bytes - there are a lot of ways you can do this. A Union is certainly one of them. You could have a union with 2 memebers: An array of 2 bytes as one member, and an integer value as another member.
Another way would be to look at MEMCPY to put the value into your CAN-message.
.. or create a function to take your input value as input, and giving you 2 individual bytes as output. This could be handy if you need to change the byte-order.
Hi everyone,
I have been doing a project where I have to send CAN messages from WAGO plc pf200 in BYtes. The signed integer needs to be unpacked into two bytes. so far I have tried Union but that has not worked with me
Hi
A SINT is a short (signed) integer. It is already only 1 byte - so you should have no problem casting it to a byte like so: bMyByte := TO_BYTE(sintMyShortInt);
If you have a regular INT you want to put in 2 bytes - there are a lot of ways you can do this. A Union is certainly one of them. You could have a union with 2 memebers: An array of 2 bytes as one member, and an integer value as another member.
Another way would be to look at MEMCPY to put the value into your CAN-message.
.. or create a function to take your input value as input, and giving you 2 individual bytes as output. This could be handy if you need to change the byte-order.
Integer data types:
https://help.codesys.com/webapp/_cds_datatype_integer;product=codesys;version=3.5.17.0
-Bjarne