pyserial

Python .readline()

蹲街弑〆低调 提交于 2019-12-02 12:27:18
First let me preface with I am new to python, no ego here. I have this code I cobbled together from various sites the ultimate goal of which being that it would output a hex code to an OBD-II chip and wait for a response. This response, also HEX, is converted to decimal processed and sent to the output. Pretty simple right? Well, there are two problems. One of which being that .readline() removes the first letter of the response. For instance if I wanted ">Elm327" I would get back ">lm327". The other problem the bigger of the two is when I use .readline() I only get the request that I sent for

pySerial sends ASCII data but recieving device does not respond to it

懵懂的女人 提交于 2019-12-02 11:41:11
I have been trying to get pySerial to send commands to a device (Weight scale, and mass flow controller) both use ASCII format, and both do not respond to comands sent. However I can easely control both with use of Terminal. I have create a virtual comport to see whats being sent to my devices from pySerial but it sends correct data. (T\r\n is sent as T 13 10, same as what Terminal sends ) so I am at a loss. It seems as though pySerial sends out the right data to my device but for what ever reason is not properly accepted, strangely I can easely read data from the device using pySerial. Its

How to read serial data with multiprocessing in python?

ε祈祈猫儿з 提交于 2019-12-02 11:24:12
I have a device that outputs data at irregular intervals. I want to write data onto a csv in 2 second intervals. So I figured multiprocessing with a queue might work. Here I'm trying to just pass data from one process to another but I get Serial Exception. Also, I'm unable to run it on IDLE. So I'm stuck with using the terminal. As a result, the error message closes as soon as it opens. Here's the code: import multiprocessing import time import datetime import serial try: fio2_ser = serial.Serial("COM3", baudrate=2400, bytesize=serial.EIGHTBITS, parity =serial.PARITY_ODD) except serial

Erratic encoding of byte to string on Python 3 on Ubuntu

丶灬走出姿态 提交于 2019-12-02 08:17:23
I'm new to Python and am working on a sensor. I'm building my code line by line and I have trouble with the encoding/decoding part for bytes to string. Same code, sometime it works, sometime it dosen't. Here is the code: import serial import time import os port = serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=1, bytesize=8) f_w = open('/home/myname/python_serial_output.txt','r+') port.send_break() while True: op = port.read(2) op_str = op.decode('utf-8') f_w.write(op_str) print(op_str) It didn't work the first time round, but worked on the second time. Why? Here is the error I get:

Sending string to serial.to_bytes not working

ぐ巨炮叔叔 提交于 2019-12-02 07:00:50
问题 I am trying to send a string variable contains the command. Like this: value="[0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a]" self.s.write(serial.to_bytes(value)) The above one fails. Won't give any error. But it's working when I send a value like this: self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) I also tried sending string like this: self.s.write(serial.to_bytes(str(value))) Still not working. Can someone please let me know how to send the value by storing in string? I want to

Sending string to serial.to_bytes not working

。_饼干妹妹 提交于 2019-12-02 05:03:10
I am trying to send a string variable contains the command. Like this: value="[0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a]" self.s.write(serial.to_bytes(value)) The above one fails. Won't give any error. But it's working when I send a value like this: self.s.write(serial.to_bytes([0x31, 0x0a, 0x32, 0x0a, 0x33, 0x0a])) I also tried sending string like this: self.s.write(serial.to_bytes(str(value))) Still not working. Can someone please let me know how to send the value by storing in string? I want to do this thing: value="[0x"+anotherstring+",0x"+string2+"0x33, 0x0a]" and send the value. Thanks! If

python and serial. how to send a message and receive an answer

↘锁芯ラ 提交于 2019-12-02 01:36:51
I have to send ZANE:1:00004:XX_X.X_XXXX_000XX:\r\n via serial communication with python. here is my code: import serial ser = serial.Serial('/dev/cu.usbserial-A901HOQC') ser.baudrate = 57600 msg = 'ZANE:1:00004:XX_X.X_XXXX_000XX:\r\n' If I write: >>> ser.write(msg) the answer will be 33 , which is the length in byte of the message I'm sending. How can I receive the answer? The connected device will answer just after he gets the message, but if I type >>> ser.write(msg); ser.readline() the result will be that readline never gets any message at all... any ideas? Your device is probably not

Python : How to know serial port device events like keybord events

允我心安 提交于 2019-12-02 00:01:07
问题 Hi i am new to python i am able to connect to the serial port device & want to know any changes are happened in the device (i want catch the event if any button is press in the device) How can i do this.With The help of pyHook in python i am able to find the keyboard events and mouse events with calling the functions "OnKeyboardEvent" & "OnMouseEvent" how to catch the any serial port device events.Is there any thing in python OnSerailportdeviceEvent function. 回答1: There is no built-in library

Can't open serial connection in Pyserial: “termios.error: (22, 'Invalid argument') ”

牧云@^-^@ 提交于 2019-12-01 19:51:39
问题 I'm having problem executing the following code: import serial ser = serial.Serial( port='/dev/tty.FireFly-16CB-SPP', baudrate=115200, #parity=serial.PARITY_ODD, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS ) ser.open() ser.isOpen() This worked yesterday, and I don't know what I changed. Now I get the following error message: Traceback (most recent call last): File "main.py", line 32, in <module> bytesize=serial.EIGHTBITS File "/Library/Frameworks/Python.framework/Versions/2.7/lib

pyserial serialwin32.py has attribute error

北慕城南 提交于 2019-12-01 14:13:16
I'm new to Python and trying to run a demo provide by Invensense. They provide a Python client which should take COM traffic and manipulate a graphic. The demo seems to crash out of the box and I'm not sure if I have something wrong with pyserial that I installed. The requirements were python2.7, pyserial and pygame. The pyserial executable serialwin32.py throws this error: Traceback (most recent call last): ....... File "C:\Python27\lib\site-packages\serial\serialwin32.py", line 47, in open if port.upper().startswith('COM') and int(port[3:]) > 8: AttributeError: 'int' object has no attribute