FAQ Database Discussion Community


Parsing PySerial Data from queue and executing function on command match

python,pyserial
I've created a thread that 'puts' incoming serial data from a host into a queue object. The host sends variable length ascii characters that are terminated with a carriage return/line feed. In the main loop thread I'm grabbing the data this way: try: while True: qCount = list( self.dataQ.get_nowait( )...

pySerial: port only work the first command

python,python-2.7,pyserial
I have a trouble with pySerial. The port can write and read the data only once. When I type the same command, the port doesn't work and return nothing. It's only work on first command. The wxTerminal also only works the first command. Why the port can't command continuously? EDIT:...

how to make matplotlib update from continuous data source?

python,matplotlib,pyserial
I am trying to make a simple graph from a data gathered from a continuous real-time data source. My code for using matplotlib is below: import matplotlib.pyplot as plt import matplotlib.animation as animation import time from serialdata import SerialData fig = plt.figure() ax1 = fig.add_subplot(1,1,1) def animate(i): xar = []...

PySerial client unable to write data

python,python-2.7,pyserial
I'm trying to write a python program which can communicate over a serial interface using PySerial module as follows: import serial if __name__ == '__main__': port = "/dev/tnt0" ser = serial.Serial(port, 38400) print ser.name print ser.isOpen() x = ser.write('hello') ser.close() print "Done!" But if I execute the above I get...

Raspberry PI USB to RS232 adapter Receiving Only Ctrl Chars

python,serial-port,raspberry-pi,pyserial
I'm using a USB to RS232 cable for get communication with a pure rs232 device. With pyserial lib a got this code running in loopback tx -> rx cable pins. Setting the port: def __init__ (self, baudrate,timeout,parity,stopbits,bytesize): try: #self.s = serial.Serial(port="'/dev/ttyUSB0'",baudrate=baudrate,timeout=timeout,parity=parity,stopbits=stopbits,bytesize=bytesize) #self.s = serial.Serial("/dev/ttyUSB0",9600) self.s=serial.Serial( "/dev/ttyUSB0", baudrate=9600, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,...

Use RFC2217 network serial ports with Twisted Python?

python,twisted,pyserial,rfc2217
Is there a way to connect to an RFC2217 networked serial port with Twisted Python? Pyserial seems to support it via the serial.serial_for_url("rfc2217://...") function. And they indicate that twisted uses pyserial for managing serial connections, however twisted.internet.serialport.SerialPort seems to expect a port name or number which suggests it is just...

Why is pyserial pausing python program

python,pyserial
I'm using some python code (running on a raspberry pi) in a loop which is extremely time sensitive (shouldn't deviate much more than +=.0001 s). I've found that if serial.Serial('/dev/ttyUSB0').read(): #what to do when there is data pending data = serial.Serial('/dev/ttyUSB0').read() seems to be the problem . I am seldom...

Handle exception in pyserial during disconnection

python,exception,pyserial
I have code which read data from serial port. try: dataIn = self.port.read(100) except serial.SerialException: #do some work return None If I disconnect device I catch exception which I can't handle someway. Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/serial/serialposix.py", line 475, in read raise SerialException('device reports readiness to read but...

Can't receive reply using PySerial but hyperterminal works

python,pyserial
I have a device (Pololu Wixel) that I'm trying to communicate with using a serial connection over USB. Hyperterminal works fine but I'm trying to use Python for more flexibility. I can send commands to the device, but when I try to receive all I get is the command I...

Serial() Parameters to read a PN532 through uart in python

python,raspberry-pi,pyserial,rfid,uart
So I'm trying to read data from my rfid reader PN532 which is connected to UART on my raspberry pi. The hardware is all connected and should be working properly, because libnfc's example nfc-poll reads my tag and phone, and the nfcpy library can read my phone. Now I want...

Serial Communication between Arduino and Python, issue of using hexidecimal values

python,arduino,pyserial,serial-communication
I am attempting to start a motor from the computer by code in Python 3.4, using pySerial to communicate to an Arduino Uno. I have packed the value I am sending to hexidecimal, so I only have one byte at a time, but am having a problem getting the correct...

Python non-block reading from a serial port: continuously dump the data to a file

python,multithreading,serial-port,pyserial
I am sending continuous stream of data from Arduino to my serial port at a high speed. I would like to dump those data to my hard drive continuously. At low speed, a simple and inefficient code would do: import serial ser = serial.Serial('COM4', baudrate=9600) f = open('data.dat', 'wb') for...

How to reject or accept an incoming call to my GSM modem using AT commands in Python?

python,gsm,at-command,pyserial,modem
I've wrote the below Python program to wait for incoming calls and accept or reject them. Based on this document and this document, the appropriate AT commands to accept an incoming call is ATA or ATS0 or ATS0<n>. And also the appropriate commands to reject the incoming call is ATH...

pySerial cuts off text in file

android,python,serial-port,pyserial
I'm trying to print out the content of a file on my Android through the serial port and it just cut off half of it. My code look like this: ser = Serial('/dev/ttyUSB0', 115200, timeout=0) ser.write(' cat /sdcard/dump.xml \r\n') sleep(5) while ser.inWaiting(): print ser.readline() ser.close() Cat works without any problems...

Can Pyserial work with hid devices?

python,linux,hid,pyserial
I am trying to access a USB device which appears in /dev/ as hidraw4. I have the specification of the communication interface (based on RS232 serial port communication), but I cannot even got the connection with pyserial to work : Code: import serial ser = serial.Serial(port='/dev/hidraw4') Error: serial.serialutil.SerialException: Could not...

Extract string from between quotations python 3.4 serial port

python,extract,pyserial,quotations
I want to identify which serial port of my computer is being used, to do so I have (VSPE which is a virtual serial port emulator just like Eltima virtual serial port driver 7.1) and the following code import sys import glob import serial def serial_ports(): """Lists serial ports :raises...

Issues with PySerial: Port must be configured before it can be used

python,usb,pyserial
I am writing code (in python) to use serial communication with an Arduino, using the pySerial library, on Windows 7. However, I am having issues using the ports correctly. Here is my code: import serial #sets the connection parameters, relook at when know more ser = serial.Serial( port ='COM4', baudrate...