|
|

楼主 |
发表于 2013-7-9 00:26:47
|
显示全部楼层
pcDuino的串口 与 Arduino的串口进行通讯的例子。
[pre lang="Ruby" line="1"]#!/usr/bin/ruby
require 'serialport'
sp = SerialPort.new "/dev/ttyS1", 115200
open("/dev/tty", "r+") { |tty|
tty.sync = true
Thread.new {
tty.puts "demo 123456"
ss = ''
while true do
ss = ss + sprintf("%02X ", sp.getc)
#tty.printf("%c", sp.getc)
#ss = sp.read
#puts ss
end
tty.puts "<< recv : #{ss}"
#tty.printf("<< recv : #{ss}")
}
while (l = tty.gets) do
l = l.chomp
puts ">> #{Time.now.strftime('%D %T')}: #{l}"
if l == "exit"
exit
elsif l == "on"
sp.write("m1 on")
elsif l == "off"
sp.write("m1 off")
else
sp.write(l.sub("\n", "\r"))
end
end
}
sp.close [/code]
Arduino 重复发1234567890 的情况 |
|