import usb.core import usb.util import time import numpy import sys from erle import encode def convlen(a,1): ##숫자를 원하는 길이의 이진수로 변환하고 빈자리를 0으로 채움. b=bin(a)[2:] padding=1-len(b) b='0'*padding+b return b def bitstobytes(a): ##이진수 데이터를 바이트로 변환 bytelist=[] if len(a)%8!=0: padding=8-len(a)%8 a='0'*padding+a for i in range(len(a)//8): bytelist.append(int(a[8*i:8*(i+1)],2)) bytelist.reverse() return bytelist class dmd(): def __init__(self): ##초기화 함수, DMD 연결 확인 self.dev=usb.core.find(idVendor=0x0451 ,idProduct=0xc900) self.dev.set_configuration() self.ans=[] def command(self,mode,sequencebyte,com1,com2,data=None): buffer = [] flagstring='' if mode=='r': flagstring+='1' else: flagstring+='0' flagstring+='1000000' buffer.append(bitstobytes(flagstring)[0]) buffer.append(sequencebyte) temp=bitstobytes(convlen(len(data)+2,16)) buffer.append(temp[0]) buffer.append(temp[1]) buffer.append(com2) buffer.append(com1) if len(buffer)+len(data)<65: for i in range(len(data)): buffer.append(data[i]) for i in range(64-len(buffer)): buffer.append(0x00) self.dev.write(1,buffer) else: for i in range(64-len(buffer)): buffer.append(data[i]) self.dev.write(1,buffer) buffer = [] j=0 while j