循环修改时钟小工具-dlms协议

#!/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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值