Comunication via rs485

Is there any way to comunicate via rs485 with ruby? Any gem or project
already made by someone? I need to do that in m project and id like to
do it with Ruby instead of using a conversor to read rs232.
Thanks a lot.

Subject: Comunication via rs485
Date: Wed 19 Dec 12 05:39:15PM +0900

Quoting iosu bueno ([email protected]):

Is there any way to comunicate via rs485 with ruby? Any gem or project
already made by someone? I need to do that in m project and id like to
do it with Ruby instead of using a conversor to read rs232.

Back in 2009 I needed to talk to a device via rs485. Eventually, due
to the distance to the device, I had to use a gizmo that converted the
conversation to ethernet-based. But while I tested the code I had the
device on my desk, and thus talked native rs485. Well, once my serial
port was properly configured to talk rs485 (in my case I needed to
change the position of a few hardware jumpers on the PCI board) I
talked to the port as I would to any other serial port. before opening
the port I called stty as follows

system(“stty -F /dev/#{@dev} speed #{@speed} -brkint -icrnl -imaxbel
-opost
-onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl
-echoke ignbrk -ixon -ixoff hupcl”

(where @dev was the appropriate ttySxx, and the speed was the expected
comms speed). Then I opened the unit as follows:

@unit=File::open(’/dev/’+@dev,File::RDWR)

and I would use @unit.syswrite and @unit.sysread as normal.

It was the first and last time I had to do with rs485. I was VERY
happy that everything worked, that’s for sure. Now I do not even have
that PCI card anymore, so I cannot give you much more advice.

HTH

Carlo

Google “ruby serial port”

Brian C. wrote in post #1089866:

Google “ruby serial port”

Im already using serialport gem in my project, but as they say in their
page “Ruby/SerialPort is a Ruby library that provides a class for using
RS-232 serial ports” so i dont know if I can use it to comunicate via
rs485 or just rs232

iosu bueno wrote in post #1090230:

Brian C. wrote in post #1089866:

Google “ruby serial port”

Im already using serialport gem in my project, but as they say in their
page “Ruby/SerialPort is a Ruby library that provides a class for using
RS-232 serial ports” so i dont know if I can use it to comunicate via
rs485 or just rs232

Have you googled for the difference between RS232 and RS485? Also, you
haven’t said what hardware you want to use to connect your PC to RS485,
nor what protocol you are going to use, nor what operating system you
are using.

If this is just a long-reach point-to-point asynchronous serial link,
then RS232 and RS485 are basically the same thing but with different
electrical properties. If you are using an RS232-to-RS485 level shifter,
or an RS485 card with a 16550A-compatible UART, then it will appear just
like an RS232 serial port.

However if you are trying to do something cleverer, e.g. talk on an
RS485 shared multipoint bus, you may have more work to do, e.g. turning
the line driver on and off at the right times. This might still be
drivable like an RS232 serial port, e.g. raising and lowering DTR might
turn the transmit driver on and off. You’ll need to read the
documentation for the hardware and OS drivers you’re using.

Brian C. wrote in post #1090294:

iosu bueno wrote in post #1090230:

Brian C. wrote in post #1089866:

Google “ruby serial port”

Im already using serialport gem in my project, but as they say in their
page “Ruby/SerialPort is a Ruby library that provides a class for using
RS-232 serial ports” so i dont know if I can use it to comunicate via
rs485 or just rs232

Have you googled for the difference between RS232 and RS485? Also, you
haven’t said what hardware you want to use to connect your PC to RS485,
nor what protocol you are going to use, nor what operating system you
are using.

If this is just a long-reach point-to-point asynchronous serial link,
then RS232 and RS485 are basically the same thing but with different
electrical properties. If you are using an RS232-to-RS485 level shifter,
or an RS485 card with a 16550A-compatible UART, then it will appear just
like an RS232 serial port.

However if you are trying to do something cleverer, e.g. talk on an
RS485 shared multipoint bus, you may have more work to do, e.g. turning
the line driver on and off at the right times. This might still be
drivable like an RS232 serial port, e.g. raising and lowering DTR might
turn the transmit driver on and off. You’ll need to read the
documentation for the hardware and OS drivers you’re using.

Thanks for your answers. I dont understan the difference 100%, not my
area, I just was asked to investigate if it was “Possible” with Ruby to
do that. In our application we read consumption meters via modbus with a
computer using Ubuntu. We want to add support to more meters that
comunicate using rs485, and it would be cheaper to do it directly
without any conversor or long software developments.

Sometimes bosses ask for strange things :slight_smile: Thanks again for your
answers and please excuse my english.