-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_send-cmd.py
49 lines (33 loc) · 1.03 KB
/
test_send-cmd.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
# -*- coding: utf-8 -*-
"""
Created on Tue Mar 30 08:31:17 2021
@author: sebas
"""
import serial
import time
try:
serial_steppers = serial.Serial(
'COM22',
baudrate = 9600,
timeout = 0.25,
bytesize = serial.EIGHTBITS,
parity = serial.PARITY_NONE,
stopbits = serial.STOPBITS_ONE,
)
except:
print("ERROR: Failed to open the communication through \'COM22\'")
exit()
running = True
while(running):
cmd = input('command?>> ')
if(cmd == 'q' or cmd == 'quit' or cmd == 'exit'):
serial_steppers.write('exit\n'.encode('utf-8'))
running = False
else:
try:
serial_steppers.write(('%s\n'%cmd).encode('utf-8'))
print("cmd: '{0}' successfully sent!".format(cmd))
except:
print("Failed to send the cmd, the communication might be broken.")
#running = False
serial_steppers.close()