power supply simulator created (not replying yet)

This commit is contained in:
King Kévin 2015-07-30 09:06:46 +02:00
parent 0758e2e50d
commit 62c3986036
1 changed files with 35 additions and 0 deletions

35
ps_simulator.rb Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env ruby
# encoding: utf-8
# ruby: 1.9
require 'serialport'
require './telegram'
pc_serial = SerialPort.open("/dev/ttyUSB0",{ baud: 57600, databits: 8, parity: SerialPort::ODD, stop_bit: 1, flow_control: SerialPort::NONE})
# ensure serial settings (weird bug)
pc_serial.baud = 57600
pc_serial.parity = SerialPort::ODD
while true
activities = IO.select([pc_serial])
activities[0].each do |activity|
data = activity.readpartial(16+1+5)
line = data.unpack("C*").collect { |b| sprintf("%02X ",b) }.join
if activity==pc_serial then
puts "> "+line
begin
telegram = Telegram.parse(data)
if telegram then
puts "> "+telegram.to_s[2..-1]
else
raise "could not parse message"
end
rescue Exception => e
puts e.to_s
end
else
raise "unknown source"
end
end
end