Last active
June 13, 2022 00:07
-
-
Save tallakt/edc2faa8c099836479a1bb5e07756e26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Reads the anemometer "Holdpeak HP-866A" from USB port | |
# Time stamp in unix time and windspeed in m/s is output | |
require 'rubyserial' | |
if ARGV.length != 1 | |
$stderr.puts "usage: read_anemometer.rb <tty device>" | |
exit(-1) | |
end | |
serialport = Serial.new ARGV.shift, 9600 | |
buffer = [] | |
loop do | |
buffer = buffer + serialport.read(9999).bytes | |
buffer = buffer.drop_while {|x| x != 0xeb } | |
if buffer.length >= 15 | |
b = buffer[2..15] | |
a, b = b.pack("c*").unpack("S>*")[-2..-1] | |
if a == b | |
puts "% 15.1f % 3.2f" % [Time.now.to_f, (a * 0.01)] | |
end | |
buffer = [] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment