From: Secesh Date: 2010-06-14T11:20:13+09:00 Subject: serialport won't thread (new to ruby) 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!