Add files via upload
This commit is contained in:
132
test-counts.py
Normal file
132
test-counts.py
Normal file
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import serial
|
||||
import serial.rs485
|
||||
import sys
|
||||
import time
|
||||
import packet
|
||||
|
||||
def read_and_print(sport, print_it=True):
|
||||
s = sport.read(6)
|
||||
barr = bytearray(s)
|
||||
ll = (barr[5]<<8) + barr[4]
|
||||
s2 = sport.read(ll+4)
|
||||
barr += bytearray(s2)
|
||||
if print_it:
|
||||
print('Rx:'),
|
||||
for b in barr:
|
||||
print(" %02x" % b),
|
||||
print('')
|
||||
return barr
|
||||
|
||||
def color_handling(s):
|
||||
b = bytearray(s)
|
||||
for idx in range(len(b)):
|
||||
if chr(b[idx]) == '`':
|
||||
b[idx+1] = int(chr(b[idx+1]))
|
||||
|
||||
s=b.translate(None,'`')
|
||||
return s
|
||||
|
||||
def send_packet(s, print_it=True):
|
||||
ser.rts = False # Set high... logic is inverted
|
||||
ser.write([s[0]])
|
||||
for c in s[1:]:
|
||||
if c == 0xfe or c == 0xff:
|
||||
if print_it:
|
||||
print('escape')
|
||||
ser.write([0xfe])
|
||||
ser.write([c])
|
||||
time.sleep(.005) # This delay seems to work...
|
||||
ser.rts = True # Set low... logic is inverted
|
||||
|
||||
def test_setup_color (print_it):
|
||||
string = '`1`1`1`1`1`1'
|
||||
time.sleep(.5)
|
||||
# 22 columns instead of 23 now
|
||||
for c in [1, 2, 3, 16, 17, 18, 19, 20, 21, 22]:
|
||||
#for c in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]:
|
||||
#for c in [1, 2, 3, 4, 5, 6, 7, 8]:
|
||||
s = color_handling(string)
|
||||
# 6 rows instead of 7 now
|
||||
val = ' '*(6-len(s))+s
|
||||
send_packet(packet.set_targets(c, val, print_it))
|
||||
read_and_print(ser, print_it)
|
||||
|
||||
send_packet(packet.arm(c, print_it))
|
||||
read_and_print(ser, print_it)
|
||||
|
||||
def test_setup (string, print_it):
|
||||
time.sleep(.5)
|
||||
# 22 col instead of 23 now
|
||||
for c in [1, 2, 3, 16, 17, 18, 19, 20, 21, 22]:
|
||||
#for c in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]:
|
||||
#for c in [1, 2, 3, 4, 5, 6, 7, 8]:
|
||||
s = color_handling(string)
|
||||
# 6 rows instead of 7 now
|
||||
val = ' '*(6-len(s))+s
|
||||
send_packet(packet.set_targets(c, val, print_it))
|
||||
read_and_print(ser, print_it)
|
||||
|
||||
send_packet(packet.arm(c, print_it))
|
||||
read_and_print(ser, print_it)
|
||||
|
||||
|
||||
def go_all(string, print_it):
|
||||
send_packet(packet.go(0x0001, print_it))
|
||||
read_and_print(ser, print_it)
|
||||
|
||||
time.sleep(12)
|
||||
# 22 rows instead of 23 now
|
||||
for c in [1, 2, 3, 16, 17, 18, 19, 20, 21, 22]:
|
||||
#for c in [1, 2, 3, 4, 5, 6, 7, 8]:
|
||||
print('c#%d] ' % c),
|
||||
# 6 rows instead of 7 now
|
||||
for i in range(6):
|
||||
send_packet(packet.reg_read(c, packet.REG_REV_COUNT_0+i, print_it))
|
||||
res = read_and_print(ser, print_it)
|
||||
count = (res[9]<<8)+res[8]
|
||||
print('%d,' % count),
|
||||
|
||||
send_packet(packet.reg_read(c, packet.REG_ZERO_NOISE, print_it))
|
||||
res = read_and_print(ser, print_it)
|
||||
count = (res[9]<<8)+res[8]
|
||||
print('z %d, ' % count),
|
||||
print('%s,' % string)
|
||||
|
||||
def main(ser, args):
|
||||
|
||||
print_it = False
|
||||
print "Initial setup..."
|
||||
for c in [1, 2, 3, 16, 17, 18, 19, 20, 21, 22]:
|
||||
#for c in [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]:
|
||||
#for c in [1, 2, 3, 4, 5, 6, 7, 8]:
|
||||
send_packet(packet.reg_write(c, packet.REG_INDEX_ADJUST, 20))
|
||||
read_and_print(ser, print_it)
|
||||
send_packet(packet.reg_write(c, packet.REG_ROTATE_NOP, 1))
|
||||
read_and_print(ser, print_it)
|
||||
send_packet(packet.reg_write(c, packet.REG_ONE_REV_MIN, 1))
|
||||
read_and_print(ser, print_it)
|
||||
send_packet(packet.reg_write(c, packet.REG_FREQ_D, 3))
|
||||
read_and_print(ser, print_it)
|
||||
###send_packet(packet.reg_write(c, packet.REG_FREQ_N, 6))
|
||||
###read_and_print(ser, print_it)
|
||||
print "done."
|
||||
|
||||
for c in 'zyxwvutsrqponmlkjihgfedcba'[::-1]:
|
||||
print "Loop"
|
||||
# 6 rows instead of 7 now
|
||||
sval = c * 6
|
||||
print "Setup..."
|
||||
test_setup(sval, True)
|
||||
#test_setup_color(False)
|
||||
print "Setup done"
|
||||
print "Go..."
|
||||
go_all(sval, True)
|
||||
print "Go Done"
|
||||
|
||||
if __name__ == '__main__':
|
||||
tty = '/dev/ttyAMA0'
|
||||
with serial.Serial(tty, 38400) as ser:
|
||||
ser.rts = False # Setting it to high... the logic is inverted.
|
||||
main(ser, sys.argv[1:])
|
Reference in New Issue
Block a user