0

I'm working on a project where I need to send a value between two pieces of hardware using CoDeSys. The comms system in use is CAN and is only capable of transmitting in Bytes, making the maximum value 255.

I need to send a value higher than 255, I'm capable of splitting this over more than one byte and reconstructing it on the receiving machine to get the original value.

I'm thinking I can divide the REAL value by 255 and if the result is over 1 then deconstruct the value in to one byte holding the remainders and one byte holding the amount of 255's in the whole number.

For example 355 would amount to one byte of 100 and another of 1.

Whilst I can describe this, I'm having a really hard time figuring out how to actually write this in logic.

Can anyone help here?

LBPLC
  • 1,570
  • 3
  • 27
  • 51
  • Your question is really similar to your old question: http://stackoverflow.com/questions/31369151/converting-32-bit-real-to-2x-16-bit-bytes/ . Why are my solutions provided in my last answer not solving your problem? Note: You are using a REAL value and you should always send all 4 bytes in the REAL, it does not matter if the value is above 255. Because all 4 bytes are needed for the accuracy in floating point arithmetic. – Felix Keil Sep 14 '15 at 07:36

1 Answers1

0

This is all handled for you in CoDeSys if I understand you correctly. 1. CAN - Yes it's in byte but you must not be using CANopen you are using the low level FB that ask you to send a CAN frame of an 8 byte array?

If it is your own two custom controllers ( you are programming both of them in CoDeSys) just use netvariables. Netvariables allows you to transfer any type of variable and you can take the variable list from one controller and import it to another controller and all the data will show up. You don't have to do any variable manipulation it's handle under the hood for you. But I don't know the specifics of your system and what you are trying to do.

If you are trying to deconstruct construct variables from one size to another that is easy and I can share that code with you.