Try communicating to device using putty.
Make sure you have same baudrate (you are using 9600) on both sides of connection, and proper com port number (you have comport 14 now which is unusual unless many devices already connected), uoy may also (although unusual) have to configure parity and stop bits.
This will isolate the problem to either improper hardware connection or code.
If you can't get it to work with putty (
https://www.putty.org/ ) you will never get it to work with python.
This is an important step to take when dealing with serial communications.
One final note, at some point you should capture ValueError and SerialException
So your code would look like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
from tkinter import *
import serial
import time
import sys
try :
s = serial.Serial( 'COM14' , 9600 , timeout = 1 )
time.sleep( 5 )
print ( "connected!" )
s.write( str .encode( 'R' ))
print ( "Sent Message!" )
except ValueError:
print ( 'Value Error message here' )
except SerialException:
print ( 'Serial Exception thrown' )
|
I also noticed that your code line:
1 |
s = serial.Serial( 'COM14' , 9600 , timeout = 1 )
|
was improperly indented (which would have shown up is you use code tags!