Codesys sample program converting word variable into 2 byte variables

Join Date
Feb 2012
Location
UK
Posts
57
Hi,
I am new to codesys programming and need some help converting a word variable into 2 byte variables.
If anyone provides the sample in Codesys syntax format, it would be great.
Thanks for the help.
 
bijt1:=WORD_TO_BYTE(woord);
bijt2:=WORD_TO_BYTE(woord/256);

some other possibilities are www.oscat.de
codesys.com forum

as long as you put codesys in the subject i will find you.
 
Consider an ordinary integer, represented in binary.

Dividing that integer by 2 shifts all the bits to the right by 1 position.
Dividing that integer by 4 shifts all the bits to the right by 2 positions.

And so on. Dividing by 256 shifts all the bits to the right by 8 positions.

So dividing the original value by 256 shifts the value so that the High Byte is now in the position of the Low Byte.

An example:

1234 decimal = 04D2 (hex).

1234 / 256 = 4.8203125. Truncate the remainder.

Result = 04 (hex)
 
ken you are correct i should have used SHR (lazy)
bijt1:=WORD_TO_BYTE(woord);
bijt2:=WORD_TO_BYTE (SHR(woord,8));
this one works exactly.
wordtobyte just takes the lower 8 bits from the word.
shr means shifting the bits 8 times to the right, meaning the low byte is overwritten by the high one.
and wordtobyte does the same as above.

and instru take a piece of paper and make it in bits with 0 and 1
 

Similar Topics

Hello, I am using a Hitachi Micro EHV+ for a small project, and I wanted to have a Web visu, done with Codesys V3.5 SP13 Patch 2. I test the...
Replies
6
Views
267
Hello, I have a requirement to manage the text alignment dynamically. So, for example: 1. English Texts should be displayed from Left in...
Replies
0
Views
86
Hello, I am new to Codesys, and am trying to learn about it for a project we're developing. I've got a couple questions, but first a little...
Replies
1
Views
133
Hi everyone, as this is my first experience with Rockwell Software i would like to know what's the best way to make Enumerations?
Replies
10
Views
488
I am trying to get Codesys to work with a couple of Moxa ioLogik E1200 series DIO devices (E1210 and E1211). I am able to write to the E1211 DOs...
Replies
2
Views
163
Back
Top Bottom