import serial import struct import binascii import sys import time def printf(format, *args): sys.stdout.write(format % args) #===================================================== # Open the Serial Interface com6 = serial.Serial() com6.port=5 com6.baudrate = 9600 com6.parity=serial.PARITY_NONE com6.rtscts=1 com6.timeout=None com6.stopbits=serial.STOPBITS_ONE com6.bytesize=serial.EIGHTBITS com6.open() #get the status print(com6.isOpen()) #get the settings com6.getSettingsDict() #===================================================== # Write Letters to the first line for i in range(0,16): com6.write("X") time.sleep(0.5) #===================================================== s_send_data = struct.Struct('b b b b') # enable the other elementes with a value > 0 # some of the elements can be dimmed over the value # all normal elements 0x30 for i in range(0,30): for y in range(1,12): printf("Command :: 0x1B 0x30 %d %d \n", i,y) commands=(0x1B, 0x30, i ,y) command_packed_data = s_send_data.pack(*commands) com6.write(command_packed_data) print 'Original values::', commands print 'Format string ::', s_send_data.format print 'Uses ::', s_send_data.size, 'bytes' print 'Packed Value ::', binascii.hexlify(command_packed_data) time.sleep(0.1) # check what happens with 0x31 for i in range(0,30): for y in range(1,12): printf("Command :: 0x1B 0x31 %d %d \n", i,y) commands=(0x1B, 0x31, i ,y) command_packed_data = s_send_data.pack(*commands) com6.write(command_packed_data) print 'Original values::', commands print 'Format string ::', s_send_data.format print 'Uses ::', s_send_data.size, 'bytes' print 'Packed Value ::', binascii.hexlify(command_packed_data) time.sleep(0.1) # check what happens with 0x32 for i in range(0,5): for y in range(1,12): printf("Command :: 0x1B 0x32 %d %d \n", i,y) commands=(0x1B, 0x32, i ,y) command_packed_data = s_send_data.pack(*commands) com6.write(command_packed_data) print 'Original values::', commands print 'Format string ::', s_send_data.format print 'Uses ::', s_send_data.size, 'bytes' print 'Packed Value ::', binascii.hexlify(command_packed_data) time.sleep(0.1) #===================================================== #Switch off the elements # for x in range(0,30): commands=(0x1B, 0x30, x ,0) command_packed_data = s_send_data.pack(*commands) com6.write(command_packed_data) for x in range(0,30): commands=(0x1B, 0x31, x ,0) command_packed_data = s_send_data.pack(*commands) com6.write(command_packed_data) #===================================================== #alternativ #use escaped syntax to pack the data to transmit #Switch on #command="\x1B\x30\x00\x03" #com6.write(command) #Swith off #command="\x1B\x30\x00\x00" #com6.write(command) #===================================================== #Switch to line 2 # command="\x1B\x22" com6.write(command) #Write a letter to line 2 for i in range(0,16): com6.write("W") time.sleep(0.5) #===================================================== # s_send_data = struct.Struct('b b') # #Delete the line commands=(0x1B, 0x50 ) command_packed_data = s_send_data.pack(*commands) com6.write(command_packed_data) #===================================================== #Switch back to line 1 # command="\x1B\x21" com6.write(command) #delete also commands=(0x1B, 0x50 ) command_packed_data = s_send_data.pack(*commands) com6.write(command_packed_data) #===================================================== # Time # #Set the clock 0x1B 0x00 M H T M J J #to set a real date use 2Byte BCD values command="\x1B\x00\x04\x04\x04\x04\x04\x04" com6.write(command) #show the Clock 0x1B 0x05 command="\x1B\x05" com6.write(command) #===================================================== #Close the port com6.isOpen() com6.close() exit()