Logic Machine Forum
2 byte to 1 byte - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: 2 byte to 1 byte (/showthread.php?tid=1045)



2 byte to 1 byte - Frankg - 18.10.2017

Hi

How do i take a 2 byte signal(9.009) and convert it to a 1 byte signal(5.001).
Need to use the 2 byte signal in a formula up against 1 byte signal and can not figure out how to proceed here.  Undecided

thank's for any help! Smile 



RE: 2 byte to 1 byte - Erwin van der Zwart - 18.10.2017

Hi,

That depends on what you want to do, what information do you need from the 2 byte value to the 1 byte value?

Could be something like this:
Code:
twobytevalue = event.getvalue()
onebytevalue = math.floor((twobytevalue / 256) + 0.5)
grp.write('1/1/2', onebytevalue)
Or:
Code:
twobytevalue = event.getvalue()
if twobytevalue < 255 then
  onebytevalue = math.floor(twobytevalue + 0.5) -- round airflow to integer
else
  onebytevalue = 255 -- if airflow is higher then 255 then max is reached
end
grp.write('1/1/2', onebytevalue)
BR,

Erwin