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.

RS485 repetative string
#1
With RS485 , Im trying to control a blind.

Controlling works fine but when the bilnd gives LM the status string, It seems to be returning the same stirng repeatedly.

In the log image that I attached, at 20:35:43 I get a string which tells me that bilnd is at 65% position
and when the bilnd reached at 90% position at 20:35:49, I get the same string again along with the string tells me that blind is at 90% position.

Is there any problem with my script or is it seems to be a specification of the blind itself?

Code:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
if not port then   require('serial')   portserial.open('/dev/RS485-1', {   baudrate = 9600,   databits = 8,   stopbits = 1,   parity = 'even',   duplex = 'half' })   line = '' end function split(str, delim)     -- Eliminate bad cases...     if string.find(str, delim) == nil then         return { str }     end     local result = {}     local pat = "(.-)" .. delim .. "()"     local lastPos     for part, pos in string.gfind(str, pat) do         table.insert(result, part)         lastPos = pos     end     table.insert(result, string.sub(str, lastPos))     return result end function str2hex(str)     raw_len = string.len(str)     i = 1   while i <= raw_len do     current_hexvalue = '0x' .. string.format("%02x", string.byte(str, i))     if value then       value = value .. ', ' .. current_hexvalue     else         value = current_hexvalue     end     i = i + 1   end   return value end res, err = port:read(30, 6) --port:flush() if res then       decoded = str2hex(res)      -- log(decoded)      t = split(decoded, "0x10, 0x02")      --log(t)     for k,v in pairs(t) do       log(v .. 'STATUS RETURNED')     end end

Attached Files Thumbnail(s)
   
Reply
#2
Do you have any other scripts accessing the same port? Only a single script can access the port at any time.
Also the reading part does not seem correct. Usually the data should be read one byte at a time, at least to the point where a message starting point is found. But this all depends on how the protocol is designed. Do you have a protocol description for this device?
Reply
#3
(01.07.2022, 14:50)admin Wrote: Do you have any other scripts accessing the same port? Only a single script can access the port at any time.
Also the reading part does not seem correct. Usually the data should be read one byte at a time, at least to the point where a message starting point is found. But this all depends on how the protocol is designed. Do you have a protocol description for this device?

Hi admin!

Thank you for your help !

I made sure that this is the only script accessing this port...and read the blind specification...

And finally realized that the cause was in my code.... the valiable "value" in str2hex() keep storing all results and this made the message looks repetative. I wrote this in the resident script  Cry

So there is nothing wrong with the blind and its specification Rolleyes

I can fix this now.... thank you so much for your help always ! 

Code:
1234567891011121314
function str2hex(str)     raw_len = string.len(str)     i = 1   while i <= raw_len do     current_hexvalue = '0x' .. string.format("%02x", string.byte(str, i))     if value then     -- this "value" keep storing all results       value = value .. ', ' .. current_hexvalue     else         value = current_hexvalue     end     i = i + 1   end   return value end
Reply


Forum Jump: