新聞中心

        EEPW首頁 > 嵌入式系統 > 設計應用 > 基于MODBUS現場總線技術的電力儀表遠程通訊軟件開發

        基于MODBUS現場總線技術的電力儀表遠程通訊軟件開發

        作者: 時間:2016-12-19 來源:網絡 收藏

        4. 人機界面:

        本文引用地址:http://www.104case.com/article/201612/331178.htm
        5.程序代碼:
        API 函數聲名
        Private Declare Function GetTickCount Lib "kernel32" () As Long
        點擊結束程序按鈕
        Private Sub CmdEnd_Click()
        End
        End Sub
        點擊讀取電功率按鈕
        Private Sub CmdRead_Click()
        Timer1.Enabled = Not Timer1.Enabled
        If Timer1.Enabled Then
        CmdRead.Caption = "停止讀數"
        Else
        CmdRead.Caption = "讀取電功率"
        &nb
        sp;End If
        End Sub
        程序初始化
        Private Sub Form_Load()
        MSComm1.InputMode = comInputModeBinary
        MSComm1.PortOpen = True
        Timer1.Enabled = False
        End Sub
        Private Sub Timer1_Timer()
        Dim C4%, C5%, C6%, C7%
        Dim Tick&
        Dim Data As Double
        Dim Buf() As Byte
        Dim ByteOut(7) As Byte
        MSComm1.InputLen = 0
        Buf = MSComm1.Input
        重新定義數據輸入緩沖區, 發送命令 4
        MSComm1.InputLen = 1
        ByteOut(0) = &H1
        ByteOut(1) = &H4
        ByteOut(2) = &H0
        ByteOut(3) = &H5C
        ByteOut(4) = &H0
        ByteOut(5) = &H4
        ByteOut(6) = &H31
        ByteOut(7) = &HDB
        MSComm1.Output = ByteOut(0) & ByteOut(1) & ByteOut(2) & ByteOut(3) & ByteOut(4) & ByteOut(5) &
        ByteOut(6) & ByteOut(7)
        &
        nbsp; 等待多功能電力儀表響應的數據到達串口
        Tick = GetTickCount()
        Do
        If (GetTickCount() - Tick) / 1000# > 10 Then
        MsgBox "時間過久,請檢查多功能電力儀表及傳輸狀態!", vbCritical + vbOKOnly, "系統信息"
        Exit Sub
        End If
        DoEvents
        Loop Until MSComm1.InBuFFerCount >= 9
        從輸入緩沖區讀數據
        Buf = MSComm1.Input
        If Buf(0) <> 1 Then
        MsgBox "地址錯誤!", vbCritical + vbOKOnly, "系統信息"
        Exit Sub
        End If
        Buf = MSComm1.Input
        If Buf(0) <> 4 Then
        MsgBox "長度錯誤!", vbCritical + vbOKOnly, "系統信息"
        Exit Sub
        End If
        Buf = MSComm1.Input
        C4 = Buf(0)
        Buf = MSComm1.Input
        C5 = Buf(0)
        Buf = MSComm1.Input
        C6 = Buf(0)
        Buf = MSComm1.Input
        C7 = Buf(0)
        Buf = MSComm1.Input
        Buf = MSComm1.Input
        Data = Power(C4, C5, C6, C7)
        TxtPower.Text = CStr(Data)
        End Sub
        自定義功率換算函數
        Private Function Power(C4%, C5%, C6%, C7%)
        Dim PowerExp As String, Mantissa As String
        Dim ReadValue#
        Dim ValueSign&
        If ((C4 And &H80) / 2 ︿ 7) = True Then
        ValueSign = -1
        Else
        ValueSign = 1
        End If
        PowerExp = CStr((C4 And &H7F) * 2 + (C5 And &H80) / 2 ︿ 7)
        Mantissa = CStr((&H80 or C5) * 2 ︿ 16 + C6 * 2 ︿ 8 + C7)
        ReadValue = ValueSign * 2 ︿ (Val(PowerExp) - 126) * Val(Mantissa) / (256 * 65536)
        Power = ReadValue
        End Function
        四、結論
        本實例是作者在實驗室做過多次實驗,達到了預定的應用效果,目前在江西某廠取得了實際的應用。
        該控制系統的最大優點是:
        1,從硬件上看,僅僅使用一個轉換模塊就可以實現全廠電能遠程監控和集中管理的功能。大大提高了效率,且十分經濟實惠。
        2,從軟件上看,直接使用串口的控制技術,而不必需要寫額外的驅動程序。采用VB 開發應用軟件十分方便,編程工作量小。

        上一頁 1 2 下一頁

        評論


        技術專區

        關閉
        主站蜘蛛池模板: 文安县| 孝昌县| 宜章县| 博乐市| 东乡族自治县| 九龙坡区| 辽宁省| 谢通门县| 隆昌县| 和田市| 凌源市| 惠安县| 九江县| 南雄市| 宜春市| 金山区| 东乡| 刚察县| 商城县| 温州市| 成安县| 贡觉县| 万载县| 宣化县| 中江县| 大石桥市| 德钦县| 响水县| 汶川县| 正镶白旗| 永仁县| 嘉善县| 宾阳县| 景宁| 朝阳县| 宁国市| 铜陵市| 赤壁市| 紫金县| 和平县| 临澧县|