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 signal collision
#11
Dear admin,

I am running the code in the site, and I want to add 2 features....could you tell me how I do these?

1. Is there a way to execute port:write(':RR\r\n') every 60 sec even if port:read(17) does not return anything? As you said before, port:read(17) is blocking the script. If there's no response from the slave, the script is not going to be executed anymore  Sad

2. I want to alart the system admin if there's no response from the slave(port:read(17)) for 5 min....can I do that in this script?

Code:
if not server then
  require('socket')
  server = socket.udp()
  server:setsockname('127.0.0.1', 5485)
  server:settimeout(60)
end

if not port then
  require('serial')
  port = serial.open('/dev/RS485-1', {
    baudrate = 19200,
    databits = 8,
    stopbits = 1,
    parity = 'none',
    duplex = 'half'
  })
end

data = server:receive()
if data then
  port:write(data)
  os.sleep(0.5)
end

port:flush()
port:write(':RR\r\n')
data, err = port:read(17, 1) -- read 17 bytes for up to 1 second
if data and #data == 17 then
  -- parse data response here
end
Reply


Messages In This Thread
RS485 signal collision - by Hadeel - 02.12.2022, 15:17
RE: RS485 signal collision - by Daniel - 02.12.2022, 15:33
RE: RS485 signal collision - by Hadeel - 02.12.2022, 15:54
RE: RS485 signal collision - by Daniel - 02.12.2022, 15:56
RE: RS485 signal collision - by Hadeel - 02.12.2022, 16:20
RE: RS485 signal collision - by Hadeel - 03.12.2022, 10:57
RE: RS485 signal collision - by admin - 05.12.2022, 07:51
RE: RS485 signal collision - by Hadeel - 05.12.2022, 18:58
RE: RS485 signal collision - by admin - 06.12.2022, 07:49
RE: RS485 signal collision - by Hadeel - 07.12.2022, 15:03
RE: RS485 signal collision - by Hadeel - 23.03.2023, 02:31
RE: RS485 signal collision - by admin - 23.03.2023, 06:00
RE: RS485 signal collision - by Hadeel - 23.03.2023, 07:48
RE: RS485 signal collision - by admin - 23.03.2023, 08:41
RE: RS485 signal collision - by Hadeel - 28.03.2023, 08:35
RE: RS485 signal collision - by admin - 30.03.2023, 05:42
RE: RS485 signal collision - by Hadeel - 30.03.2023, 07:59

Forum Jump: