pyserial

Access USB serial ports using Python and pyserial

让人想犯罪 __ 提交于 2019-12-03 03:21:18
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) How do I find out what name should be on a Mac? EDIT: In response to an answer below, I'd like to find

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

匿名 (未验证) 提交于 2019-12-03 03:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In python 3 i imported the pySerial library so i could comunicate 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 diferently is use raw_input but i dont know what is happening in python 3 here is my code import serial, time import tkinter import os def serialcmdw(): os.system('clear') serialcmd = input("serial command: ") ser.write (serialcmd)

pySerial buffer won't flush

匿名 (未验证) 提交于 2019-12-03 02:56:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having a problem with serial IO under both Windows and Linux using pySerial. With this code the device never receives the command and the read times out: import serial ser = serial.Serial('/dev/ttyUSB0',9600,timeout=5) ser.write("get") ser.flush() print ser.read() This code times out the first time through, but subsequent iterations succeed: import serial ser = serial.Serial('/dev/ttyUSB0',9600,timeout=5) while True: ser.write("get") ser.flush() print ser.read() Can anyone tell what's going on? I tried to add a call to sync() but it

pyserial: No module named tools

匿名 (未验证) 提交于 2019-12-03 02:50:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have installed the latest pySerial on my Ubuntu box with python 2.7.2, and it works fine for most things, but whenever I try to import the 'tools' package, it says that it can't find 'tools'. The documentation for pySerial explicitly references this 'tools' package. >>> from serial import tools Traceback (most recent call last): File "<pyshell#30>", line 1, in <module> import serial.tools ImportError: No module named tools and when I: >>> serial.VERSION '2.5' which is the latest version according to Source Forge So why can't I get to the

Is there a way to “compile” Python code onto an Arduino (Uno)?

ε祈祈猫儿з 提交于 2019-12-03 02:09:53
问题 I have a robotics type project with an Arduino Uno, and to make a long story short, I am experimenting with some AI algorithms. However, I need to implement some high level matrix algorithms that would be quite simple using NumPy/SciPy, but they are an utter nightmare in C or C++. Even with the libraries out there, this is just getting ridiculous. Is there any way I can do this project in Python? I think I heard something about the Mega having this capability, but I have an Uno, and replacing

How to access USB port using pySerial (Windows)?

匿名 (未验证) 提交于 2019-12-03 01:26:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to open USB port in Python (using pySerial). I ran port listing tool, but it only shows COM ports. I'd like to open USB port instead (trying to communicate with tablet, but that's not relevant, I suppose). I know it is possible (and quite easy) on Linux, but I am on Windows 8, so there's nothing like "/dev/tty...". I'd like to show you some of my code, but I can't, because I have none yet (I need to know how to open USB port to be able to start coding, I am just testing yet). Maybe I will have to install some other module, but I

pyserial for Python 2.7.2

随声附和 提交于 2019-12-02 21:12:20
I'm new to Python. According to the internets I was looking for the module pyserial after receiving this error: ImportError: No module named serial I first tried to install pywin32 , it went well. But it seems not to contain pyserial. :-( Then I found a single module installer for pyserial, I was not able to install it, it says it did not found the path to python in the registry. :-( After that I found this module on python.org, but I don't know what to do, it does not come with an installer. :-( How can I add pyserial to Python (64) 2.7 on Windows 7 64 ? Constantinius You could try it with

Python .readline()

自古美人都是妖i 提交于 2019-12-02 18:01:34
问题 First let me preface with I am new to python, no ego here. I have this code I cobbled together from various sites the ultimate goal of which being that it would output a hex code to an OBD-II chip and wait for a response. This response, also HEX, is converted to decimal processed and sent to the output. Pretty simple right? Well, there are two problems. One of which being that .readline() removes the first letter of the response. For instance if I wanted ">Elm327" I would get back ">lm327".

Efficient and fast Python While loop while using sleep()

怎甘沉沦 提交于 2019-12-02 18:00:17
I am attempting to communicate with a device over serial using Pyserial. As commands need to be continually sent, they have to be placed in a while loop in Python. I am currently using this code, and have taken a look at python process takes 100% CPU : while True: #do some serial sending here time.sleep(0.2) This code works. However, the sending speed is slow. I tried to make it faster by decreasing the sleep interval, but it seems to load the CPU a bit too much. In short, is there a any way to effectively iterate over a while loop forever, while still maintaining a low consumption of CPU

Is there a way to “compile” Python code onto an Arduino (Uno)?

人走茶凉 提交于 2019-12-02 17:15:15
I have a robotics type project with an Arduino Uno , and to make a long story short, I am experimenting with some AI algorithms. However, I need to implement some high level matrix algorithms that would be quite simple using NumPy / SciPy , but they are an utter nightmare in C or C++. Even with the libraries out there, this is just getting ridiculous. Is there any way I can do this project in Python? I think I heard something about the Mega having this capability, but I have an Uno, and replacing it is not an option at this point (that would set the project back quite a bit.) Also, I heard