No.724
Python で Open DMX USB を動かすことに成功しました。
setbreakon と setbreakoff の挙動は予想の通りでした。
以下がテストソースです。
slot1 と slot512 を 0 から255 までカウントして終了します。
### Open DMX USB test ###
import ftd2xx as ftd
import time
if __name__ == '__main__' :
baudrate = 250000
word_length = 8
stop_bit = 2
parity = 0
purge_tx = 2
try :
d = ftd.open( 0 ) # Open first FTDI device
d.setBaudRate( baudrate )
d.setDataCharacteristics( word_length, stop_bit, parity )
d.purge( purge_tx )
channelVals = bytearray( [ 0 ] * 513 )
channelVals[ 0 ] = 0 # start code
for i in range( 256 ) :
try :
channelVals[ 1 ] = i
channelVals[ 512 ] = i
channelbytes = bytes( channelVals )
# Send Slot
cstart = time.perf_counter_ns( )
d.write( channelbytes )
while time.perf_counter_ns( ) - cstart < 22800000 :
pass
# Break Time
d.setBreakOn( )
cstart = time.perf_counter_ns( )
while time.perf_counter_ns( ) - cstart < 192000 :
pass
# Mark After Break
d.setBreakOff( )
cstart = time.perf_counter_ns( )
while time.perf_counter_ns( ) - cstart < 12000 :
pass
# Press Ctl+C to Exit
except KeyboardInterrupt :
break
d.close( )
except :
print( 'No Device' )
time.sleep() は求める精度に足りないので time.perf_counter_ns() を用いています。
0 から 255 のカウントが5.9秒強で終わるので 43fps くらい。ほぼ規格最大値です。
本当にコレでいいのかわからんけど、モヤモヤしてたのがスッキリした。
#Python #器具の製作
setbreakon と setbreakoff の挙動は予想の通りでした。
以下がテストソースです。
slot1 と slot512 を 0 から255 までカウントして終了します。
### Open DMX USB test ###
import ftd2xx as ftd
import time
if __name__ == '__main__' :
baudrate = 250000
word_length = 8
stop_bit = 2
parity = 0
purge_tx = 2
try :
d = ftd.open( 0 ) # Open first FTDI device
d.setBaudRate( baudrate )
d.setDataCharacteristics( word_length, stop_bit, parity )
d.purge( purge_tx )
channelVals = bytearray( [ 0 ] * 513 )
channelVals[ 0 ] = 0 # start code
for i in range( 256 ) :
try :
channelVals[ 1 ] = i
channelVals[ 512 ] = i
channelbytes = bytes( channelVals )
# Send Slot
cstart = time.perf_counter_ns( )
d.write( channelbytes )
while time.perf_counter_ns( ) - cstart < 22800000 :
pass
# Break Time
d.setBreakOn( )
cstart = time.perf_counter_ns( )
while time.perf_counter_ns( ) - cstart < 192000 :
pass
# Mark After Break
d.setBreakOff( )
cstart = time.perf_counter_ns( )
while time.perf_counter_ns( ) - cstart < 12000 :
pass
# Press Ctl+C to Exit
except KeyboardInterrupt :
break
d.close( )
except :
print( 'No Device' )
time.sleep() は求める精度に足りないので time.perf_counter_ns() を用いています。
0 から 255 のカウントが5.9秒強で終わるので 43fps くらい。ほぼ規格最大値です。
本当にコレでいいのかわからんけど、モヤモヤしてたのがスッキリした。
#Python #器具の製作