pyserial

Read response AT command with pySerial

孤者浪人 提交于 2019-12-05 00:59:21
问题 I have the following sample code: import serial ser = serial.Serial('/dev/ttyUSB1', 115200, timeout=5) ser.write("AT\r") response = ser.readline() ser.write(chr(26)) ser.close() print response My goal is to send the AT command and get your answer OK . The documentation of PySerial readline() says reads the data received until it finds a line break, the problem is that my print is returning nothing. I'm sure that after the AT command, the response that the 3G modem sends me is OK . Anyone know

pyserial - possible to write to serial port from thread a, do blocking reads from thread b?

不想你离开。 提交于 2019-12-04 18:53:42
问题 I tried googling this, couldn't find an answer, searched here, couldn't find an answer. Has anyone looked into whether it's thread safe to write to a Serial() object (pyserial) from thread a and do blocking reads from thread b? I know how to use thread synchronization primitives and thread-safe data structures, and in fact my current form of this program has a thread dedicated to reading/writing on the serial port and I use thread-safe data structures to coordinate activities in the app. My

Python serial communication

此生再无相见时 提交于 2019-12-04 18:52:53
问题 I'm working on an Arduino project, and I am interfacing it with a Python script due to memory limitations. On the Python side I have a 2 dimensional matrix containing respective x, y values for coordinates, and in this list is 26000 coordinate pairs. So, in interest of clarifying the data structure for all of you, pathlist[0][0] , would return the X value of the first coordinate of my list. Performing different operations, etc. on this list in Python is posing no problems. Where I am running

Need to do a daily log rotation (0utc) using Python

帅比萌擦擦* 提交于 2019-12-04 18:47:35
I'm an admitted noob to Python. I've written a little logger that takes data from the serial port and writes it to a log file. I've got a small procedure that opens the file for append, writes, then closes. I suspect this might not be the best way to do it, but it's what I've figured out so far. I'd like to be able to have it automagically perform a log-rotate at 00 UTC, but so far, my attempts to do this with RotatingFileHandler have failed. Here's what the code looks like: import time, serial, logging, logging.handlers,os,sys from datetime import * CT12 = serial.Serial() CT12.port = "/dev

How do I recover from a serialException using pySerial

99封情书 提交于 2019-12-04 18:09:08
问题 I have an application that reads and transmits data to a device connected via USB. I'm using pySerial to facilitate this communication. Everything works fine until the USB cable is unplugged from the PC and an exception is thrown. Once the cable is plugged back in, I can't seem to recover and reconnect to my device. The only way for me to recover is to close down the application and unplug and plug the cable in again. Any help in understanding what's going on would be much appreciated. This

Python3 Two-Way Serial Communication: Reading In Data

久未见 提交于 2019-12-04 14:58:48
I am trying to establish a two-way communication via Python3. There is a laser range finder plugged into one of my USB ports and I'd like to send/receive commands to that. I have a sheet of commands which can be sent and what they would return, so this part is already there. What I need is a convenient way to do it in real-time. So far I have the following code: import serial, time SERIALPORT = "/dev/ttyUSB0" BAUDRATE = 115200 ser = serial.Serial(SERIALPORT, BAUDRATE) ser.bytesize = serial.EIGHTBITS #number of bits per bytes ser.parity = serial.PARITY_NONE #set parity check: no parity ser

pyserial reading serial port in flask (maybe using gevent)

被刻印的时光 ゝ 提交于 2019-12-04 14:28:07
问题 I'm building a webserver that would need to read (and keep reading) the serial port of the machine it's running on. The purpose is to be able to read a barcode scanner, and using Server-Sent Events to update a browser with the read barcode. I'm using flask to do this. I've browsed around and some implementations require only flask, some say I would need an async library like Gevent, and some others even say I'd need Gevent and some sort of queue like Redis or RabbitMQ. I've tried to base my

Can I use the xmodem protocol with PySerial?

旧时模样 提交于 2019-12-04 14:24:12
问题 I have a working connection with my serial device via PySerial, but I also want to transfer files via the xmodem protocol as part of my program. Which would be the most platform-neutral way to do this? Worst case, I could close() my serial.Serial object in Python and use subprocess to call upon /usr/bin/sb , but that seems inelegant. I'm currently on Ubuntu 9.10 and am using a USB-TTY adapter. Any ideas? 回答1: There is xmodem module on PyPi. It takes two functions in constructor for reading

How can I communicate with a 3G modem via pySerial while it is connected?

白昼怎懂夜的黑 提交于 2019-12-04 12:55:59
I'm running Ubuntu 11.04 and a ZTE 3G modem. The modem is dialed with WvDial When the modem is not in use by WvDial I can send AT commands to the modem, and get information like signal strength: AT+ZCSQ +ZCSQ: 1, -87 OK But when WvDial is using the modem, /dev/ttyUSB0 is locked and I can't query it. Am I missing something obvious? Is there any way I can configure the modem, WvDial , or pyserial so I can send AT commands to the modem while it's connected? Ah. Apparently this modem exposes a couple of ttys to work with. I was able to use /dev/ttyUSB1 to sent AT commands while WvDial was

How to send a value from Arduino to Python and then use that value

為{幸葍}努か 提交于 2019-12-04 11:31:58
问题 I am in the process of building a robot that is remote controlled using Python to send control messages via the Internet through a simple GUI. I have gotten part of my code working pretty well, the GUI and control systems, but I am stuck. I am trying to use a parallax ping sensor to get distance to objects information from an Arduino Mega, and send that value to my Python control script to be displayed on the remote GUI. The main problem that I am having is how to integrate Python code that