Forum: Ruby serial port

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7f3f938311545a9e4ae7c1cd8a0a79fd?d=identicon&s=25 Joakim Oman (joakim)
on 2006-06-08 17:00

I have been trying to come up with a simple way of utilizing the COM1
port on my Windows XP Machine. The result is at the end of this entry
(sorry for the linebreaks)

This program requires that the tx and the rx ports on the COM-port are
connected. The program is just talking to itself.

The second thread in the program listed below is the listner and if I
remove the sleep function the whole things goes havoc. What I would like
is if someone could tell me why or even better, come up with a really
nice and functional serial communication class that works with win32

class Serial<File

			@device	=	device
			@baud	=	baud
			@parity	=	parity
			@data	=	data
			@stop	=	stop
			@retryy	=	retryy
			modestr = "mode "+@device+" baud="+@baud+" parity="+@parity+"
data="+@data+" stop="+@stop+" retry="+@retryy
	end #initialize

end"COM1:", "r+","14400"){
		p res if(res.length>1)

37ee5fa90f5eaeef62553629382497f7?d=identicon&s=25 Leslie Viljoen (Guest)
on 2006-06-09 23:55
(Received via mailing list)
On 6/8/06, Joakim Oman <> wrote:
> remove the sleep function the whole things goes havoc. What I would like
>                         @baud   =       baud
> end
> loop{
>                 p res if(res.length>1)
>                 sleep(0.015)
>          }
> }
> t1.join
> t2.join

By havoc I assume you get garbage back?
I'd suggest synchronising the threads and seeing what happens. It may
be a thread safety issue with reading and writing the same "file" at
the same time.

Since you probably won't have that problem when actually communicating
with other devices, your class may already be functional.

7f3f938311545a9e4ae7c1cd8a0a79fd?d=identicon&s=25 Joakim Oman (joakim)
on 2006-06-12 14:10
Yepp, you were absolutely right.

Introducing the mutex class was the solution. Thank you very much.

This topic is locked and can not be replied to.