Sending correct results via RS232 [Resolved]

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
medelec35
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]

Post by medelec35 »

Just tryng to send correct result via RS232.
In the Flowcode simulator results are correct from:
Long and Byte Var.png
(58.23 KiB) Downloaded 2302 times
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
Attachments
Long and Byte_v7.fcfx
(8.04 KiB) Downloaded 247 times
Martin

User avatar
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

Post by LeighM »

Hi Martin,

Could you try this for the second calc icon ...

Code: Select all

.Results = .HiByte
.Results = .Results << 8
.Results = .Results + .LoByte
Leigh

medelec35
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

Post by medelec35 »

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.
Martin

User avatar
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

Post by LeighM »

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 :lol:

Leigh

Post Reply