This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

2 byte to 1 byte
#1
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 
Reply
#2
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
Reply


Forum Jump: