ahagelberg

Untitled

May 12th, 2021
412
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import serial
  2.  
  3. # Open serial port
  4. ser = serial.Serial('COM3', 9600)
  5.  
  6. # Enter infinite loop - commands within are repeated until program is terminated
  7. while True:          
  8.     # Read command from serial port
  9.     msg = ser.readline()
  10.     # Decode binary string to unicode string - needed since most Python commands expect unicode strings
  11.     msg = msg.decode('utf-8')
  12.     # Remove trailing line feed
  13.     msg = msg.strip()
  14.     # Print the message
  15.     print(msg)
  16.  
RAW Paste Data