-
Notifications
You must be signed in to change notification settings - Fork 0
/
uart_rx_tx.py
27 lines (20 loc) · 873 Bytes
/
uart_rx_tx.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import serial # import the module
import struct
import time
ComPort = serial.Serial('/dev/ttyUSB1') # open COM24
ComPort.baudrate = 115200 # set Baud rate to 9600
ComPort.bytesize = 8 # Number of data bits = 8
ComPort.parity = 'N' # No parity
ComPort.stopbits = 1 # Number of Stop bits = 1
print("Enter 2 sixteen bit numbers.\nThe sum will be printed")
print("Press 'q' to exit infinite loop at any time")
while True:
x=input("Enter number 1: ")
ot= ComPort.write(struct.pack('h', int(x))) #for sending data to FPGA
if x == 'q':
break
y=input("Enter number 2: ")
ot= ComPort.write(struct.pack('h', int(y))) #for sending data to FPGA
it=(ComPort.read(2)) #for receiving data from FPGA
print(f"{x}+{y} = {int.from_bytes(it, byteorder='big')}")
ComPort.close() # Close the Com port