Just tryng to send correct result via RS232.
In the Flowcode simulator results are correct from:
Results on both hardware and Proteus show the same unexpected results:
Was expecting 62 not 193
At this stage, not putting it down to a bug.
It's probably me not allowing for correct typecasting?
Any idea how to send correct byte value via RS232 please?
Even though using a long for the calculations, expected results will be 0 to 100
So using bytes to save space.
Martin
Sending correct results via RS232 [Resolved]
Moderator: Benj
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Sending correct results via RS232 [Resolved]
- Attachments
-
- Long and Byte_v7.fcfx
- (8.04 KiB) Downloaded 247 times
Martin
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
Re: Sending correct results via RS232
Hi Martin,
Could you try this for the second calc icon ...
Leigh
Could you try this for the second calc icon ...
Code: Select all
.Results = .HiByte
.Results = .Results << 8
.Results = .Results + .LoByte
-
- Matrix Staff
- Posts: 9521
- Joined: Sat May 05, 2007 2:27 pm
- Location: Northamptonshire, UK
- Has thanked: 2585 times
- Been thanked: 3815 times
Re: Sending correct results via RS232
Hi Leigh,
Thank you.
You are spot on as the results are now as expected.
Just wondering if you know of any resources that show how to change the calculations in the way you did?
Trying to look on the web for such information.
Thank you.
You are spot on as the results are now as expected.

Just wondering if you know of any resources that show how to change the calculations in the way you did?
Trying to look on the web for such information.
Martin
- LeighM
- Matrix Staff
- Posts: 2178
- Joined: Tue Jan 17, 2012 10:07 am
- Has thanked: 481 times
- Been thanked: 699 times
Re: Sending correct results via RS232
Hi Martin,
"integer promotion in c" is what you need to look for.
It's the way that the compiler creates temporary variables for such as " + (.HiByte << 8 ) " that causes these issues.
On 8bit/16bit embedded devices the "integer promotion" promotes to 16 bit, not 32 bit as you might expect.
The right hand side does not seem to know what's on the left hand side
Leigh
"integer promotion in c" is what you need to look for.
It's the way that the compiler creates temporary variables for such as " + (.HiByte << 8 ) " that causes these issues.
On 8bit/16bit embedded devices the "integer promotion" promotes to 16 bit, not 32 bit as you might expect.
The right hand side does not seem to know what's on the left hand side

Leigh