-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPort_tester.py
More file actions
41 lines (32 loc) · 846 Bytes
/
Port_tester.py
File metadata and controls
41 lines (32 loc) · 846 Bytes
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
# coding: utf-8
import sys
import os
base_path = os.path.dirname(os.path.abspath(__file__))
serial_path = base_path + "\packages\site-packages"
sys.path.insert(0, serial_path)
import serial
import time
port = "COM4"
arg = sys.argv[1:]
if arg != []:
port = arg[0]
print("Testing Port: %s" % (port))
baudrate = 57600
ser = None
try:
ser = serial.Serial(port, baudrate=baudrate, timeout=0.5)
except:
raise Exception("Couldn´t find device.")
time.sleep(2)
print("Test active")
while 1:
adata = ser.readline().decode('ascii').rstrip()
if adata.rstrip() == "t":
print("Received connection test")
val = "c"
ser.write(val.encode('ascii'))
adata2 = ser.readline().decode('ascii').rstrip()
if adata2 == "c":
print("Arduino is online")
break
time.sleep(0.05)