pyserial

PySerial: How to send Ctrl-C command on the serial line

老子叫甜甜 提交于 2019-11-28 02:41:44
问题 I'm automating a configuration process for an embedded board. To enter the setup screen I need to send "Ctrl-C" command. This is NOT to interrupt a process I'm running locally, KeyboardInterrupt will not work . I need to send a value that will be interpreted by the bootloader as Ctrl-C. What is the value I need to send? Thank you 回答1: IIRC, Ctrl-C is etx . Thus send \x03 . 回答2: You should send a character with the ASCII code 3: serial.write('\x03') 回答3: \x03 Which means 'end of text' or

Reading serial data in realtime in Python

烈酒焚心 提交于 2019-11-27 17:31:45
I am using a script in Python to collect data from a PIC microcontroller via serial port at 2Mbps. The PIC works with perfect timing at 2Mbps, also the FTDI usb-serial port works great at 2Mbps (both verified with oscilloscope) Im sending messages (size of about 15 chars) about 100-150x times a second and the number there increments (to check if i have messages being lost and so on) On my laptop I have Xubuntu running as virtual machine, I can read the serial port via Putty and via my script (python 2.7 and pySerial) The problem: When opening the serial port via Putty I see all messages (the

PySerial App runs in shell, by not py script

混江龙づ霸主 提交于 2019-11-27 17:01:11
问题 I have a very simple python script that uses pySerial to send data over the serial port to my Arduino. When I execute this line-by-line in the python shell, it works just fine, but when I put it in a ".py" file, and try to run it, nothing happens. Though the serial lights on my UART do flash. So something is getting through, but it's garbage (I checked). Here is the simple code. import serial ser = serial.Serial('COM3',9600,timeout=.2) ser.write('A') ser.close() I've already tried adding

pySerial works fine in Python interpreter, but not standalone

纵然是瞬间 提交于 2019-11-27 16:11:01
问题 Good morning! Recently I bought an Arduino board to make sort of "light control" in my room. Here is the code of the firmware I wrote: int control = 0; int pin = 0; void setup() { Serial.begin(9600); for(pin = 0; pin <= 13; pin++) pinMode(pin, OUTPUT); } void loop() { control = Serial.read(); if (control > 0 && control <= 13) digitalWrite(control, HIGH); if (control < 256 && control >= (256-13)) digitalWrite((256-control), LOW); } After that, I used pySerial from Python interpreter to control

Disable DTR in pyserial from code

China☆狼群 提交于 2019-11-27 16:05:03
I'm trying to use pyserial to send data to an arduino. But when I open the COM port it sets DTR low and resets the board. However, I have my arduino code setup such that I have to put it into serial receive mode by holding two buttons for 1 second. I would rather not have to do the serial input on boot of the arduino, if possible. Apparently you can modify serialWin32.py file, changing the line that reads: self._dtrState = win32.DTR_CONTROL_ENABLE to: self._dtrState = win32.DTR_CONTROL_DISABLE But, is there a way to just disable this directly in my python script? I also need to do this for all

python3 pySerial TypeError: unicode strings are not supported, please encode to bytes:

一曲冷凌霜 提交于 2019-11-27 14:34:15
问题 In Python 3 I imported the pySerial library so I could communicate with my Arduino Uno by serial commands. It worked very well in Python 2.7 but in Python 3 I keep running into a error it says this TypeError: unicode strings are not supported, please encode to bytes: 'allon' In Python 2.7 the only thing I did differently is use raw_input but I don't know what is happening in Python 3. Here is my code import serial, time import tkinter import os def serialcmdw(): os.system('clear') serialcmd =

pyserial - How to read the last line sent from a serial device

℡╲_俬逩灬. 提交于 2019-11-27 10:37:34
I have an Arduino connected to my computer running a loop, sending a value over the serial port back to the computer every 100 ms. I want to make a Python script that will read from the serial port only every few seconds, so I want it to just see the last thing sent from the Arduino. How do you do this in Pyserial? Here's the code I tried which does't work. It reads the lines sequentially. import serial import time ser = serial.Serial('com4',9600,timeout=1) while 1: time.sleep(10) print ser.readline() #How do I get the most recent line sent from the device? Vinay Sajip Perhaps I'm

Virtual Serial Device in Python?

六眼飞鱼酱① 提交于 2019-11-27 09:36:35
问题 I know that I can use e.g. pySerial to talk to serial devices, but what if I don't have a device right now but still need to write a client for it? How can I write a "virtual serial device" in Python and have pySerial talk to it, like I would, say, run a local web server? Maybe I'm just not searching well, but I've been unable to find any information on this topic. 回答1: this is something I did and worked out for me so far: import os, pty, serial master, slave = pty.openpty() s_name = os

PyQt5 - Automate Serial module

瘦欲@ 提交于 2019-11-27 07:33:52
问题 I am trying to automate serial connection without clicking on button. When the gui load, serial should be read immediately and refreshed at interval without using the mouse to trigger any button (that is auto read in and updated). How possible is this? See script and GUI below.. import schedule import serial import sys from PyQt5 import uic, QtWidgets qtCreatorFile = "gui.ui" Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile) estudiantes = [' ',' ',' ',' '] ser = serial.Serial('COM9',

pySerial inWaiting returns incorrect number of bytes

北慕城南 提交于 2019-11-27 07:27:35
问题 I've got a simple program to test serial functionality. My serial device reacts to two inputs. If the user enters 'a', it responds with 'fg'. If the user enters anything other character/byte, it responds with 'z'. If I send 'b' to the serial device, it will return 'z' just fine. When I send 'a', it should return both 'f' and 'g', so two bytes instead of one. See code below. #!/usr/bin/env python import serial ser = serial.Serial( port = '/dev/ttyUSB0', baudrate = 9600, parity = serial.PARITY