Python stepper control code.

#!/usr/bin/python

import serial # if you have not already done so
import sys

# 	usage :
#	python _stepper.py -1 S
#	1 step counter clockwise

#	python _stepper.py 12 R
#	12 revs clockwise

#	bitmask for revolutions
revs = 128
#	bitmask for clockwise / anticlockwise
pos = 64

def binary(n):
	l=[]
	while(n>0):
		l.append(str(n&1)); n=n>>1
	return "".join(l[::-1])
	
	
r = int(sys.argv[1])

if ( r > 0 ):
#	its positive
	r = r + pos + revs
	print "`Clockwise,",
else:
	r = r * -1
	r = r + revs
	print "`Anticlockwise,",

print abs(int(sys.argv[1])),

if ( len(sys.argv) > 2 ):
	if ( sys.argv[2] == 'S' ):
		revs = 0
		print "Steps\'"
else:
	print "Revolutions\'"


ser = serial.Serial('/dev/tty.usbserial-A1000gh8', 38400)
print "binary " + binary(r)
print "int    " + str(r)
print "char   " + chr(r)
ser.write(chr(r))