Skip to content

Instantly share code, notes, and snippets.

@nmanzi
Created September 6, 2011 11:41
Show Gist options
  • Save nmanzi/1197336 to your computer and use it in GitHub Desktop.
Save nmanzi/1197336 to your computer and use it in GitHub Desktop.
Save n*bytes worth of serial input directly to file
#!/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