Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from socket import (
- socket,
- AF_INET,
- SOCK_STREAM,
- )
- def make_control(**kwargs):
- head = '<control'
- tail = ' />'
- body = ''
- for key, value in kwargs.items():
- body += ' ' + key + '="' + str(value) + '"'
- return head + body + tail
- def send_command(ip, port, settings):
- settings = make_control(**settings)
- try:
- with socket(AF_INET, SOCK_STREAM) as sock:
- sock.connect((ip, port))
- sock.sendall(data.encode())
- except (ConnectionAbortedError,ConnectionError, ConnectionRefusedError):
- print('Could not connect to {}:{}'.format(ip, port))
- except TimeoutError:
- print('Connection Timout')
- except Exception as e:
- print(e)
- raise
- if __name__ == '__main__':
- settings = {
- 'acc': 1000,
- 'current': 200,
- 'decc': 1000,
- 'mode': 129,
- 'pos': 1000,
- 'speed': 500,
- }
- ip, port = ('192.168.1.102', 10000)
- send_command(ip, port, settings)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement