serialport won't thread (new to ruby)


S

Secesh

def readSerial
while 1
puts "reading line from TTY\n"
TTY.read_timeout=1
lineTTY = TTY.read.unpack("H*")
lineTTY.each { |l|
if l.sub!(/^0262([0-9A-F]{12})06/i, "")
puts "Got ACK on: #{$1}\n"
#This message is simply an ACK from the PLM of a
message I sent
#to the PLM. because I incorporate error-detection
elsewhere,
#I assume I send good data to the PLM, and only get
ACKs.
#NAKs from the PLM are "15" instead of "06"
redo
elsif l.sub!(/^0250([0-9A-F]{6})([0-9A-F]{6})([0-9A-F]{2})
([0-9A-F]{2})([0-9A-F]{2})/i, "")
#I wish I could condense the repition out of the
above, but doing so makes me loose variables below.
puts "A SD was sent from #{$1} to #{$2}. Flag was:
#{$3}. Commands were: #{$4} #{$5}\n"
redo
elsif l.length > 0
print "unknown: " + l + "\n"
end
}
sleep(1)
end
end

def watchGets
while 1
line=gets.chomp
exit if line=="q"
end
end

______________________________
# Given the above, this works:
readSerial
# But the problem is that rather than just calling that, I want to
thread.
# But the below hangs (I get one line of "Reading line from TTY" --
but only one).
# and while threadTTY hangs, threadGets works fine in the background.
threadGets = Thread.new{watchGets}
threadTTY = Thread.new{readSerial}
threadGets.join
threadTTY.join
# Thanks!
 
Ad

Advertisements

R

Roger Pack

# Given the above, this works:
readSerial
# But the problem is that rather than just calling that, I want to
thread.
# But the below hangs (I get one line of "Reading line from TTY" --
but only one).
# and while threadTTY hangs, threadGets works fine in the background.
threadGets = Thread.new{watchGets}
threadTTY = Thread.new{readSerial}
threadGets.join
threadTTY.join

What is TTY?
Also are you on windows? Which version of ruby?
-r
 

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

Top