Hello
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
/Joakim
class Serial<File
def
initialize(device=“COM1”,modeString=“r+”,baud=“9600”,parity=“n”,data=“8”,stop=‘1’,retryy=“n”)
@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
system(modestr)
super(device,modeString)
end #initialize
end
test1=Serial.new(“COM1:”, “r+”,“14400”)
t1=Thread.new{
loop{
test1.write(“abcdefghijklmnopdqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ”)
sleep(1)
}
}
t2=Thread.new{
loop{
res=test1.read
p res if(res.length>1)
sleep(0.015)
}
}
t1.join
t2.join