pyserial

Passing serial data to javascript via Flask

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 09:53:05
问题 I've been poking around with pushing data from Flask to Javascript, mainly by modifying the code found here: https://github.com/clebio/flask-d3 Now I'm trying to read data from a COM Port and pass it through Flask to Javascript. I've done some of this before using PySerial, but am not sure the right way to approach combining it into Flask. I feel comfortable implementing something where, with each request, the port is opened, reads a line, and is closed. That's not very efficient, so ideally

Python: Writing to and Reading from serial port

梦想的初衷 提交于 2019-12-22 06:48:15
问题 I've read the documentation, but can't seem to find a straight answer on this. I have a list of all COM Ports in use by Modems connected to the computer. From this list, I try to open it, send it a command, and if it says anything back, add it to another list. I'm not entirely sure I'm using pyserial's read and write functions properly. i=0 for modem in PortList: for port in modem: try: ser = serial.Serial(port, 9600, timeout=1) ser.close() ser.open() ser.write("ati") time.sleep(3) print ser

Reconnecting to device with pySerial

*爱你&永不变心* 提交于 2019-12-22 05:10:07
问题 I am currently having a problem with the pySerial module in Python. My problem relates to connecting and disconnecting to a device. I can successfully connect to my device and communicate with it for as long as I want to, and disconnect from it whenever I desire. However, I am unable to reconnect to the device once the connection has been severed. Here is the wrapper class that my program uses to interface with the serial port: import serial, tkMessageBox class Controller: """ Wrapper class

Python3 Two-Way Serial Communication: Reading In Data

删除回忆录丶 提交于 2019-12-21 20:09:57
问题 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

Using a QThread in PyQT for serial communication (w. pyserial)

眉间皱痕 提交于 2019-12-21 05:05:19
问题 I am pretty much a beginner when it comes to GUI programming. I am using QT in combination with python bindings (PyQT4). What I am trying to do: Setting up a QThread to read from & write to a Serial Port with pyserial. The main application should be able to emit new serial data via a signal to the running QThread . and receive serial data from the QThread with a signal. I started my own test implementation based on this code (Link). Prior to this I read the basics about QThread s and tried to

Reading real time values with pySerial while plotting

二次信任 提交于 2019-12-21 02:48:15
问题 So here is the deal, I have a module which sends out data over the serial port at 9600 baud and I am using the matplotlib to plot that data in real time. I wrote this code #! python ############ import section ################### import serial import struct import numpy as np import matplotlib.pyplot as plt ############################################### ############ Serial Configuration ############# com = serial.Serial(14,9600) print ("Successfully opened " + com.portstr) ##################

Access USB serial ports using Python and pyserial

浪子不回头ぞ 提交于 2019-12-20 12:16:51
问题 How do I access the USB port using pyserial? I have seen an example with: import serial ser = serial.Serial('/dev/ttyUSB0') I used to access the serial port from MATLAB on Windows and using the appropriate syntax, /dev/ttyUSB0 would be replaced by COM1 or any other COM port. I'm on a Mac and I tried using the serial port scanners on the pyserial documentation to no avail. I think I should write it like this: import serial name = ? # Names of serial ports on Mac OS X ser = serial.Serial(name)

Access USB serial ports using Python and pyserial

我的未来我决定 提交于 2019-12-20 12:16:45
问题 How do I access the USB port using pyserial? I have seen an example with: import serial ser = serial.Serial('/dev/ttyUSB0') I used to access the serial port from MATLAB on Windows and using the appropriate syntax, /dev/ttyUSB0 would be replaced by COM1 or any other COM port. I'm on a Mac and I tried using the serial port scanners on the pyserial documentation to no avail. I think I should write it like this: import serial name = ? # Names of serial ports on Mac OS X ser = serial.Serial(name)

Erratic encoding of byte to string on Python 3 on Ubuntu

时间秒杀一切 提交于 2019-12-20 05:45:08
问题 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)

Python Multi-threading with PySerial object

家住魔仙堡 提交于 2019-12-20 01:38:45
问题 I am new to Python and programming in general. I am trying to write a device driver using pyserial. I opened a thread that would read data from the device and send it to std out. On my main loop I used a function that would read instructions from std in as strings and write them to the device using a dictionary. My program is reading my instructions but is not displaying any data that should be coming out of the device - I know its writing to the device because it crashes when I use an