Skip to content

Commit 05172c6

Browse files
authored
Create robodk.py
1 parent 01c363e commit 05172c6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

robodk.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import sys
2+
from robodkdriver.robot import Robot
3+
4+
ROBOTCOM_STATUS = {
5+
'ready': 'Ready',
6+
'working': 'Working...',
7+
'waiting': 'Waiting...',
8+
'disconnected': 'Disconnected',
9+
'not_connected': 'Not connected',
10+
'connection_problems': 'Connection problems',
11+
}
12+
13+
14+
class RoboDK:
15+
def __init__(self, robot: Robot):
16+
self._robot = robot
17+
18+
@classmethod
19+
def update_status(cls, status: str):
20+
if status in ROBOTCOM_STATUS:
21+
status = 'SMS:' + ROBOTCOM_STATUS[status]
22+
23+
cls._print_message('{status}'.format(status=status))
24+
25+
def run_driver(self):
26+
while True:
27+
# If input is available
28+
if not sys.stdin.isatty():
29+
command = sys.stdin.readline()
30+
command = self._parse_command(command)
31+
32+
status = self._robot.run_command(**command)
33+
self.update_status(status)
34+
35+
@staticmethod
36+
def _print_message(message):
37+
print(message)
38+
sys.stdout.flush()
39+
40+
@staticmethod
41+
def _parse_command(command):
42+
parts = command[0:-1].split(' ')
43+
parts = list(map(str.strip, parts))
44+
45+
parts = {
46+
'cmd': parts[0],
47+
'args': parts[1:]
48+
}
49+
50+
return parts

0 commit comments

Comments
 (0)