国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

9、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(7)

這篇具有很好參考價(jià)值的文章主要介紹了9、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(7)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

源碼將于最后一遍文章給出下載

監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(6)

串口(COM)通訊開(kāi)發(fā)

本章節(jié)測(cè)試使用了 Configure Virtual Serial Port Driver虛擬串口工具和本人自寫的串口調(diào)試工具,請(qǐng)自行baidu下載對(duì)應(yīng)工具

9、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(7),物聯(lián)網(wǎng),python

com.zxy.common.Com_Para.py中添加如下內(nèi)容

#RS232串口通訊列表 串口號(hào),波特率,數(shù)據(jù)位,索引(A,B,C,D區(qū)分),多串口分割符;
ComPortList = ""  #linux參考:/dev/ttyS0,9600,8,0,A;/dev/ttyS1.9600,8,0,B windwows參考:COM1,9600,8,0;COM2,9600,8,2
#串口通訊全局變量hashtable <String, seria>串口索引---串口對(duì)象
htComPort = {}

?在com.zxy.main.Init_Page.py中添加如下內(nèi)容

    @staticmethod
    def Start_ComPort():
        iIndex = 0
        for temComPort in Com_Para.ComPortList.split(";"):
            iIndex = iIndex + 1
            temComPortInfo = temComPort.split(",")   
            try:
                if len(temComPortInfo) == 5 and Com_Fun.GetHashTableNone(Com_Para.htComPort, temComPortInfo[4]) is None:
                    temCD = ComDev(temComPortInfo[0], int(temComPortInfo[1]), int(temComPortInfo[2]), int(temComPortInfo[3]), iIndex)
                    temCD.attPortName = temComPortInfo[4]
                    Com_Fun.SetHashTable(Com_Para.htComPort, temComPortInfo[4], temCD)
            except Exception as e:
                print("com link error:COM"+temComPortInfo[0]+"==>"  + repr(e)+"=>"+str(e.__traceback__.tb_lineno))
            finally:
                Pass

創(chuàng)建串口設(shè)備管理類com.zxy.comport.ComDev.py

#! python3
# -*- coding: utf-8 -
'''
Created on 2017年05月10日
@author: zxyong 13738196011
'''

import datetime,threading,time,serial
from com.zxy.common.Com_Fun import Com_Fun
from com.zxy.adminlog.UsAdmin_Log import UsAdmin_Log
from com.zxy.common import Com_Para
from com.zxy.z_debug import z_debug

#監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用--串口設(shè)備管理
class ComDev(z_debug):    
    attIndex    =   0
    attPort     =   0
    attBaudrate =   9600
    attBytesize =   8
    attSerial   =   None
    #超時(shí)時(shí)間(秒) 為了驗(yàn)證測(cè)試效果,將時(shí)間設(shè)置為10秒
    attTimeout  =   10
    #返回值
    attReturnValue  = None
    attPortName     = ""
    #特殊插件處理
    attProtocol     = ""
    #回發(fā)數(shù)據(jù)
    attSendValue    = None
    #線程鎖
    attLock = threading.Lock()
    
    def __init__(self, inputPort,inputBaudrate,inputBytesize,inputparity,inputIndex):
        self.attPort = inputPort
        self.attBaudrate = inputBaudrate
        self.attBytesize = inputBytesize
        temParity =  "N"
        if str(inputparity) == "0":   #無(wú)校驗(yàn)
            temParity =  "N"
        elif str(inputparity) == "1": #偶校驗(yàn)
            temParity =  "E"
        elif str(inputparity) == "2": #奇校驗(yàn)
            temParity =  "O"
        elif str(inputparity) == "3":
            temParity =  "M"
        elif str(inputparity) == "4":
            temParity =  "S"
        self.attSerial = serial.Serial(port=self.attPort,baudrate=self.attBaudrate,bytesize=self.attBytesize,parity=temParity, stopbits=1)
        self.attSerial.timeout = self.attTimeout
        self.attIndex = inputIndex
        self.OpenSeriaPort()
    
    #打開(kāi)串口
    def OpenSeriaPort(self):
        try: 
            if not self.attSerial.isOpen():  
                self.attSerial.open()
            t = threading.Thread(target=self.OnDataReceived, name="ComPortTh" + str(self.attIndex))
            t.start()
            
            uL = UsAdmin_Log(Com_Para.ApplicationPath,str("ComPortTh" + str(self.attIndex)))
            uL.SaveFileDaySub("thread")      
            print("Open ComPortTh" + str(self.attIndex)+" COM:"+str(self.attSerial.port)+" "+Com_Fun.GetTimeDef()+" lenThreads:"+str(len(threading.enumerate())))
            return True
        except Exception as e:
            if str(type(self)) == "<class 'type'>":
                self.debug_in(self,repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            else:
                self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            return False
        finally:
            pass

    #關(guān)閉串口
    def CloseSeriaPort(self):
        try: 
            if not self.attSerial.isOpen():  
                self.attSerial.close()
            return True
        except Exception as e:
            if str(type(self)) == "<class 'type'>":
                self.debug_in(self,repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            else:
                self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            return False
        finally:
            pass
    
    #發(fā)送數(shù)據(jù)無(wú)返回 
    def WritePortDataImmed(self,inputByte):
        try: 
            if not self.attSerial.isOpen():  
                self.OpenSeriaPort()
            if self.attSerial.isOpen() and self.attLock.acquire():                    
                self.attReturnValue = None
                temNumber = self.attSerial.write(inputByte)
                time.sleep(0.2)
                self.attLock.release()
                return temNumber
            else:
                return 0
        except Exception as e:
            if str(type(self)) == "<class 'type'>":
                self.debug_in(self,repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            else:
                self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            return -1
    
    #返回值為字節(jié),帶結(jié)束符 
    def WritePortDataFlag(self,inputByte,EndFlag):
        try: 
            if not self.attSerial.isOpen():  
                self.OpenSeriaPort()
            if self.attSerial.isOpen() and self.attLock.acquire():                    
                self.attReturnValue = None
                temNumber = self.attSerial.write(inputByte)    
                starttime = datetime.datetime.now()    
                endtime = datetime.datetime.now() + datetime.timedelta(seconds=self.attTimeout)
                while (self.attReturnValue is None or self.attReturnValue[len(self.attReturnValue) - len(EndFlag):len(self.attReturnValue)] != EndFlag.encode(Com_Para.U_CODE)) and starttime <= endtime:
                    starttime = datetime.datetime.now()
                    time.sleep(0.2)                
                self.attLock.release()
                return temNumber
        except Exception as e:
            if str(type(self)) == "<class 'type'>":
                self.debug_in(self,repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            else:
                self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            return -1
        finally:
            pass
    
    #返回值為字節(jié) 
    def WritePortData(self,inputByte):
        try: 
            if not self.attSerial.isOpen():  
                self.OpenSeriaPort()
            if self.attSerial.isOpen() and self.attLock.acquire():                    
                self.attReturnValue = None
                temNumber = self.attSerial.write(inputByte)    
                starttime = datetime.datetime.now()    
                endtime = datetime.datetime.now() + datetime.timedelta(seconds=self.attTimeout)
                while self.attReturnValue is None and starttime <= endtime:
                    starttime = datetime.datetime.now()
                    time.sleep(0.2)                
                self.attLock.release()
                return temNumber
        except Exception as e:
            if str(type(self)) == "<class 'type'>":
                self.debug_in(self,repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            else:
                self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))#打印異常信息
            return -1
        finally:
            pass
    
    #接收數(shù)據(jù)        
    def OnDataReceived(self):
        try:
            while self.attSerial.isOpen():
                temNum = self.attSerial.inWaiting()
                if temNum > 0:
                    if self.attReturnValue is None:
                        self.attReturnValue = self.attSerial.read(temNum)
                    else:
                        self.attReturnValue = self.attReturnValue + self.attSerial.read(temNum)
                else:
                    time.sleep(1)
        except Exception as e:
            if str(type(self)) == "<class 'type'>":
                self.debug_in(self, repr(e)+"=>"+str(e.__traceback__.tb_lineno))
            else:
                self.debug_in(repr(e)+"=>"+str(e.__traceback__.tb_lineno))
            self.attReturnValue = None

串口通訊測(cè)試案例MonitorDataCmd.py主文件中編寫:

在該語(yǔ)句下添加

9、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(7),物聯(lián)網(wǎng),python

       #串口配置參數(shù)
        Com_Para.ComPortList = "COM2,9600,8,0,A;COM4,9600,8,2,B"
        #串口連接初始化
        Init_Page.Start_ComPort()
        #測(cè)試串口數(shù)據(jù)發(fā)送和接收
        temCP2 = Com_Fun.GetHashTable(Com_Para.htComPort,"A")#獲取串口2對(duì)象
        temCP4 = Com_Fun.GetHashTable(Com_Para.htComPort,"B")#獲取串口4對(duì)象
        temByte1 = ("AABBCCDDVV").encode(Com_Para.U_CODE)   #發(fā)送字符串轉(zhuǎn)byte[]
        temByte2 = ("11223344KM").encode(Com_Para.U_CODE)   #發(fā)送字符串轉(zhuǎn)byte[]
        
        print("開(kāi)始發(fā)送串口數(shù)據(jù)")
        temRec1 = temCP2.WritePortData(temByte1)#往串口2發(fā)送數(shù)據(jù)
        print("串口2發(fā)送數(shù)據(jù)長(zhǎng)度:"+str(temRec1))
        strRec = ""
        if temCP2.attReturnValue != None:
            strRec = temCP2.attReturnValue.decode(Com_Para.U_CODE)#收到串口數(shù)據(jù)
        print("串口2收到數(shù)據(jù)值:"+strRec)

        temRec2 = temCP4.WritePortData(temByte2)#往串口4發(fā)送數(shù)據(jù)
        print("串口3發(fā)送數(shù)據(jù)長(zhǎng)度:"+str(temRec2))
        strRec = ""
        if temCP4.attReturnValue != None:
            strRec = temCP4.attReturnValue.decode(Com_Para.U_CODE)#收到串口數(shù)據(jù)
        print("串口4收到數(shù)據(jù)值:"+strRec)

串口調(diào)試測(cè)試結(jié)果:

9、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(7),物聯(lián)網(wǎng),python文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-680722.html

  1. 監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(8.1)

到了這里,關(guān)于9、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(7)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • 7、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(5.3)

    7、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(5.3)

    監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(5.2) 靜態(tài)配置庫(kù)數(shù)據(jù)庫(kù)調(diào)用,新建全局變量初始化類 com.zxy.main.Init_Page.py 數(shù)據(jù)庫(kù)操作測(cè)試 MonitorDataCmd.py 主文件中編寫: if __name__ == \\\'__main__\\\' : 下編寫 程序執(zhí)行成功結(jié)果:自動(dòng)生成center_data.db 打印出數(shù)據(jù)庫(kù)數(shù)據(jù) 小測(cè)試:把上文的sql語(yǔ)句故意語(yǔ)法

    2024年02月10日
    瀏覽(25)
  • 11、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(8.2)

    11、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(8.2)

    監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(8.1) 新建TCP/IP Client線程類 com.zxy.tcp.ClientThread.py 新建tcp client數(shù)據(jù)接收插件類1 com.plugins.Usereflect.testClientReflectClass1.py 新建tcp client數(shù)據(jù)接收插件類2 com.plugins.Usereflect.testClientReflectClass2.py 在 com.zxy.main.Init_Page.py 中添加代碼 TCP Client測(cè)試案例 Monit

    2024年02月10日
    瀏覽(25)
  • 13、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(9.2)

    13、監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(9.2)

    監(jiān)測(cè)數(shù)據(jù)采集物聯(lián)網(wǎng)應(yīng)用開(kāi)發(fā)步驟(9.1) TCP/IP Server開(kāi)發(fā) 新建TCP/IP Server線程類 com.zxy.tcp.ServerThread.py 新建作為TCP Server接收數(shù)據(jù)攔截器插件類 com.plugins.usereflect.testServerReflectInClass1.py 新建作為TCP Server接收數(shù)據(jù)攔截器插件類 com.plugins.usereflect.testServerReflectInClass2.py 在 com.zxy.main.Init_

    2024年02月10日
    瀏覽(52)
  • 物聯(lián)網(wǎng)數(shù)據(jù)采集網(wǎng)關(guān)在工廠數(shù)字化轉(zhuǎn)型中的應(yīng)用

    物聯(lián)網(wǎng)數(shù)據(jù)采集網(wǎng)關(guān)能將各種傳感器、執(zhí)行器等設(shè)備連接在一起,通過(guò)收集、處理和傳輸來(lái)自各種物理設(shè)備的信息,實(shí)現(xiàn)數(shù)據(jù)的集成和分析,同時(shí)可通過(guò)云平臺(tái)進(jìn)行數(shù)據(jù)交互。它具有數(shù)據(jù)轉(zhuǎn)換、數(shù)據(jù)處理、數(shù)據(jù)傳輸?shù)裙δ?,是工廠數(shù)字化轉(zhuǎn)型的核心組件。隨著科技的飛速發(fā)展

    2024年02月22日
    瀏覽(20)
  • iNeuOS工業(yè)互聯(lián)網(wǎng)操作系統(tǒng),高效采集數(shù)據(jù)配置與應(yīng)用

    iNeuOS工業(yè)互聯(lián)網(wǎng)操作系統(tǒng),高效采集數(shù)據(jù)配置與應(yīng)用

    1. 概述 2. 通訊原理 3. 參數(shù)配置 ?1.?? 概述 某生產(chǎn)企業(yè)世界500強(qiáng)的集團(tuán)能源管控平臺(tái)項(xiàng)目建設(shè),通過(guò)專線網(wǎng)絡(luò)實(shí)現(xiàn)異地廠區(qū)數(shù)據(jù)集成, 每個(gè)終端能源儀表都有 IP 地址,總共有1000 多臺(tái)能源表計(jì),總共有將近10000 個(gè)數(shù)據(jù)點(diǎn) 。在集團(tuán)端部署iNeuOS工業(yè)互聯(lián)網(wǎng)操作系統(tǒng),終端能源表

    2024年02月05日
    瀏覽(25)
  • 【雕爺學(xué)編程】MicroPython手冊(cè)之 ESP32-CAM 物聯(lián)網(wǎng)圖像數(shù)據(jù)采集應(yīng)用

    【雕爺學(xué)編程】MicroPython手冊(cè)之 ESP32-CAM 物聯(lián)網(wǎng)圖像數(shù)據(jù)采集應(yīng)用

    MicroPython是為了在嵌入式系統(tǒng)中運(yùn)行Python 3編程語(yǔ)言而設(shè)計(jì)的輕量級(jí)版本解釋器。與常規(guī)Python相比,MicroPython解釋器體積小(僅100KB左右),通過(guò)編譯成二進(jìn)制Executable文件運(yùn)行,執(zhí)行效率較高。它使用了輕量級(jí)的垃圾回收機(jī)制并移除了大部分Python標(biāo)準(zhǔn)庫(kù),以適應(yīng)資源限制的微控制

    2024年02月20日
    瀏覽(29)
  • 嵌入式物聯(lián)網(wǎng)單片機(jī)項(xiàng)目開(kāi)發(fā)實(shí)例-4G DTU邊緣數(shù)據(jù)采集網(wǎng)關(guān)開(kāi)發(fā)

    鏈接:https://pan.baidu.com/s/163D-kElFqXov629YaSrWDw?pwd=1688 提取碼:1688 [1.EC200S_STM32F103_4G CAT1網(wǎng)絡(luò)TCP和UDP的透?jìng)髯址甝 [2.EC200S_STM32F103_4G CAT1網(wǎng)絡(luò)TCP和UDP的透?jìng)魇M(jìn)制包含0x00] [3.EC200S_STM32F103_4G CAT1通過(guò)外置MQTT協(xié)議發(fā)送定位和固定數(shù)據(jù)到ONENET] [4.EC200S_STM32F103_4G CAT1通過(guò)外置MQTT協(xié)議發(fā)送

    2024年01月16日
    瀏覽(26)
  • 【IoT物聯(lián)網(wǎng)】IoT小程序在展示中央空調(diào)采集數(shù)據(jù)和實(shí)時(shí)運(yùn)行狀態(tài)上的應(yīng)用

    【IoT物聯(lián)網(wǎng)】IoT小程序在展示中央空調(diào)采集數(shù)據(jù)和實(shí)時(shí)運(yùn)行狀態(tài)上的應(yīng)用

    ??利用前端語(yǔ)言實(shí)現(xiàn)跨平臺(tái)應(yīng)用開(kāi)發(fā)似乎是大勢(shì)所趨,跨平臺(tái)并不是一個(gè)新的概念,“一次編譯、到處運(yùn)行”是老牌服務(wù)端跨平臺(tái)語(yǔ)言Java的一個(gè)基本特性。隨著時(shí)代的發(fā)展,無(wú)論是后端開(kāi)發(fā)語(yǔ)言還是前端開(kāi)發(fā)語(yǔ)言,一切都在朝著減少工作量,降低工作成本的方向發(fā)展。 ?

    2024年02月16日
    瀏覽(20)
  • 水庫(kù)安全監(jiān)測(cè)方案(實(shí)時(shí)數(shù)據(jù)采集、高速數(shù)據(jù)傳輸)

    水庫(kù)安全監(jiān)測(cè)方案(實(shí)時(shí)數(shù)據(jù)采集、高速數(shù)據(jù)傳輸)

    ? 一、引言 水庫(kù)的安全監(jiān)測(cè)對(duì)于防止水災(zāi)和保障人民生命財(cái)產(chǎn)安全至關(guān)重要。為了提高水庫(kù)安全監(jiān)測(cè)的效率和準(zhǔn)確性,本文將介紹一種使用星創(chuàng)易聯(lián)DTU200和SG800 5g工業(yè)路由器部署的水庫(kù)安全監(jiān)測(cè)方案。 二、方案概述 本方案主要通過(guò)使用星創(chuàng)易聯(lián)DTU200和SG800 5g工業(yè)路由器實(shí)現(xiàn)

    2024年02月08日
    瀏覽(27)
  • 橋梁安全監(jiān)測(cè)系統(tǒng)中數(shù)據(jù)采集上傳用 什么?

    橋梁安全監(jiān)測(cè)系統(tǒng)中數(shù)據(jù)采集上傳用 什么?

    背景 2023年7月6日凌晨時(shí)分,G5012恩廣高速達(dá)萬(wàn)段230公里加80米處6號(hào)大橋部分橋面發(fā)生垮塌,導(dǎo)致造成2車受損后自燃,3人受輕傷。目前,四川省公安廳交通警察總隊(duì)高速公路五支隊(duì)十四大隊(duì)民警已對(duì)現(xiàn)場(chǎng)進(jìn)行雙向管制。 作為世界第一橋梁大國(guó),目前我國(guó)公路橋梁數(shù)量超過(guò)100萬(wàn)

    2024年02月12日
    瀏覽(35)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包