Logic Machine Forum
Read RS232 send to KNX Group adress - 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: Read RS232 send to KNX Group adress (/showthread.php?tid=3131)



Read RS232 send to KNX Group adress - AndersH - 27.01.2021

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


RE: Read RS232 send to KNX Group adress - admin - 27.01.2021

Serial docs: https://openrb.com/docs/serial.htm


RE: Read RS232 send to KNX Group adress - AndersH - 27.01.2021

Thanks, but how do i transfer received value to KNX group adress ?


RE: Read RS232 send to KNX Group adress - Daniel - 27.01.2021

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.


RE: Read RS232 send to KNX Group adress - admin - 27.01.2021

See this example: https://forum.logicmachine.net/showthread.php?tid=746&pid=4224#pid4224
You just need to add several if's and grp.write calls


RE: Read RS232 send to KNX Group adress - AndersH - 27.01.2021

Ok, i will try and reply how it goes

Thanks


RE: Read RS232 send to KNX Group adress - AndersH - 03.02.2021

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

   


RE: Read RS232 send to KNX Group adress - admin - 03.02.2021

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



RE: Read RS232 send to KNX Group adress - AndersH - 03.02.2021

I got nothing in the log ....


RE: Read RS232 send to KNX Group adress - admin - 03.02.2021

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)



RE: Read RS232 send to KNX Group adress - AndersH - 03.02.2021

This came up now...

   


RE: Read RS232 send to KNX Group adress - admin - 03.02.2021

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



RE: Read RS232 send to KNX Group adress - AndersH - 03.02.2021

And before this it should be to open the port ?


RE: Read RS232 send to KNX Group adress - Daniel - 03.02.2021

Yes this
Code:
if not port then
  require('serial')
  port = serial.open('/dev/RS232', { baudrate = 9600 })
  port:flush()
  line = ''
end



RE: Read RS232 send to KNX Group adress - AndersH - 03.02.2021

Ok, sorry but i get nothing now on the log, i don´t know what is wrong.


RE: Read RS232 send to KNX Group adress - Daniel - 03.02.2021

Check alerts not logs. Start logging the object 1/1/1 or which ever you used in the script


RE: Read RS232 send to KNX Group adress - AndersH - 03.02.2021

This is how the script looks now..

   


RE: Read RS232 send to KNX Group adress - admin - 03.02.2021

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


RE: Read RS232 send to KNX Group adress - AndersH - 05.02.2021

I had some things between will check it on monday.

TY


RE: Read RS232 send to KNX Group adress - AndersH - 10.02.2021

Hi, the problem is solved the script is working fine....   Big Grin

Thank you very much for the support

//Anders