app/models/extface/driver/eltrade_tm_u220.rb in extface-0.4.8 vs app/models/extface/driver/eltrade_tm_u220.rb in extface-0.4.9
- old
+ new
@@ -9,10 +9,11 @@
NAME = 'Eltrade TM-U220 (Serial)'.freeze
RESPONSE_TIMEOUT = 3 #seconds
INVALID_FRAME_RETRIES = 6 #count
BUSY_MAX_WAIT_CYCLES = 60 #count
+ BAD_SEQ_MAX_COUNT = 3
FLAG_TRUE = "\xff\xff"
FLAG_FALSE = "\x00\x00"
has_serial_config
@@ -258,15 +259,25 @@
end
return result
end
def frecv(timeout) # return RespFrame or nil
- if frame_bytes = pull(timeout)
- return Frame.new(frame_bytes.b)
- else
- errors.add :base, "No data received from device"
- return nil
+ rframe = nil
+ BAD_SEQ_MAX_COUNT.times do
+ if frame_bytes = pull(timeout)
+ rframe = Frame.new(frame_bytes.b)
+ if rframe.seq.ord == sequence_number(false) #accept only current sequence number as reply
+ break
+ else
+ errors.add :base, "Sequence mismatch"
+ rframe = nil #invalidate mismatch sequence frame for the last retry
+ end
+ else
+ errors.add :base, "No data received from device"
+ break
+ end
end
+ return rframe
end
def pbcd(byte)
((byte / 10) << 4) | (byte % 10)
end
\ No newline at end of file