SHARE
TWEET

Henschel HiDrive Servo example

DeaD_EyE Oct 31st, 2018 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from socket import (
  2.     socket,
  3.     AF_INET,
  4.     SOCK_STREAM,
  5.     )
  6.  
  7.  
  8. def make_control(**kwargs):
  9.     head = '<control'
  10.     tail = ' />'
  11.     body = ''
  12.     for key, value in kwargs.items():
  13.         body += ' ' + key + '="' + str(value) + '"'
  14.     return head + body + tail
  15.  
  16.  
  17. def send_command(ip, port, settings):
  18.     settings = make_control(**settings)
  19.     try:
  20.         with socket(AF_INET, SOCK_STREAM) as sock:
  21.             sock.connect((ip, port))
  22.             sock.sendall(data.encode())
  23.     except (ConnectionAbortedError,ConnectionError, ConnectionRefusedError):
  24.         print('Could not connect to {}:{}'.format(ip, port))
  25.     except TimeoutError:
  26.         print('Connection Timout')
  27.     except Exception as e:
  28.         print(e)
  29.         raise
  30.  
  31.  
  32. if __name__ == '__main__':
  33.     settings = {
  34.         'acc': 1000,
  35.         'current': 200,
  36.         'decc': 1000,
  37.         'mode': 129,
  38.         'pos': 1000,
  39.         'speed': 500,
  40.         }
  41.     ip, port = ('192.168.1.102', 10000)
  42.     send_command(ip, port, settings)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top