serial port connection

S

Sangeeta Huddar

Hi ,
currently i m using ruby telnet for connecting to HW board but
now i want to switch to serial port
for the same i have downloaded the
http://rubyforge.org/frs/?group_id=61&release_id=308 and put the
serial.so at /ruby/lib/ruby/1.8/i386-mswin32

now i want to use this and access the board .i tried d simple ways i
could think but nothing worked :(
can anyone help me with simple program to use serial.so
or is there any other way i can connect to board via serial port


thanks in advance,
-sangeeta
 
B

B. Randy

Hello,
Very intersting ... I'll try it late.
Well, I suppose that you are under Win$ and you must notice that the
SERIAL link is a "funny" game.

1 - Use a modem-cable, to link the two RS232 ports of your PC or an
other RS232 on a other PC.

2 - Test with classics tools the communication. On Win$, there is "Hyper
Terminal", any other kind of tool is good. On Linux, "minicom" for
example. Configure the two tools : same speed, no hardware handshaking,
no software handshaking, same parity, same stop-bits.
After, when you type some words in one window, you must see the text in
the other. At this point, your link is good.

3 - Replace one of the tools (Hyper Terminal, minicom) by your Ruby
code.
Try to send some text. I'll take the example from :
http://ruby-serialport.rubyforge.org/ and make some modifications.

require 'rubygems'
require 'serialport'
sp = SerialPort.new "COM1", 9600, 1, NONE
sp.write "Hello world !"
puts sp.read

You should see the text on the new window. At this point, the soft is
good.

You can play with a modem too.

4 - For you HW. I don't know the kind of your HW, so I'll be "large".
Don't forget to verify the protocol of your HW board. Some HW wants some
special escape caracters before and after the message, or special
sequence for initiate the link, or want work only in dialog mode. In
this later case when you send something you must read something, if you
don't make this the HW will block.

Sangeeta Huddar wrote:
[...]
now i want to use this and access the board .i tried d simple ways i
could think but nothing worked :( [...]
can anyone help me with simple program to use serial.so
or is there any other way i can connect to board via serial port
thanks in advance,
-sangeeta
 
B

B. Randy

Oops ! Sorry there is a mistake.

1 - Use a NULL-MODEM cable , to link the two RS232 ports of your PC or
an
other RS232 on a other PC.
 
S

Stalin Thangaraj

B. Randy said:
Hello,
Very intersting ... I'll try it late.
Well, I suppose that you are under Win$ and you must notice that the
SERIAL link is a "funny" game.

1 - Use a modem-cable, to link the two RS232 ports of your PC or an
other RS232 on a other PC.

2 - Test with classics tools the communication. On Win$, there is "Hyper
Terminal", any other kind of tool is good. On Linux, "minicom" for
example. Configure the two tools : same speed, no hardware handshaking,
no software handshaking, same parity, same stop-bits.
After, when you type some words in one window, you must see the text in
the other. At this point, your link is good.

3 - Replace one of the tools (Hyper Terminal, minicom) by your Ruby
code.
Try to send some text. I'll take the example from :
http://ruby-serialport.rubyforge.org/ and make some modifications.

require 'rubygems'
require 'serialport'
sp = SerialPort.new "COM1", 9600, 1, NONE
sp.write "Hello world !"
puts sp.read

You should see the text on the new window. At this point, the soft is
good.

You can play with a modem too.

4 - For you HW. I don't know the kind of your HW, so I'll be "large".
Don't forget to verify the protocol of your HW board. Some HW wants some
special escape caracters before and after the message, or special
sequence for initiate the link, or want work only in dialog mode. In
this later case when you send something you must read something, if you
don't make this the HW will block.

Sangeeta Huddar wrote:
[...]
now i want to use this and access the board .i tried d simple ways i
could think but nothing worked :( [...]
can anyone help me with simple program to use serial.so
or is there any other way i can connect to board via serial port
thanks in advance,
-sangeeta

Hello,
I installed the gem and ran the code. Message was written
successfully. But I can't read the written data. It is waiting there.
The device I opened was /dev/ttyS0. Help me to read the data from serial
port.

Thanks,
Stalin .T
 
A

Axel

Hello,

I never used serial-port communication with Ruby, but I collected some
informations on this. (It's likely that I'll need it in the future...)

Maybe, the following is usefull for you:

"
# ...All I had to do was set a seemingly
# arbitrary read_timeout value. With the timeout,
serialport.gets just returns
# whatever was in the input buffer.
"

My collection:


###########################################################################
# 2008-12-08: According to comp.lang.ruby, there is no easy-to-use
library,
# for serial port usage under windows. But: This should work:
# http://grub.ath.cx/win32serial/
# which worked fine on my system (Windows XP sp3, using cygwin
ruby, but I
# think it'll work with the one-click version of Ruby)
# Small, but must be compiled first. Compilation made problems,
according to
# comp.lang.ruby
#
# 2009-06-09: Somebody got library working (comp.lang.ruby,
2008-06):
# Nevertheless, it seems to be working today! All I had to do
was set a seemingly
# arbitrary read_timeout value. With the timeout,
serialport.gets just returns
# whatever was in the input buffer.
#
# Other thread (2008-06):
# ...in my experience Ruby serialport library for Windows is in
most cases
# not usable. I suppose the problem is Ruby's implementation of
threads
# (green threads) under Windows.
#
# For serial communication under windows I now use a
RS-232/422/485
# connections over Ethernet (i.e. Ethernet to serial) - so from
windows
# (Ruby) perspective I use TCP/IP communication which works fine.

Regards,
Axel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,150
Members
46,697
Latest member
AugustNabo

Latest Threads

Top