QuickTip #241 - Python Tutorial - Read Serial Port Data

preview_player
Показать описание
Python Tutorial - Read Serial Port Data
|||||||||||||||||Affiliate-Links|||||||||||||||||
Meine Buchempfehlungen:
Facebook:
Рекомендации по теме
Комментарии
Автор

Make sure to have the pyserial library installed.
Here'sa guide how to do it in PyCharms.
Regards,

TheCarloszoom
Автор

Hey, love your "commando style" format -- quick, bare bones answer without a lot of chatter or unecessary info. Just a couple comments that I hope are helpful: 1) You could maybe use a higher-contrast color scheme to make your code more readable and 2) I guess you are using the pySerial library ... so maybe clarify that up front so we can install it.

DaveFer
Автор

I’m setting the timeout to 2 while creating the serial object. When I’m reading from serial port I’m checking wether data is present in input buffer by :
if(obj.inWaiting>0) :

If the data packets are interrupted it hangs in there.... I have given timeout value as 2 still it’s waiting indefinitely... why it’s not considering timeout value????

prasadvaidya
Автор

Thank you so much. Got my USB-COM port barcode scanner to work with your python script. :)

hareshindrajit
Автор

after running the python code it is giving me following error
the code is
import serial

ser = serial.Serial(port='COM5', baudrate = 9600, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, timeout=2)
try:
ser.isOpen()
print("Serial port is open")
except:
print("ERROR")
exit()

if(ser.isOpen()):
try:
while( True ) :
print(ser.read())
except:
print("error")
else:
print("Cannot open serial port")


error i recieve:

Traceback (most recent call last):
File "C:/Users/Ing Saeed/Desktop/serialdatapython.py", line 1, in <module>
import serial
ModuleNotFoundError: No module named 'serial'

saeedahmed
Автор

Thanks a lot, i finally have finished my problem.

Now, do You know how to receive data and in the same time to emit data from same port? Because if you send the data from the port, you can make a contact (with screwdriver if you want) between second and third pin on the port and you receive the same data which you have sent.(in purpose to simulate another port) It bothers me how to make at the same tame to get and to emit data.

And please put in description the code, for us not to manually copy down whole code.

ahmedkrdzalic
Автор

is it possible to read data from network serial port?

jigishaprajapati
Автор

Thanks..i can solve my problem..event Handler thank you very much

PuputDanny
Автор

please send the code in the description.

mohamedharmouche
Автор

It sais There is an errror. The library named "serial" does not work. the error was "ImportError: No module named 'serial'"
PLZ HELP

hdbrom