2025基于STONE串口屏的停车管理系统热敏打印头

基于树莓派和STONE串口屏的停车管理系统热敏打印头

简要介绍

热敏打印机在我们的日常生活中非常常见,餐厅、停车场和购物中心等场所都能见到热敏打印机的应用。本文将重点探讨热敏打印机在停车系统中的应用。

所需材料
  1. STONE STWI101WT-01
  2. FTP热敏打印头
  3. Raspberry Pi Pico
  4. 投币式机器
功能

控制功能显示在串口屏幕上,主界面选择楼层,进入主界面后选择停车位,同时在右上角的文本框中显示停车位编号,然后选择停车时长(两个滚动文本选择器),随后同样在右上角的文本框中显示订单信息, 根据固定单价乘以停车时长计算总价。仅当停车位和停车时长均选定后,方可进入支付按钮,否则操作无效。进入支付界面后,将使用硬币接收器。屏幕将显示需投入的硬币数量及已投入的硬币数量。投入硬币后,将显示支付成功提示。随后可选择打印小票,在热敏纸上打印停车位编号和时间。

设计过程

最初,我计划使用树莓派Pico制作小型打印机。在选型过程中,我认为热敏打印机更易实现,确定程序后开始采购硬件。实际上,在网上采购过程中发现,市面上有许多热敏打印机配备优质驱动电路,大部分采用STMicroelectronics(ST)国产芯片,并设计有专属指令集。例如,通过其指令让打印机打印字符或换纸,但这种打印机的实用性很高,但学习价值不大。它是通过串口发送指令,即可操控打印机。因此我决定购买打印头并自行开发。关于打印头,我选择了FTP热敏打印头。

FTP 热敏打印头

parking-management-system

该打印头应可全球供应,基本原理相同。左侧为步进电机。中间为6个加热单元,每个加热单元上有64个加热点,总计384个加热点。下方为锁存器,锁存器下方为移位寄存器。最后需提供时钟信号。整个工作原理是向打印头提供时钟信号,然后在每个时钟周期发送数据。发送384个时钟信号和384个数据后,移位寄存器中的数据将存储在锁存器中。随后将锁存器设置为低电平。此时,384个加热点将根据每个数据的值(0或1)选择加热或不加热。同时,让步进电机旋转以驱动热敏纸打印出预设字符。

在获得热敏打印头后,我索要了数据手册,发现其采用30针FPC电缆。显然,直接连接到Pico并不方便。因此我决定设计一个背板电路。

我有一个STONE串行显示屏,电源为12V。查看热敏打印头的打印电压参考值为7.6V,最大值为8V,因此需提供约7.6V的电压。此外,其逻辑电压为3.3V, 而树莓派Pico最大支持5V电源,且自带3.3V输出电压。因此电源设计可采用两个DC-DC转换器:一个12V电源,其中一个DC-DC转换器输出7.6V供热敏打印头使用,另一个输出5V供Pico使用,再从Pico的3.3V输出为热敏打印头的逻辑电压供电。然后12V直接连接到串口屏幕。

顺便说一下,热敏打印头的步进电机也需要驱动。我有一个集成的达林顿管集成器。但它太大了,而且是直接插头的,所以还是买一个驱动芯片吧。这样电机驱动部分也搞定了。

打印需要设计字体,基本上大家都使用SPF闪存存储字体,这是一个巨大的项目。仅ASCII码就超过100个,因此需要购买另一个SPF闪存。然后整个规划大致如下。

设计电路

随后开始设计电路。首先选择电源,最初我使用了三端电压调节器,因为电路简单,但调试时发热问题严重,触摸时非常烫手,因此改用DC-DC转换器。直接按照芯片数据手册绘制电路图。这里我选择了MT2492,但忽略了一个重要参数——打印头工作电流。该芯片的最大输出电流为2A,而打印头工作电流为2.3A,相差0.3A。虽然可以使用,但效率不会太高,具体效果后续再讨论。

parking-management-system

然后我购买的电机驱动芯片是LV8548,请参考打印头数据手册,其中包含步进电机驱动时序图。根据该时序图,需要为其提供一个四路PWM信号。

parking-management-system

.然后是闪存芯片,型号为BY25Q32BS,容量为32Mbit,容量相当大,已连接至Pico,等待Pico调用。

parking-management-system

整体电路图如下所示:
左上角为通信接口和电源接口,下方为蜂鸣器(实际电路中未使用),右侧为发光二极管,右下角为连接打印头的30针FPC接口。

parking-management-systemparking-management-system

树莓派 Pico

parking-management-system

parking-management-system

parking-management-system

parking-management-system

然后连接打印头、串口屏和Pico,测量逻辑电压约为3.3V,确认无问题后即可编写程序。

程序

我计划首先调整步进电机,这一部分调整较为简单,请参考数据手册中的时序图,8个时钟周期内,每个时钟周期需分别向电机四个引脚发送逻辑信号,8个周期后电机开始旋转,随后调整速度,但在过程中, 我们需要添加延迟来调整占空比,否则电机转速过快。我设置的延迟时间约为5毫秒,转动后必须将电平拉低,否则电机看似停止但内部线圈仍通电,长时间后可能闻到烧焦味。

然后编写函数,将主体代码放入循环中,循环次数代表电机旋转的持续时间。函数代码稍长,建议单独放置并等待调用。

打开电源,首先不要连接到Pico和打印头,测量DC-DC的输出电压,正常情况下一个约为7.5V,另一个约为5V

parking-management-system

parking-management-system

这是经过几次修改后的功能,速度和持续时间将在主程序中传输。目前仍需大量优化。
接下来是调整打印头的位置,这一部分对我来说比较困难,需要一个时钟信号,数据手册中写的是最大8M,我原本以为需要一个约8M频率的信号,但实际操作中存在困难。首先我通过IO翻转电平测量了频率,但差异过大。
接着我想使用一个引脚,研究了一整天但效果不佳,我的个人技能有限,可能需要深入手动研究rp2040芯片。
然后将电平翻转384个周期进行尝试,工作流程如下:初始化数据输入1个引脚,锁存1个引脚,时钟信号1个引脚, 6个打印单元引脚,然后除了锁存所有其他引脚外,将所有其他引脚拉低,然后在1个时钟周期内发送一个数据,循环384次后将锁存设置为0,将6个打印单元设置为1,然后哪个点有数据哪个点就会被加热。设置完成后,将电平拉回。
程序编写完成并开始测试后,实际运行并不正常,原因是控制的打印单元过多导致电流不足。随后将两个打印单元的电平降低,重新测试。

parking-management-system

parking-management-system

通过水平和垂直线,然后得到一条对角线,注意一个打印单元包含64个点,这定义了一个长度,例如32,然后循环32次,每次384个周期,每个周期仅将前64个数据设置为1,并将接下来的320个数据设置为0,然后循环32次,每次仅在第一个单位打印一个点,然后循环增量,结合步进电机的速度进行调整,最终调整出64×32大小的对角线,你也可以先拼出一个字母Z。

然后程序的框架就出来了,如果你想打印某个单词,首先需要设置字体。首先输入大写字母A,尺寸为32×32,并准备一个定义列表。我计划在此使用pin.value()函数实现,因此需先创建字体,然后使用32行32列的二进制值作为调用参数,提取后进行位移操作,最后传递给pin.value()函数,这就是实现过程。。

parking-management-system

With 0 as the background and 1 as the foreground, the actual implementation process then looks like this.

parking-management-system

这种点阵字体依然很常见,网上有工具可以直接实现。具体操作是:在字符前面加上“0b”,然后在后面添加一个逗号,之后就可以根据自己的创意进行调整。这种字体最初是设计用来存储在闪存芯片中的,但我调整了很长时间,仍然无法打开。

我不知道问题出在哪里,等我有时间了再调整一下。好消息是,Pico本身配备了16Mbit的闪存,存储一个ASCII库绰绰有余,这样我就不用担心存储空间了。

parking-management-system

parking-management-system

parking-management-system

Define it with a dictionary, put it in a separate piece, and call it back in the main program. Then after debugging, the available version looks like this.
from machine import Pin
from time import sleep
import _thread
import rp2
from array import array
import ascii_ku
import speed_motor
#import sys
delaytime = 0.0000001 # Printer clock delay
motor = speed_motor.motor_control(2, 3, 4, 5) # Initialize the printer's internal stepper motor pins, corresponding to the a+/a-/b+/b- of the stepper motor
mov_bit = 0
PRINTER_DIN = Pin(20, Pin.OUT)
PRINTER_CLK = Pin(19, Pin.OUT)
PRINTER_LAT = Pin(18, Pin.OUT, Pin.PULL_UP)
STB1 = Pin(6, Pin.OUT, Pin.PULL_DOWN)
STB2 = Pin(7, Pin.OUT, Pin.PULL_DOWN)
STB3 = Pin(8, Pin.OUT, Pin.PULL_DOWN)
STB4 = Pin(9, Pin.OUT, Pin.PULL_DOWN)
STB5 = Pin(14, Pin.OUT, Pin.PULL_DOWN)
STB6 = Pin(15, Pin.OUT, Pin.PULL_DOWN)
lock = _thread.allocate_lock()
ascii_code = ascii_ku.ascii_code() # Importing an ascii character library
shuru = input("Please enter text:")
line_word = []
for item in range(len(shuru)):
line_word.append(shuru[item])
# line_num = len(shuru)
# bottom_line_num = len(shuru)%
# global motor_speed = 0
# global line = 0
# if len(shuru) > 12:
#     motor_speed = len(shuru) % 6
#     if (len(shuru) % 6) == 0:
#         motor_speed = 12
# else:
#     motor_speed = len(shuru)
# print(motor_speed)
motor_speed = len(shuru)
line = (len(shuru) // 12) + 1
if (len(shuru) % 12) == 0:
line -= 1
lins = 0
supper = 0
slower = 0
# _thread.start_new_thread(motor.run_stop, (0.005*motor_speed, 26*line))
_thread.start_new_thread(motor.run_stop, (motor_speed, 1))
# _thread.start_new_thread(motor.run_stop, (0.03, 56))
def last_word_size32 (word_line, linss, lins, supper, slower):
for mov_bit in range((supper*32)+(slower*24)):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(31, -1, -1):
word_bit = (word_line[linss] >> mov_bit)&0b00000000000000000000000000000001
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(word_bit)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(352-((supper*32)+(slower*24))):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
if (supper*32)+(slower*24) < 192:
PRINTER_LAT.value(0)
STB1.value(1)
STB2.value(1)
STB3.value(1)
sleep(0.005)
STB1.value(0)
STB2.value(0)
STB3.value(0)
PRINTER_LAT.value(1)
else:
PRINTER_LAT.value(0)
STB4.value(1)
STB5.value(1)
STB6.value(1)
sleep(0.005)
STB4.value(0)
STB5.value(0)
STB6.value(0)
PRINTER_LAT.value(1)
def word_size24 (word_line, linss, lins, supper, slower):
for mov_bit in range((supper*32)+(slower*24)):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(23, -1, -1):
word_bit = (word_line[linss] >> mov_bit)&0b000000000000000000000001
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(word_bit)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(360-((supper*32)+(slower*24))):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
if (supper*32)+(slower*24) < 192:
PRINTER_LAT.value(0)
STB1.value(1)
STB2.value(1)
STB3.value(1)
sleep(0.005)
STB1.value(0)
STB2.value(0)
STB3.value(0)
PRINTER_LAT.value(1)
else:
PRINTER_LAT.value(0)
STB4.value(1)
STB5.value(1)
STB6.value(1)
sleep(0.005)
STB4.value(0)
STB5.value(0)
STB6.value(0)
PRINTER_LAT.value(1)
for linss in range(32):
supper=slower=0
if linss < 32:
for lins in range(len(line_word)):
#             if lins//12:
#                 break
if (line_word[lins].isupper() or line_word[lins].isdigit() or line_word[lins].isspace()):
last_word_size32 (ascii_code.code.get(line_word[lins]), linss%32, lins%12, supper, slower)
supper += 1
elif (line_word[lins].islower()):
word_size24 (ascii_code.code.get(line_word[lins]), linss%32, lins%12, supper, slower)
slower += 1
else:
if linss == 32:
sleep(5.8)
for lins in range(motor_speed):
if (line_word[lins].isupper()):
last_word_size32 (ascii_code.code.get(line_word[12]), linss%32, lins%12, len(line_word))
#     elif:
#         _thread.start_new_thread(motor.run_stop, (motor_speed, line))
#     for linss in range(32):
#         for lins in range(len(line_word)):
#             if (line_word[lins].isupper()):
#                 last_word_size32 (ascii_code.code.get(line_word[lins]), linss, lins, len(line_word))
line_word.clear()

I am a separate control printing unit, because the current is not enough so like this, but in order to print clear, making my printing speed becomes particularly slow, the more words the slower, and then the lowercase letters are 24 * 32 dot matrix, that it is fewer print points to use, but can not give it to leave 32 heating points of space then the character spacing is large, so the capital letters and lowercase letters are separated, the numbers are still 32 * 32. Then print can achieve the basic functions, but there are two auxiliary functions that have not been done, one is the lack of paper detection and overheating protection, the circuit part has been done, the program I still have no time to do it.
Temporarily first manual attention to renew the paper and do not let the heating head heating it for a long time.
The next step is to do the coin acceptor, and I found that the circuit forgot to leave a wiring port for the coin acceptor, so I’ll connect the wires from the back of the board.
Fortunately, only one signal line to be used for the coin acceptor, and then look at my pico, there is a GP28 available on the right side, but, after connecting, the signal can not be measured, so I changed to use the GP22, the same program I do not understand why the GP28 can not be used.

parking-management-system(20)

Finally, the whole program is attached.
from machine import UART,Pin
from time import sleep
import _thread
import rp2
from array import array
import ascii_ku
import speed_motor
from os import uname
#import sys
uart1 = UART(0, baudrate = 115200, tx =Pin(0), rx = Pin(1))
floor1 = ['f', 'l', 'o', 'o', 'r','1']
floor2 = ['f', 'l', 'o', 'o', 'r','2']
floor3 = ['f', 'l', 'o', 'o', 'r','3']
button_cmd = [16,1]
selector_cmd = [16,129]
print(uname()[0])
delaytime = 0.0000001 # Printer clock delay
coin = Pin(22, Pin.IN,Pin.PULL_UP)
coin_num = 0
motor = speed_motor.motor_control(2, 3, 4, 5) # Initialize the printer's internal stepper motor pins, corresponding to the a+/a-/b+/b- of the stepper motor
mov_bit = 0
PRINTER_DIN = Pin(20, Pin.OUT)
PRINTER_CLK = Pin(19, Pin.OUT)
PRINTER_LAT = Pin(18, Pin.OUT, Pin.PULL_UP)
STB1 = Pin(6, Pin.OUT, Pin.PULL_DOWN)
STB2 = Pin(7, Pin.OUT, Pin.PULL_DOWN)
STB3 = Pin(8, Pin.OUT, Pin.PULL_DOWN)
STB4 = Pin(9, Pin.OUT, Pin.PULL_DOWN)
STB5 = Pin(14, Pin.OUT, Pin.PULL_DOWN)
STB6 = Pin(15, Pin.OUT, Pin.PULL_DOWN)
lock = _thread.allocate_lock()
ascii_code = ascii_ku.ascii_code() # Importing an ascii character library
# shuru = 'aa'
# line_word = []
# for item in range(len(shuru)):
#     line_word.append(shuru[item])
# line_num = len(shuru)
# bottom_line_num = len(shuru)%
# global motor_speed = 0
# global line = 0
# if len(shuru) > 6:
#     motor_speed = len(shuru) % 6
#     if (len(shuru) % 6) == 0:
#         motor_speed = 12
# else:
#     motor_speed = len(shuru)
# # print(motor_speed)
#
# line = (len(shuru) // 12) + 1
# if (len(shuru) % 12) == 0:
#     line -= 1
lins = 0
supper = 0
slower = 0
danjia = 0
# _thread.start_new_thread(motor.run_stop, (0.005*motor_speed, 26*line))
# _thread.start_new_thread(motor.run_stop, (motor_speed, line))
# _thread.start_new_thread(motor.run_stop, (0.03, 56))
def pay(pay):
global coin_num
line_word = {'line_word1':['s','i','t','e',':','F','1','-','0'],'line_word2':['0','d','a','y','2','h','o','u','r'],'line_word3':['t','o','t','a','l',':','4','.','0'],'line_word4':['T','o','t','a','l',':','4','.','0']}
line_wors = {'line_word1':['U','n','i','t',':','2','.','0','0'],'line_word2':['T','o','t','a','l',':','4','.','0'],
'line_word3':['U','n','i','t',':','2','.','0','0'],'line_word4':['T','o','t','a','l',':','5','.','0']}
#     line_word1 = ['S','i','t','e',':','F','1','-','0']
#     line_word2 = ['1','D','a','y','1','H','o','u','r']
#     line_word3 = ['U','n','i','t',':','2','.','0','0']
#     line_word4 = ['T','o','t','a','l',':','5','.','0']
#     line_word1[8]=str(pay[0])
#     line_word2[0]=str(pay[1])
#     line_word2[4]=str(pay[2])
#     line_word4[6]=str(pay[3])
(line_word['line_word1'])[8]=str(pay[0])
#     (line_word['line_word2'])[0]=str(pay[1])
#     (line_word['line_word2'])[4]=str(pay[2])
#     (line_word['line_word4'])[6]=str(pay[3])
sleep(1)
uart1.write('ST<{"cmd_code":"set_value","type":"image_value","widget":"image_value4","value":'+str(pay[3])+'}>ET')
#     sleep(2)
#     print(line_word.get('line_word'+str(1))[0])
#     print('zfdszfz',line_word)
#     sleep(2)
#     uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message5","text":"F1 - '+pay[0]+'"}>ET')
#     uart1.sendbreak()
#     sleep(1)
#     uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message6","text":"'+str(pay[1])+'"}>ET')
#     uart1.sendbreak()
#     sleep(1)
# #     uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message22","text":"'+str(pay[2])+'"}>ET')
#     uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message8","text":"'+str(pay[3])+'"}>ET')
while True:
if coin.value()==0:
coin_num += 1
print("Number of coins deposited:",coin_num)
sleep(0.1)
uart1.write('ST<{"cmd_code":"set_value","type":"image_value","widget":"image_value2","value":'+str(coin_num)+'}>ET')
if coin_num == pay[3]:
uart1.write('ST<{"cmd_code":"set_visible","type":"widget","widget":"image37","visible":true}>ET')
if uart1.any()>1:
rx2 = []
data_name2 = ''
bin_data = uart1.read(40)
uart1.sendbreak()
rx1 = list(bin_data)
for item in rx1:
rx2.append(chr(item))
print(rx2)
if rx1[3:5:1] == button_cmd:
data_name_len = rx1[6] - 1
data_name = rx2[7:data_name_len+6:1]
data_name2 = ''.join(data_name)
print(data_name2)
if data_name2 == 'back':
break
elif data_name2 == 'print' and coin_num == pay[3] and rx1[13] == 2:
data_name2=''
_thread.start_new_thread(motor.run_stop, (9, 4))
for iii in range(1,3):
for linss in range(32):
supper=slower=0
for lins in range(9):
#                                 temp_list=ascii_code.code.get(('line_word'+str(iii))[lins])
#                                 print(temp_list,type(temp_list))
if (line_word.get('line_word'+str(iii))[lins]).islower():
word_size24 (ascii_code.code.get(line_word.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
slower += 1
else:
last_word_size32 (ascii_code.code.get(line_word.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
supper += 1
sleep(6)
#                     for iii in range(1,2):
#                         for linss in range(32):
#                             supper=slower=0
#                             for lins in range(9):
# #                                 temp_list=ascii_code.code.get(('line_word'+str(iii))[lins])
# #                                 print(temp_list,type(temp_list))
#                                 if (line_wors.get('line_word'+str(iii))[lins]).islower():
#                                     word_size24 (ascii_code.code.get(line_wors.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
#                                     slower += 1
#                                 else:
#                                     last_word_size32 (ascii_code.code.get(line_wors.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
#                                     supper += 1
#                     sleep(6)
#                     for iii in range(1,2):
#                         for linss in range(32):
#                             supper=slower=0
#                             for lins in range(9):
# #                                 temp_list=ascii_code.code.get(('line_word'+str(iii))[lins])
# #                                 print(temp_list,type(temp_list))
#                                 if (line_wors.get('line_word'+str(iii))[lins]).islower():
#                                     word_size24 (ascii_code.code.get(line_wors.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
#                                     slower += 1
#                                 else:
#                                     last_word_size32 (ascii_code.code.get(line_wors.get('line_word'+str(iii))[lins]), linss%32, lins%12, supper, slower)
#                                     supper += 1
def floor1def():
day_jia = 0
hour_jia = 0
day_flag = False
hour_flag = False
price_flag = False
posltion = False
zongjia = 0
pay1 = [0,0,0,0]
print("floor1 now")
#     uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message3","text":"2.00$/H"}>ET')
uart1.sendbreak()
while True:
if uart1.any()>1:
rx2 = []
data_name2 = ''
bin_data = uart1.read(40)
uart1.sendbreak()
rx1 = list(bin_data)
for item in rx1:
rx2.append(chr(item))
print(rx2)
if rx1[3:5:1] == button_cmd:
data_name_len = rx1[6] - 1
data_name = rx2[7:data_name_len+6:1]
data_name2 = ''.join(data_name)
print(data_name2)
if data_name2 == 'back':
break
elif data_name2 == 'position':
posltion = True
pay1[0]=rx2[15]
write1(rx2[15])
elif data_name2 == 'pay' and posltion and price_flag:
uart1.write('ST<{"cmd_code":"open_win","type":"window","widget":"window7"}>ET')
pay(pay1)
#                 if data_name2 == 'pay' and posltion = True and (day_flag or hour_flag):
#                     posltion = True
#                     uart1.write('ST<{"cmd_code":"open_win","type":"window","widget":"window7"}>ET')
if rx1[3:5:1] == selector_cmd:
data_name_len = rx1[6] - 4
data_name = rx2[7:data_name_len+7:1]
data_name2 = ''.join(data_name)
print(data_name2)
if data_name2 == 'time_day1':
pay1[1]=rx2[19]
write2(ord(rx2[19]))
day_jia = ord(rx2[19])
day_flag = True
elif data_name2 == 'time_hour1':
pay1[2]=rx2[20]
write3(ord(rx2[20]))
hour_jia = ord(rx2[20])
hour_flag = True
if hour_flag or day_flag:
price_flag = True
zongjia = (day_jia*48) + (hour_jia*2)
pay1[3]=zongjia
print(str(zongjia))
uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message4","text":"'+str(zongjia)+'"}>ET')
hour_flag = day_flag = False
def floor2def():
pass
def floor3def():
pass
def write1(num):
#print(ss)
for item in range(49,55):
uart1.write('ST<{"cmd_code":"set_image","type":"image","widget":"image1_'+chr(item)+'","image":"nocar_bg"}>ET')
uart1.write('ST<{"cmd_code":"set_image","type":"image","widget":"image1_'+num+'","image":"selectedcar_bg2"}>ET')
uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message1","text":"F1 - '+num+'"}>ET')
def write2(num):
#     danjia = 1
uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message2","text":"'+str(num)+'"}>ET')
#     if danjia == 1:
#         uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message3","text":"2.00$/H"}>ET')
def write3(num):
#     danjia = 1
uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message22","text":"'+str(num)+'"}>ET')
#     if danjia == 1:
#         uart1.write('ST<{"cmd_code":"set_text","type":"edit","widget":"message3","text":"2.00$/H"}>ET')
def last_word_size32 (word_line, linss, lins, supper, slower):
for mov_bit in range((supper*32)+(slower*24)):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(31, -1, -1):
word_bit = (word_line[linss] >> mov_bit)&0b00000000000000000000000000000001
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(word_bit)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(352-((supper*32)+(slower*24))):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
if (supper*32)+(slower*24) < 192:
PRINTER_LAT.value(0)
STB1.value(1)
STB2.value(1)
STB3.value(1)
STB4.value(1)
sleep(0.005)
STB1.value(0)
STB2.value(0)
STB3.value(0)
STB4.value(0)
PRINTER_LAT.value(1)
else:
PRINTER_LAT.value(0)
STB4.value(1)
STB5.value(1)
STB6.value(1)
sleep(0.005)
STB4.value(0)
STB5.value(0)
STB6.value(0)
PRINTER_LAT.value(1)
#         PRINTER_LAT.value(0)
#         STB1.value(1)
#         STB2.value(1)
#         STB3.value(1)
#         STB4.value(1)
#         STB5.value(1)
#         STB6.value(1)
#         sleep(0.005)
#         STB1.value(0)
#         STB2.value(0)
#         STB3.value(0)
#         STB4.value(0)
#         STB5.value(0)
#         STB6.value(0)
#         PRINTER_LAT.value(1)
def word_size24 (word_line, linss, lins, supper, slower):
for mov_bit in range((supper*32)+(slower*24)):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(23, -1, -1):
word_bit = (word_line[linss] >> mov_bit)&0b000000000000000000000001
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(word_bit)
PRINTER_CLK.value(1)
sleep(delaytime)
for mov_bit in range(360-((supper*32)+(slower*24))):
PRINTER_CLK.value(0)
sleep(delaytime)
PRINTER_DIN.value(0)
PRINTER_CLK.value(1)
sleep(delaytime)
if (supper*32)+(slower*24) < 192:
PRINTER_LAT.value(0)
STB1.value(1)
STB2.value(1)
STB3.value(1)
sleep(0.005)
STB1.value(0)
STB2.value(0)
STB3.value(0)
PRINTER_LAT.value(1)
else:
PRINTER_LAT.value(0)
STB4.value(1)
STB5.value(1)
STB6.value(1)
sleep(0.005)
STB4.value(0)
STB5.value(0)
STB6.value(0)
PRINTER_LAT.value(1)
#         PRINTER_LAT.value(0)
#         STB1.value(1)
#         STB2.value(1)
#         STB3.value(1)
#         STB4.value(1)
#         STB5.value(1)
#         STB6.value(1)
#         sleep(0.005)
#         STB1.value(0)
#         STB2.value(0)
#         STB3.value(0)
#         STB4.value(0)
#         STB5.value(0)
#         STB6.value(0)
#         PRINTER_LAT.value(1)
while True:
if uart1.any()>1:
rx2 = []
data_name2 = ''
bin_data = uart1.read(40)
uart1.sendbreak()
rx1 = list(bin_data)
for item in rx1:
rx2.append(chr(item))
print(rx2)
if rx2[7:13:1] == floor1:
floor1def()
elif rx2[7:13:1] == floor2:
floor2def()
elif rx2[7:13:1] == floor3:
floor3def()
for linss in range(32):
supper=slower=0
if linss < 32:
for lins in range(len(line_word)):
#             if lins//12:
#                 break
if (line_word[lins].isupper() or line_word[lins].isdigit() or line_word[lins].isspace()):
last_word_size32 (ascii_code.code.get(line_word[lins]), linss%32, lins%12, supper, slower)
supper += 1
elif (line_word[lins].islower()):
word_size24 (ascii_code.code.get(line_word[lins]), linss%32, lins%12, supper, slower)
slower += 1
else:
if linss == 32:
sleep(5.8)
for lins in range(motor_speed):
if (line_word[lins].isupper()):
last_word_size32 (ascii_code.code.get(line_word[12]), linss%32, lins%12, len(line_word))
#     elif:
#         _thread.start_new_thread(motor.run_stop, (motor_speed, line))
#     for linss in range(32):
#         for lins in range(len(line_word)):
#             if (line_word[lins].isupper()):
#                 last_word_size32 (ascii_code.code.get(line_word[lins]), linss, lins, len(line_word))
line_word.clear()

滚动至顶部