Ruby简单的串口通信

def serialport_command(command)
	result = ""
	File.open("COM3","w+") do |sp|
		sp.write(command)
		while char = sp.read(1)
			result += char
			break if result.upcase.include?("ENDEND")
		end
	end
	result
end

编程技巧