pyserial

How to check if device is connected Pyserial

最后都变了- 提交于 2019-12-09 11:28:10
问题 I am connecting with my Arduino through a USB port and sending data to it by using PySerial module. At first I can check if the device is connected by using this code: try: ser = serial.Serial("COM3", 9600) except serial.serialutil.SerialException: print "Arduino not connected" Now what I want to do is to check periodically if the Arduino is still connected to the computer. I tried ser.isOpen() but this returns true even if the Arduino is disconnected. I would also like to know how to

OSError: [Errno 13] Permission denied: '/dev/ttyACM0' - using pyserial from Python to Arduino

眉间皱痕 提交于 2019-12-09 06:05:46
问题 Environment Linux Mint 17.1 Python 2.7 pyserial 2.7 Arduino UNO rv3 Desired Behaviour I'm trying to send three values from a Python application to Arduino. It works when doing the following from terminal: $ python $ import serial $ import struct $ ser = serial.Serial('/dev/ttyACM0', 9600) $ ser.write(struct.pack('>3B', 255, 0, 0)) Current Behaviour It doesn't work when using the same code in a Python file ie: import serial import struct ser = serial.Serial('/dev/ttyACM0', 9600) ser.write

ImportError: No module named serial

坚强是说给别人听的谎言 提交于 2019-12-08 14:41:53
问题 I have a script written in Python 3 with 3.3.5 installed, and I am getting this error from the terminal whenever I try to run it. I am using a Mac, OSX 10.7.5 I have already installed pyserial (using pip) for python 3. In order to do this, I first installed pip using: $ curl -O http://python-distribute.org/distribute_setup.py $ sudo python3 distribute_setup.py $ curl -O https://raw.githubusercontent.com/pypa/pip/master/contrib/get-pip.py $ sudo python3 get-pip.py I then installed pyserial

serial.serialutil.SerialException: [Errno 16] could not open port: [Errno 16] device or resource busy: '/dev/ttyACM0'

僤鯓⒐⒋嵵緔 提交于 2019-12-08 12:57:49
问题 I'm trying to print serial output from Arduino Uno onto my screen using Pyserial python library. Here is my Arduino code. It just produces and prints random numbers to serial monitor: void setup() { Serial.begin(9600); } void loop() { long rand = random(10); Serial.print(rand); } My python code is just supposed to print the values from serial onto the command line, here is the code: #!/usr/bin/python import serial ser = serial.Serial("/dev/ttyACM0",9600) while True: thing = ser.readline()

pySerial: opening multiple ports at once

大憨熊 提交于 2019-12-08 08:15:52
问题 EDIT : Found the problem: I tried referencing a variable, but mixed up its name, so instead I declared a new variable. Turns out pySerial is not limited to one open serial point at a time. I'm trying to open two serial ports at once using the following code ser0 = serial.Serial( port = port_list[0], baudrate = 115200, timeout = 0.1 ) ser1 = serial.Serial( port = port_list[1], baudrate = 115200, timeout = 0.1 ) But it seems that I open the second, the first one closes. Is there an inherent

Python/Pyserial: reading incoming information from port

风格不统一 提交于 2019-12-08 05:16:00
问题 I've just started using pyserial as I will eventually need to read/save information coming from a particular port. Using the following code I am merely printing the port used and then trying to write and then read in some text ("hello"). The port is printing fine, but the output of my string is coming out as 5. Any idea why this is? import serial import sys from time import sleep try: ser = serial.Serial('\\.\COM8', 9600,timeout=None, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,

Python xbee library no output for incoming frames

大憨熊 提交于 2019-12-08 04:41:20
问题 I am using 2 XBee pro S1, I want to read the packets received by the co-ordinator on my PC , it is enabled with API_2 and all other connections are done properly, I can see the packets with XCTU, I am using the python xbee library , but it gives no output : The Code : import serial.tools.list_ports from xbee import XBee import serial ports = list(serial.tools.list_ports.comports()) for p in ports: #print the list of ports print p def toHex(s): lst = [] for ch in s: hv = hex(ord(ch)).replace(

How to open a serial port with pyserial?

故事扮演 提交于 2019-12-08 04:12:58
问题 I am trying to open a serial port with python. This is on Ubuntu. I import the openinterface.py and enter in this ser = openinterface.CreateBot(com_port = "/dev/ttyUSB1", mode="full") I get an error saying "unsupported operand types for -: 'str' and 'int'" I tried the same call with single quotes instead of double, and with no quotes at all. How can I fix this? Or is there an alternative function to use? I only know the basics of Python so maybe its some small syntax thing I am not noticing?

Pyserial, Getting extra info from OBD Device

邮差的信 提交于 2019-12-08 03:09:55
问题 I am new at programming and am trying to communicate with my vehicle with an OBD II device. Serial to USB. I've done what I want it to do but I get the command I entered to print out. How do I just get the information from the device? Heres my code. I am using Python 3.2.3 import serial import time import string import io import os import sys ser = serial.Serial("/dev/ttyUSB1") ser.baudrate = 38400 s = input('Enter AT command --> ') print ('AT command = ' + s) ser.write(bytes(s + '\r\n',

Using Pyserial to send a file?

大憨熊 提交于 2019-12-08 01:56:47
问题 I have a Raspberry Pi connected to my Macbook Pro by two radio modules. I have been successful so far in sending strings and commands from one device to the other using pyserial, however, I cannot find a way to send a text file. Like on HyperTerminal, where you can choose to send a text file over xmodem. I have downloaded the xmodem library and played with it a bit, and I think I am able to send files, but I have no idea how to receive them on the other end. Any help? 回答1: this question is