-
Notifications
You must be signed in to change notification settings - Fork 1
/
COMport.py
50 lines (35 loc) · 1.02 KB
/
COMport.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
This is a program to demonstrate a multithreading operation which is done using two virtual ports using
VSPD and a python module called pySerial
"""
import time
import threading
from serial import Serial
def send():
write_port = Serial(port = "COM1", timeout = 0, baudrate = 9600)
sender = write_port.write(b'hello')
print(sender)
print(write_port.is_open)
print(write_port.baudrate)
print(write_port.port)
print(write_port.in_waiting)
print(write_port.out_waiting)
# write_port.close()
return sender
def recieve():
read_port = Serial(port = "COM2", timeout = 5, baudrate = 9600)
reciever = read_port.read()
print(reciever)
print(read_port.is_open)
print(read_port.baudrate)
print(read_port.port)
print(read_port.in_waiting)
print(read_port.out_waiting)
# read_port.close()
return reciever
thread_1 = threading.Thread(target = send)
thread_2 = threading.Thread(target = recieve)
thread_1.start()
thread_2.start()
thread_1.join()
thread_2.join()