Skip to content

Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)"

Somehow, most of the time my Arduino-based EggBot clone outputs one byte of undetermined garbage before saying "Ready". This caused gcode-sender.rb to fail with "invalid byte sequence in UTF-8 (ArgumentError)".

Eventually I found the solution in a post by Wayne Brissette here: https://www.ruby-forum.com/topic/4409620. Basically you need to treat the string as binary instead of utf-8. This small change in the code that waits for the robot to be ready fixed the issue for me:
--- gcode-sender.rb.orig
+++ gcode-sender.rb
@@ -30,7 +30,7 @@
sp.read_timeout = 0 # Necessary for Windows.
while line = sp.gets
print line
- break if line.match(/^Ready/)
+ break if line.force_encoding("BINARY").match(/^.?Ready/)
end
File.foreach(filename) do |line|
line.chomp!

  • Twitter
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at del.icio.us
  • Facebook
  • Google Bookmarks
  • FriendFeed
  • Digg Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)"
  • Mixx Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)"
  • Bloglines Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)"
  • Technorati Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)"
  • Fark this: Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)"
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at YahooMyWeb
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at Furl.net
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at reddit.com
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at blinklist.com
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at Spurl.net
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at NewsVine
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at Simpy.com
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" at blogmarks
  • Bookmark Fixing gcode-sender.rb / serialport.rb "invalid byte sequence in UTF-8 (ArgumentError)" with wists
  • wong it!
  • Bookmark using any bookmark manager!
  • Stumble It!
  • Print this article!
  • E-mail this story to a friend!
  • Identi.ca

Trackbacks

No Trackbacks

Comments

Display comments as Linear | Threaded

No comments

Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Form options