һ - רҵ·ĵϷƽ̨

VB控件Mscomm控件与PLC进行RS485(Modbus)通讯源码 - 百度文库

Դû ʱ䣺2025/7/24 23:35:47 loading ƪĵֻ
˵ݽԤݿܲȫҪĵҪݣwordʹáword΢ź:xxxxxxxQQxxxxxx ܸṩĵл֧½⡣

VBؼMscommؼPLCRS485(Modbus)ͨѶԴ

õModbus RTUͨѶģʽͨתRS485Χ豸ͨͨѶдΧ豸ַָݣӶﵽԶԶ豸

Dim HiByte As Byte Dim LoByte As Byte Dim CRC16Lo As Byte Dim CRC16Hi As Byte Dim ReturnData(1) As Byte Dim K As Integer Dim CmdLenth As Integer

Private Sub Command1_Click() K = Text9.Text 'д6 ֽ

Text13.Text = \

'===========

ֵ

=======================================================================================

'<< 㷨һ >> Dim WriteStr() As Byte Dim u As Integer

ReDim WriteStr(K + 2) For u = 0 To K

WriteStr(u) = Val(\ext) Next

'<< 㷨 >> Dim CRC_2() As Byte Dim v As Integer ReDim CRC_2(K) For v = 0 To K

CRC_2(v) = Val(\Next

'==================================================================================================

Call CRC161(CRC_2())

Call CRC16(WriteStr(), K)

MSComm1.InBufferCount = 0

'==========

ʾʹ

========================================================================================

Dim m As Integer For m = 0 To 23 If m <= K Then

Text8(m).Text = Hex(WriteStr(m)) Else

Text8(m).Text = \End If Next

'================================================================================================== WriteStr(K + 1) = LoByte WriteStr(K + 2) = HiByte

' ʹ Text4.Text = \Dim g As Integer

For g = 0 To K + 2

Text4.Text = Text4.Text + \ \Next

'дͺ,յ8 ֽʱж CmdLenth = 8

MSComm1.RThreshold = CmdLenth

MSComm1.Output = WriteStr End Sub

Private Sub Command2_Click() End End Sub

Private Sub Command3_Click()

Label34.Caption = \Text13.Text = \

K = Text9.Text 'д6 ֽ

'=========== ========

'<< 㷨 >> Dim CRC_2() As Byte Dim v As Integer ReDim CRC_2(K)

For v = 0 To K

CRC_2(v) = Val(\Next

'==================================================================================================

Call CRC161(CRC_2()) Call CRC16(WriteStr(), K)

MSComm1.InBufferCount = 0

'========== ʾʹ ========================================================================================

Dim m As Integer For m = 0 To 23

If m <= K Then

Text8(m).Text = Hex(WriteStr(m)) Else

Text8(m).Text = \End If Next

'================================================================================================== WriteStr(K + 1) = LoByte

ֵ

===============================================================================

WriteStr(K + 2) = HiByte

' ʹ Text4.Text = \Dim g As Integer

For g = 0 To K + 2

Text4.Text = Text4.Text + \ \Next

'ͺ, 5 + SendStr(5) * 2 ֽʱж CmdLenth = 5 + WriteStr(5) * 2 MSComm1.RThreshold = CmdLenth

MSComm1.Output = WriteStr '

'****************************************************************************************************************************************

'********************************************************** *********************************************************

'**************************************************************************************************************************************** ' Dim sAddr As String '

' Dim CheckString As String ' Dim CheckCode As String ' Dim CmdCode As String ' Dim Sum As Integer ' Dim a As Integer ' Dim tmp As String 'a = 0 'tmp = 0 ' ' '

' Do While Len(tmp) < 8

'

' tmp = tmp + MSComm1.Input

' testNO.Caption = testNO.Caption + \ \' a = a + 1

' If a >= 3000 Then

' MSComm1.PortOpen = False

VB控件Mscomm控件与PLC进行RS485(Modbus)通讯源码 - 百度文库.doc ĵWordĵصԣ㸴ơ༭ղغʹӡ
Ƽ
Copyright © 2012-2023 һ Ȩ | ϵ
:վز֪ʶȨݡϢ紫ȨתصƷַȨ,һ֪ͨǣǻἰʱɾ
ͷQQxxxxxx 䣺xxxxxx@qq.com
ICP2023013149
Top