Created
September 6, 2011 11:41
-
-
Save nmanzi/1197336 to your computer and use it in GitHub Desktop.
Save n*bytes worth of serial input directly to file
This file contains 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/ruby -wKU | |
require "rubygems" | |
require "serialport" | |
device = ARGV[0] ? ARGV[0] : nil | |
input_size = ARGV[1] ? ARGV[1] : nil | |
output_file = ARGV[2] ? ARGV[2] : nil | |
if !input_size || !output_file || !device | |
Kernel.exit | |
end | |
port_str = device | |
baud_rate = 9600 | |
data_bits = 8 | |
stop_bits = 1 | |
parity = SerialPort::NONE | |
sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity) | |
File.open(output_file, "w") { |file| | |
while file.pos < input_size.to_i do | |
file.putc(sp.getc) | |
end | |
} | |
sp.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment