Skip to content

Commit

Permalink
hack: switch out (buggy) ruby serial port gem for python serial port …
Browse files Browse the repository at this point in the history
…proxy
  • Loading branch information
plainlystated committed Feb 26, 2011
1 parent 0c763ad commit d17c248
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
12 changes: 1 addition & 11 deletions lib/xbee/packet.rb
Expand Up @@ -165,17 +165,7 @@ def _parse_digital_samples
end

def _read_packet(serial)
start = Time.now
i = 1
until Time.now - start > 6
if serial.getc == START_IOPACKET
lengthMSB = serial.getc
lengthLSB = serial.getc
length = (lengthLSB + (lengthMSB << 8)) + 1

return Array.new(length) { serial.getc }
end
end
serial.gets.split(" ").map {|byte| byte.to_i}
end
end
end
3 changes: 1 addition & 2 deletions power_hungry.rb
@@ -1,5 +1,4 @@
require 'rubygems'
require 'serialport'

require 'lib/power_hungry/config'
require 'lib/power_hungry/history'
Expand All @@ -9,7 +8,7 @@

class PowerHungry
def initialize
@serial = SerialPort.new(Config.serial_port)
@serial = IO.popen("python serial_proxy.py #{Config.serial_port}")
end

def debug
Expand Down
4 changes: 2 additions & 2 deletions serial_proxy.py
Expand Up @@ -19,12 +19,12 @@ def find_packet(serial):
sys.exit(["Required arg: serial dev (eg /dev/ttyUSB0)"])

serial_dev = sys.argv[1]
print("opening " + serial_dev)
serial = serial.Serial(serial_dev, 9600)
serial.open()

while True:
packet = find_packet(serial)
if packet:
packet_bytes = [hex(ord(byte)) for byte in packet]
packet_bytes = [str(ord(byte)) for byte in packet]
print(string.join(packet_bytes, " "))
sys.stdout.flush()

0 comments on commit d17c248

Please sign in to comment.