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.

serial library
#1
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
Reply
#2
Can you explain why do you need to use different baudrates? Are you trying to connect several devices to one port? This may cause permanent device damage if several devices are transmitting. On the other hand it's usually OK to connect one TX to several RX inputs.
Reply
#3
(04.01.2018, 08:02)admin Wrote: Can you explain why do you need to use different baudrates? Are you trying to connect several devices to one port? This may cause permanent device damage if several devices are transmitting. On the other hand it's usually OK to connect one TX to several RX inputs.

Yes i was thinking of connecting a few 232 devices to one port, but if this is a bad idea... i think i will keep one device for the rs233 (the one i need 2 way feedback on one device) the others,
if i use an rs232-rs485 converter and put on the rs485port will this be ok?

with the Rs232 port what is the best way to read the incoming data all the time in a library? or am i best to have a resident script and manage the port and incoming data here then parse to library to process etc?

thanks
Reply
#4
You still need a resident script to handle data communication. Library is just a way of having a re-usable code in different scripts.
As for RS-485<>RS-232 adapters keep in mind that RS-485 is only half-duplex so you cannot send and receive data at the same time. If you need full-duplex then the onyl solution is USB<>RS-232 adapter.
Reply
#5
(05.01.2018, 08:24)admin Wrote: You still need a resident script to handle data communication. Library is just a way of having a re-usable code in different scripts.
As for RS-485<>RS-232 adapters keep in mind that RS-485 is only half-duplex so you cannot send and receive data at the same time. If you need full-duplex then the onyl solution is USB<>RS-232 adapter.

ok i have this sorted now, if i use twice serial.open wil this cause any issue?

port = serial.open('/dev/RS232', { baudrate = 9600, parity = 'none', duplex = 'full' })

1 in resident script to recieve data and 1 in library to send data 

many thanks.
Reply
#6
Do you mean that you want to write from event scripts? This is not recommended as several scripts might try to access the port at once. Here's a short example that uses single resident script for port access and internal UDP server to handle data from event scripts:
https://forum.logicmachine.net/showthrea...15#pid2015
Reply


Forum Jump: