3、监测数据采集物联网应用开发步骤(3)

源码将于最后一遍文章给出下载

  1. 监测数据采集物联网应用开发步骤(2)

系统整体结构搭建

新建项目

输入项目名称:MonitorData

所谓兵马未动粮草先行,按下图创建好对应的模块备用:

com.plugins 业务插件模块

com.zxy.adminlog 日志或文本文件读写模块

com.zxy.autoUpdate 程序版本自动更新模块

com.zxy.business 通用业务处理模块

com.zxy.common 通用函数模块

com.zxy.comport 串口通讯模块

com.zxy.db_Self 静态接口配置库(Sqlit3)模块

com.zxy.db1 静态接口配置库(Sqlit3)模块

com.zxy.db2 业务数据库(Sqlite3)模块

com.zxy.interfaceReflect 通用插件管理模块

com.zxy.main 全局变量初始化模块

com.zxy.taskhandler 定时器任务模块

com.zxy.tcp tcp协议模块

编写主程序代码MonitorDataCmd.py,打印启动时间,sleep 5秒,然后打印结束时间

python 复制代码
#! python3
# -*- coding: utf-8 -
'''
Created on 2023年08月28日
@author: zxyong 13738196011
'''

import time
from com.zxy.common.Com_Fun import Com_Fun

#监测数据采集物联网应用-主程序
class MonitorDataCmd(object):

    def __init__(self, params):
        pass
    
    if __name__ == '__main__':
        print("监测数据采集物联网应用软件开始:"+Com_Fun.GetTimeDef())
        time.sleep(5)
        print("监测数据采集物联网应用软件结束:"+Com_Fun.GetTimeDef())

新建通用函数代码com.zxy.common.Com_Fun.py

python 复制代码
#! python3
# -*- coding: utf-8 -
'''
Created on 2023年08月28日
@author: zxyong 13738196011
'''

import datetime,uuid,time
from datetime import timedelta

#监测数据采集物联网应用--通用函数
class Com_Fun():
        
    def __init__(self):
        pass
    
    @staticmethod
    def NoNull(objTag):
        if objTag is None:
            return ""
        else:
            return str(objTag)
    
    @staticmethod
    def FloatNull(objTag):
        if objTag is None or objTag == "" or objTag == "-":
            return 0
        else:
            return float(objTag)
        
    @staticmethod
    def ZeroNull(objTag):
        if objTag is None or objTag == "":
            return 0
        else:
            return int(objTag)
        
    @staticmethod
    def GetLong(inputTimeFormat,inputTime):
        if len(inputTime) > 19:
            inputTime = inputTime[0:19]
        time1=datetime.datetime.strptime(inputTime.replace("T"," "),inputTimeFormat)
        return time.mktime(time1.timetuple())

    #获得当前时间戳
    @staticmethod
    def getTimeLong():
        temT = datetime.datetime.now()
        timeStamp = time.mktime(temT.timetuple())
        return timeStamp

    #日期信息格式化timeFormat : '%Y-%m-%d %H:%M:%S'
    @staticmethod
    def GetTime(inputTimeFormat):
        return datetime.datetime.now().strftime(inputTimeFormat)
    
    #日期信息格式化秒数据10整数化
    @staticmethod
    def GetTimeNum(inputTime):
        temTime = datetime.datetime.strptime(inputTime.replace("T", " "),"%Y-%m-%d %H:%M:%S")
        temSB = temTime.strftime("%Y-%m-%d %H:%M")
        temSE = temTime.strftime("%S")
        temSec = int(int(temSE) / 10)
        return temSB+":"+str(temSec)+"0"
        
    #日期信息格式化timeFormat : '%Y-%m-%d %H:%M:%S'
    @staticmethod
    def GetTimeDef():
        return str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
    
    #日期信息格式化timeFormat : '%Y-%m-%d %H:%M:%S' 字符串
    @staticmethod
    def GetTimeInput(inputTimeFormat,inputTime):
        if inputTime is None or inputTime == "":
            return "1900-01-01 00:00:00"
        time1=datetime.datetime.strptime(inputTime.replace("T", " "),inputTimeFormat)
        return time1
    
    #日期信息格式化timeFormat : '%Y-%m-%d %H:%M:%S' 字符串
    @staticmethod
    def GetStrTimeInput(inputTimeFormat,inputTime):
        if inputTime is None or inputTime == "":
            return "1900-01-01 00:00:00"
        time1=datetime.datetime.strptime(inputTime.replace("T", " "),inputTimeFormat)
        return str(time1)
        
    #返回time格式
    @staticmethod
    def GetToTimeInput(inputTimeFormat,inputTime):
        if inputTime is None or inputTime == "":
            return "1900-01-01 00:00:00"
        elif len(inputTime) <= 19:
            return datetime.datetime.strptime(inputTime.replace("T"," "),inputTimeFormat)
        else:
            return datetime.datetime.strptime(inputTime[0:19],inputTimeFormat)
        
    #日期信息格式化timeFormat : '%Y-%m-%d %H:%M:%S',返回字符串格式
    @staticmethod
    def GetDateInput(inputDateFormat,inputTimeFormat,inputTime):
        if len(inputTime) < 10 or inputTime is None or  inputTime == "":
            return "1900-01-01"
        time1=datetime.datetime.strptime(inputTime.replace("T"," "),inputTimeFormat)
        return time1.strftime(inputDateFormat)
    
    #(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
    @staticmethod
    def DateTimeAdd(inputDate,inputDateType,inputNum):
        #%d %H:%M:%S
        delta = None
        if inputDateType == "d":
            delta = timedelta(days=inputNum)
        elif inputDateType == "W":
            delta = timedelta(weeks=inputNum)
        elif inputDateType == "H":
            delta = timedelta(hours=inputNum)
        elif inputDateType == "M":
            delta = timedelta(minutes=inputNum)
        elif inputDateType == "S":
            delta = timedelta(seconds=inputNum)
        return inputDate + delta
        
    @staticmethod
    def SetHashTable(inputHt,inputStrKey,inputStrValue):
        if inputHt is None:
            inputHt = {}
        inputHt[inputStrKey] = inputStrValue
    
    @staticmethod
    def GetHashTable(inputHt,inputStrKey):
        if inputHt is None or inputStrKey not in list(inputHt.keys()):
            return ""
        else:
            return inputHt[inputStrKey]

    @staticmethod
    def GetHashTableNone(inputHt,inputStrKey):
        if inputHt is None or inputStrKey not in list(inputHt.keys()):
            return None
        else:
            return inputHt[inputStrKey]

    @staticmethod
    def RemoveHashTable(inputHt,inputStrKey):
        if inputHt.get(inputStrKey) is not None:
            inputHt.pop(inputStrKey)
    
    @staticmethod
    def Str_To_Int(inputStr):
        if inputStr is not None and inputStr != "":
            return int(inputStr)
        else:
            return 0
    
    @staticmethod
    def Get_New_GUID():
        return str(uuid.uuid1()).upper()

运行程序,选择主程序右键:

程序执行结果:

恭喜你!系统整体结构搭建完成。

  1. 监测数据采集物联网应用开发步骤(4)
相关推荐
胖达不服输1 小时前
「日拱一码」020 机器学习——数据处理
人工智能·python·机器学习·数据处理
吴佳浩1 小时前
Python入门指南-番外-LLM-Fingerprint(大语言模型指纹):从技术视角看AI开源生态的边界与挑战
python·llm·mcp
吴佳浩2 小时前
Python入门指南-AI模型相似性检测方法:技术原理与实现
人工智能·python·llm
叶 落2 小时前
计算阶梯电费
python·python 基础·python 入门
Python大数据分析@3 小时前
Origin、MATLAB、Python 用于科研作图,哪个最好?
开发语言·python·matlab
编程零零七3 小时前
Python巩固训练——第一天练习题
开发语言·python·python基础·python学习·python练习题
Zonda要好好学习4 小时前
Python入门Day4
java·网络·python
小龙在山东4 小时前
Python 包管理工具 uv
windows·python·uv
weixin_307779135 小时前
批量OCR的GitHub项目
python·github·ocr
孤狼warrior6 小时前
灰色预测模型
人工智能·python·算法·数学建模