Serial Port Communication Using Python Programming Language

preview_player
Показать описание
Code can be downloaded from the following link:-
or

Books:

Blog Link:
YouTube Channel:
Facebook Page:
Email Id:
Skype ID:
Рекомендации по теме
Комментарии
Автор

Great video!
i have to wait till any character press. can you pls tell me how can i check enterd character in serial terminal(in python).
i have written code in c
int main ()
{
int serial_port ;
char dat;
serial_port = serialOpen ("/dev/ttyS0", 9600)
while(1)
{

if(serialDataAvail (serial_port) )
{
dat = serialGetchar (serial_port); /* receive character serially*/
printf ("%c", dat) ;
fflush (stdout) ;
serialPutchar(serial_port, dat); /* transmit character serially on port */
}
}
}


in python :
import serial
from time import sleep

ser = serial.Serial ("/dev/ttyS0", 9600) #Open port with baud rate
while True:
received_data = ser.read() #read serial port
sleep(0.03)
data_left = ser.inWaiting() #check for remaining byte
received_data += ser.read(data_left)
print (received_data) #print received data
ser.write(received_data)




in c its working fine but in python not working


can u help me pls!

rameshrathod
Автор

I have this Error
File "C:\Users\USUARIO\anaconda3\lib\site-packages\serial\serialutil.py", line 268, in port
raise ValueError('"port" must be None or a string, not {}'.format(type(port)))
ValueError: "port" must be None or a string, not <class 'int'>
help me pleace

johnger
Автор

Thanks bro. Can you show us the condition if there is a specific word in a text file or Excel file in a directory, it triggers a port in a serial, say comm8?

eric
Автор

it's working fine now how can i send these data to my arduino

rishavrajprasad
Автор

please i needed help ... this code don't start with python 3.7 ...
it shows me an error

cedrichounnou
Автор

i can show the list of all available serial ports on PC. help me!!

quoccuongphan
Автор

It was very helpfull to me thaks a lot! I really liked it.

frankjonathansaenz
Автор

I would like write script for port tty on linux
do you have any example?

younes