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.

Read RS232 send to KNX Group adress
#1
Hi.

Is it anyone who knows how to read from RS232 and send forward to a KNX group adress.

i will receive 4 different values that should call for a scene on the KNX side....

0/r, 1/r, 2/r and 3/r, i have seen some script examples but how do i make it send to the KNX group adress

require('serial')
port = serial.open('/dev/RS232', {
  baudrate = 38400,
  databits = 8,
  stopbits = 1,
  parity = 'none',
  duplex = 'full'
})


This must be to open the port, but the rest i don`t know how, i think it must be some "port:read" and  "write to"

Best regards
Reply
#2
Serial docs: https://openrb.com/docs/serial.htm
Reply
#3
Thanks, but how do i transfer received value to KNX group adress ?
Reply
#4
It depend of the application. You may need to convert the data and then write to object as to any other object. The simplest way is to make If received string is X then write to object Y etc.
------------------------------
Ctrl+F5
Reply
#5
See this example: https://forum.logicmachine.net/showthrea...24#pid4224
You just need to add several if's and grp.write calls
Reply
#6
Ok, i will try and reply how it goes

Thanks
Reply
#7
I tried this script.... but something must be wrong in the log it says "* string: port not open"

   
Reply
#8
Try this script (resident, sleep time = 0) as is without changing anything and post what you get in Alerts tab:
Code:
if not port then
  require('serial')
  port = serial.open('/dev/RS232', { baudrate = 9600 })
  port:flush()
  line = ''
end

char = port:read(1, 1)
if char then
  if char == '\r' then
    line = line:trim()
    alert(line)
    line = ''
  else
    line = line .. char
  end
end
Reply
#9
I got nothing in the log ....
Reply
#10
Are you sure that data is being sent to the port? Try this and post what you get in Logs tab.
Code:
if not port then
  require('serial')
  port = serial.open('/dev/RS232', { baudrate = 9600 })
  port:flush()
  line = ''
end

char, err = port:read(1, 60)
log(char, err)
Reply
#11
This came up now...

   
Reply
#12
This should accept strings in X/r format where X is a number between 0 and 3:
Code:
char = port:read(1, 1)
if char then
  if char == 'r' then
    if #line == 2 and line:sub(2, 2) == '/' then
      value = tonumber(line:sub(1, 1))
      
      if value and value >= 0 and value <= 3 then
        grp.write('1/1/1', value)
      end
    end

    alert(line)
    line = ''
  else
    line = line .. char
  end
end
Reply
#13
And before this it should be to open the port ?
Reply
#14
Yes this
Code:
if not port then
  require('serial')
  port = serial.open('/dev/RS232', { baudrate = 9600 })
  port:flush()
  line = ''
end
------------------------------
Ctrl+F5
Reply
#15
Ok, sorry but i get nothing now on the log, i don´t know what is wrong.
Reply
#16
Check alerts not logs. Start logging the object 1/1/1 or which ever you used in the script
------------------------------
Ctrl+F5
Reply
#17
This is how the script looks now..

   
Reply
#18
Anything in the Alerts tab? Add a new line with log(line) after if char then, and post what you get in the Logs tab
Reply
#19
I had some things between will check it on monday.

TY
Reply
#20
Hi, the problem is solved the script is working fine....   Big Grin

Thank you very much for the support

//Anders
Reply


Forum Jump: