-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPGA_Server.py
33 lines (26 loc) · 911 Bytes
/
FPGA_Server.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
28
29
30
31
32
33
# This code should be run in advance of GPU_server.py
import socket
import serial
HOST = '127.0.0.1' # Standard loopback interface address (localhost)
PORT = 22 # Port to listen on (non-privileged ports are > 1023)
RECV_BUFFER_SIZE = 1024
def fc_on_fpga(data):
# This function should send data to FPGA and return the received results
ser = serial.Serial('/dev/ttyUSB1/', 19200)
ser.write(data)
s = ser.read(10)
return str(s.hex())
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while True:
data = conn.recv(RECV_BUFFER_SIZE)
if not data:
break
else:
print('Received', repr(data))
rsts = fc_on_fpga(data)
conn.sendall(str.encode(rsts))