Page 1 of 1

Sending correct results via RS232 [Resolved]

Posted: Mon Aug 08, 2016 11:42 am
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

Re: Sending correct results via RS232

Posted: Mon Aug 08, 2016 12:04 pm
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

Re: Sending correct results via RS232

Posted: Mon Aug 08, 2016 12:26 pm
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.

Re: Sending correct results via RS232

Posted: Mon Aug 08, 2016 1:49 pm
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