开发者

Ruby SerialPorts

开发者 https://www.devze.com 2022-12-24 17:21 出处:网络
I\'m using the ruby serial port gem. After I open up the port I send the data I want like this. sp.write [200.chr, 30.chr, 7.chr, 5.chr, 1.chr, 2.chr, 0.chr, 245.chr].to_s

I'm using the ruby serial port gem. After I open up the port I send the data I want like this.

sp.write [200.chr, 30.chr, 7.chr, 5.chr, 1.chr, 2.chr, 0.chr, 245.chr].to_s

It doesn't work,开发者_开发百科 but if I put it in a loop of around 200 times:

200.times do
  sp.write [200.chr, 30.chr, 7.chr, 5.chr, 1.chr, 2.chr, 0.chr, 245.chr].to_s
end

It works. Any ideas on why this is happening?


It can be related to some kind of buffer that only gets flushed (ie: sends data) when:

  1. You're explicitly sending a CRLF at the end of your string
  2. It (the buffer) is full

Just for testing, would it be wrong for you to try to add \r\n at the end of the string?

0

精彩评论

暂无评论...
验证码 换一张
取 消