Ruby and Python sending data over serial behaving differently -
i trying create ruby library lcd. have written little amount of python code sends image, , derived illustration code. code works. updates lcd screen bitmap image provided.
import serial import io import sys import os import time import re ser1 = serial.serial() #initialize serial connection ser1.baudrate = 115200 #set baud rate ser1.port = '/dev/ttyacm0' #set port print ser1.port #print out port verification ser1.open() #start serial connection bmp1 = open('image.bmp', 'rb') #open bitmap file sending data1 = bmp1.read() #store info in variable bmp1.close() #close bitmap file ser1.write(data1) #send info on serial lcd
however, when converted code ruby, running not display on lcd. running 1 time again wouldn't display anything. running 3rd time, however, cause lcd filled 3 copies of image, overlapping each other. if cleared screen , ran again, final result of overlapped images not same previous time.
the next ruby code:
require 'serialport' port = "/dev/ttyacm0" baud = 115200 puts "connecting lcd on port #{port}, baud #{baud}" lcd = serialport.new(port, baud) bmp = file.open("image.bmp", "rb") info = bmp.read bmp.close puts "sending data..." lcd.write(data)
i can't seem figure out why behave differently, or how create ruby code work expected. have tried adding lcd.flush
end of file, still doesn't display on first run of program.
python ruby lcd
No comments:
Post a Comment