#!/usr/bin/env python
-- coding: utf-8 --
@Time : 2024/01/18 16:12
@Author : Piu
@Version : python3.8
@File : testtimeloop0118.py
@Software : PyCharm
import binascii
import datetime
import re
import time
import serial
from PyQt5.QtCore import QThread
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QPushButton, QVBoxLayout, QHBoxLayout, QStackedWidget,
QLabel, QComboBox, QLineEdit, QLCDNumber
from PyQt5.QtSerialPort import QSerialPortInfo
from dateutil.relativedelta import relativedelta
import iconfile
import crc16Check
get now time to hex string
%w表示时,1-6表示周一到周六,0表示周日
print(date.strftime(“%w”))
isoweekday()基于ISO 9601标准的星期几,其中星期一到星期七为1~7
def now_time_tohex_string_isoweekday(nowtimestring):
numweek = nowtimestring.isoweekday()
now_time_pattern = nowtimestring.strftime(‘%Y-%m-%d-%w-%H-%M-%S’)
now_time_pattern_list = now_time_pattern.split(‘-’)
# year to hex
# 年高字节中无空格
now_time_pattern_list[0] = (
“%02X%02X” % (int(now_time_pattern_list[0]) // 256, int(now_time_pattern_list[0]) % 256))
# month,day,hour,minute,second to hex
for index in range(1, len(now_time_pattern_list)):
now_time_pattern_list[index] = (“%02X” % (int(now_time_pattern_list[index]) % 256))
numweektohex = (“%02X” % (int(numweek) % 256))
now_time_pattern_list[3] = numweektohex
timestringhex = ‘’
# year,month,day,
for timestr in now_time_pattern_list:
# 每个字符中不添加空格
timestringhex += timestr
timestringhex = timestringhex.rstrip()
return timestringhex
get now time to hex string
%w表示时,1-6表示周一到周六,0表示周日
print(date.strftime(“%w”))
weekday()其中星期一到星期七为0~6
def now_time_tohex_string_weekday(nowtimestring):
numweek = nowtimestring.weekday()
now_time_pattern = nowtimestring.strftime(‘%Y-%m-%d-%w-%H-%M-%S’)
now_time_pattern_list = now_time_pattern.split(‘-’)
# year to hex
# 年高字节中无空格
now_time_pattern_list[0] = (
“%02X%02X” % (int(now_time_pattern_list[0]) // 256, int(now_time_pattern_list[0]) % 256))
# month,day,hour,minute,second to hex
for index in range(1, len(now_time_pattern_list)):
now_time_pattern_list[index] = (“%02X” % (int(now_time_pattern_list[index]) % 256))
numweektohex = (“%02X” % (int(numweek) % 256))
now_time_pattern_list[3] = numweektohex
timestringhex = ‘’
# year,month,day,
for timestr in now_time_pattern_list:
# 每个字符中不添加空格
timestringhex += timestr
timestringhex = timestringhex.rstrip()
return timestringhex
get now time to hex string
%w表示时,1-6表示周一到周六,0表示周日
print(date.strftime(“%w”))
def now_time_tohex_string(nowtimestring):
now_time_pattern = nowtimestring.strftime(‘%Y-%m-%d-%H-%M-%S’)
now_time_pattern_list = now_time_pattern.split(‘-’)
# year to hex
# 年高字节中无空格-XXXX年转为16进制表示,eg:2022转十六进制07e6
# now_time_pattern_list[0] = (“%02X%02X” % (int(now_time_pattern_list[0][2:]) // 256,
# int(now_time_pattern_list[0]) % 256))
# year to hex
# 年高字节中无空格-XXXX年取后两字节转为16进制表示,eg:2022,取22转十六进制16
now_time_pattern_list[0] = (“%02X” % (int(now_time_pattern_list[0][2:]) % 256))
# month,day,hour,minute,second to hex
for index in range(1, len(now_time_pattern_list)):
now_time_pattern_list[index] = (“%02X” % (int(now_time_pattern_list[index]) % 256))
timestringhex = ‘’
# year,month,day,
for timestr in now_time_pattern_list:
# 每个字符中不添加空格
timestringhex += timestr
timestringhex = timestringhex.rstrip()
return timestringhex
Adds a space every two characters to a given string
def string_add_space(strcmd):
pattern = re.compile(‘.{2}’)
return ’ '.join(pattern.findall(strcmd)).upper()
对串口的参数进行配置 - loadprofile
def port_open_recv_lp(self):
ser.port = self.combo_box.currentText()
ser.baudrate = int(self.combo_box_baudrate.currentText())
ser.bytesize = 8
ser.stopbits = 1
# 奇偶校验位
ser.parity = “N”
ser.open()
# isOpen()函数来查看串口的开闭状态
if (ser.isOpen()):
# print

最低0.47元/天 解锁文章
7894

被折叠的 条评论
为什么被折叠?



