Skip to content

Instantly share code, notes, and snippets.

@pklaus
Created September 19, 2012 16:47
Show Gist options
  • Save pklaus/3750717 to your computer and use it in GitHub Desktop.
Save pklaus/3750717 to your computer and use it in GitHub Desktop.
New Focus Picomotor Series – TCP/IP Control of An 8752 Ethernet Controller via Python
#!/usr/bin/env python
import socket
import time
TCP_IP = '192.168.10.77'
TCP_PORT = 23
BUFFER_SIZE = 1024
MOVE_FORWARD_MESSAGE = 'FOR A1 G'
MOVE_REVERSE_MESSAGE = 'REV A1 G'
STOP_MESSAGE = 'STO'
#SET_FAST_MESSAGE = 'VEL A1 0=2000'
#SET_SLOW_MESSAGE = 'VEL A1 0=250'
## does the same job:
SET_FAST_MESSAGE = 'RES COARSE'
SET_SLOW_MESSAGE = 'RES FINE'
def send(message):
print message
s.send(message + '\n')
time.sleep(0.005)
def receive():
data = s.recv(BUFFER_SIZE)
time.sleep(0.005)
return data
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
time.sleep(0.1)
print receive()
send(SET_FAST_MESSAGE)
print receive()
send(MOVE_FORWARD_MESSAGE)
print receive()
time.sleep(1)
send(STOP_MESSAGE)
print receive()
time.sleep(1)
send(MOVE_REVERSE_MESSAGE)
print receive()
time.sleep(1)
send(STOP_MESSAGE)
print receive()
time.sleep(1)
send(SET_SLOW_MESSAGE)
print receive()
send(MOVE_FORWARD_MESSAGE)
print receive()
time.sleep(1)
send(STOP_MESSAGE)
print receive()
time.sleep(1)
s.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment