03.01.2018, 21:12
I need to open an rs232 port in 2 different baud rates at different times, how do i achieve this while still receiving data from the rs232 port once the port is open again.
where is the best location to handle the opening/closing of the port and where is the best location to receive the read data?
if i put some looping code in a library
if port do
port:read(1,1)
end
other functions are not able to run while the loop is running what is the right method to receive data into a library, i need to keep the port open/recieved data coming in as i don't know when some string might be sent from the rs232 end point.
i have looked at the serial library doc http://openrb.com/docs/serial.htm
and can get the code below to work and have connectivity to rs232 device
any help is much appreciated.
if not port then
require('serial')
port = serial.open('/dev/RS232', { baudrate = 9600, parity = 'none', duplex = 'full' })
port:flush()
end
-- port ready
if port then
char = port:read(1, 1)
if char then
alert(char)
end
end
where is the best location to handle the opening/closing of the port and where is the best location to receive the read data?
if i put some looping code in a library
if port do
port:read(1,1)
end
other functions are not able to run while the loop is running what is the right method to receive data into a library, i need to keep the port open/recieved data coming in as i don't know when some string might be sent from the rs232 end point.
i have looked at the serial library doc http://openrb.com/docs/serial.htm
and can get the code below to work and have connectivity to rs232 device
any help is much appreciated.
if not port then
require('serial')
port = serial.open('/dev/RS232', { baudrate = 9600, parity = 'none', duplex = 'full' })
port:flush()
end
-- port ready
if port then
char = port:read(1, 1)
if char then
alert(char)
end
end