pyserial

Kill process that raises Device or resource busy: '/dev/ttyUSB0'?

▼魔方 西西 提交于 2019-12-12 08:20:06
问题 I connect to my Arduino board with the following Python code. device=glob.glob("/dev/ttyUSB*")[0] time.sleep(1) arduino = serial.Serial(device, 115200, timeout=5) It generally works, but somehow some other process must be accessing the board after reboot giving me the error serial.serialutil.SerialException: could not open port /dev/ttyUSB0: [Errno 16] Device or resource busy: '/dev/ttyUSB0' When unplugging and replugging the USB-plug I can execute the Python code normally, without the error

How to read data from pyserial incrementally?

老子叫甜甜 提交于 2019-12-12 04:45:55
问题 I am trying to send an image by chunks of 50 bytes. I am able to send it via Python across two xbees serially. Now , i want to read first 50 bytes and append it to a variable , then after the next 50 bytes , append it and so on . But I cant find a good solution at all . Any help ? I am now getting error f.write(data_stream[i:i+inc]). Type error must be string or buffer. The amount of bytes , length of image is 6330 in sending side . But in the receiving side it is 129. I am in no where now .

Pyserial converting bytes to normal string

你说的曾经没有我的故事 提交于 2019-12-12 04:29:07
问题 I am receiving a packet through a serial port but when I receive the packet it is of class bytes and looks like this: b'>0011581158NNNNYNNN +6\r' How do I convert this to a normal string? When I try to take information from this string, it comes out as a decimal representation it appears. 回答1: You can call decode on the bytes object to convert it to a string, but that only works if the bytes object actually represents text: >>> bs = b'>0011581158NNNNYNNN +6\r' >>> bs.decode('utf-8') '

pyserial communication with arduino (for motor-control)

删除回忆录丶 提交于 2019-12-12 02:42:14
问题 I would like to send data from python do arduino in order to control motors via relays. Idea is to send a number, in order to identify a motor and a value, to finally move it. Unfortunately im struggling with some problems. Data is getting lost. So, in this minimal example there is an identifier "n", to indicate that the received data is the variable "number" and an identifier "c" to identify that the received data is a counter. To find out what's wrong, I send the data back to Python and try

Writing into CSV file using python

僤鯓⒐⒋嵵緔 提交于 2019-12-12 00:22:43
问题 Here some simple code I have written. Data is not accumulated in the CSV file; can someone share code to read data from serial port and log this to a CSV file? import serial import csv import string import os import time import sys def main(): pass if __name__ == '__main__': main() count=0 f=open("test.txt","w+"); result = csv.writer(f,delimiter=',', dialect='excel-tab') result_statememt=("date","zenith","elevation","azimuth","conv_elevation"); result.writerow(result_statememt) f.close()

using PySerial don't work until port is opened with minicom

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-11 21:21:00
问题 I developed a plugin for Domoticz on a RPi3B+. This plugin is in Python. I want to send commands to a Arduino board using a USB serial port. The plugin opens the serial port, sends a command and closes the serial port. It works well except after a reboot. After a reboot, the port is open, and the command seems to be sent to the Arduino, but it doesn't understand it, just as if the baud rate were wrong. Arduino's Rx LED is blinking. If I open the serial in parallel using minicom and exit

Using xonxoff-flow control with pyserial

与世无争的帅哥 提交于 2019-12-11 19:18:53
问题 I am currently trying to interface with a somewhat old old model of a HP-printer which gives me two possible methods of flow-control: No flow control at all or software-based flow control (XON/XOFF). I am initializing pySerial with the following command and just justing a plain big string to write my data to the port: serial = serial.Serial(port = '/dev/ttyUSB3', baudrate = 9600, parity = serial.PARITY_ODD, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS) This works fine - but

Maximize Arduino serial output

给你一囗甜甜゛ 提交于 2019-12-11 13:47:41
问题 There are a multiple questions intersperced throughout this post. Kindly read carefully and answer the pieces you can for an upvote. Use Case Create a time series csv file of pressure reads. These reads need to be of maximum frequency, but I only need it to last less than 10 seconds or so. Material Arduino Uno Clone (unalterable) serial over USB 2.0 (alterable) pyserial (Python 3) SSD Problem Identify and fix the bottleneck preventing frequency from maximum reads/s. The code Arduino void

pySerial can write, but not read

若如初见. 提交于 2019-12-11 13:39:52
问题 I am trying to use pySerial on a Windows 10 machine (Python 3.6.4, 32 bit) to read serial data from a piece of lab equipment that would normally log its data to a serial ASCII printer. Connecting using a USB-to-serial adaptor. If I connect the computer to the printer, I can print using serial.write(), so I know my adaptor is working. However, when I connect the computer to the lab equipment and try to read data using the following code, I get nothing all: import serial ser = serial.Serial(

Disable RTS/DSR Handshaking while keeping lines high in PySerial

橙三吉。 提交于 2019-12-11 12:43:45
问题 I'm using PySerial to read serial messages form a device. The device communicates in TTL. The TTL->RS-232 converter (which is then emulated on its USB input) requires DSR and RTS lines be high to receive power. So I attempt to send data: import serial port = serial.Serial(arguments...,rtscts=True,dsrdtr=True) port.write(b'Hello World) This script will hang forever (or I've never seen it exit). I'm assuming this is because my handshaking lines are dictating I currently can't send a message. Is