您当前的位置:五五电子网电子知识plc技术PLC入门S7-200 ModBus从站通讯程序(PC作主站) 正文
S7-200 ModBus从站通讯程序(PC作主站)

S7-200 ModBus从站通讯程序(PC作主站)

点击数:7155 次   录入时间:03-04 11:48:48   整理:http://www.55dianzi.com   PLC入门

Next i

End If

If Len(FGetData) >= 6 Then

If Len(FGetData) > Val("&H" & Mid(FGetData, 5, 2)) * 2 + 8 Then

ReceiveData = FGetData

Exit Function

End If

End If

If GetTickCount - t1 > 2000 Then '2秒没收完就不收了

ReceiveData = ""

Exit Function

End If

Loop

End Function

Private Function IReceiveData() As String '反回I状态

Dim FGetData As String

Dim t1 As Long

Dim av As Variant

Dim i As Integer

Dim ReDataLen As Integer

FGetData = ""

t1 = GetTickCount() '取时间,做延时用

Do '循环等待接收数据

DoEvents

If MSComm1.InBufferCount > 0 Then '串口有数据了

字串5



ReDataLen = MSComm1.InBufferCount '取数据长度

av = MSComm1.Input '将串口数据取出来

For i = 0 To ReDataLen - 1

FGetData = FGetData & Right("00" & Hex(av(i)), 2)

Next i

End If

If Len(FGetData) >= 6 Then

If Len(FGetData) > Val("&H" & Mid(FGetData, 5, 2)) * 2 + 8 Then

IReceiveData = FGetData

Exit Function

End If

End If

If GetTickCount - t1 > 2000 Then '2秒没收完就不收了

IReceiveData = ""

Exit Function

End If

Loop

End Function

Private Function QReceiveData() As String '反回Q状态

Dim FGetData As String

Dim t1 As Long

Dim av As Variant

Dim i As Integer

Dim ReDataLen As Integer

FGetData = ""

t1 = GetTickCount() '取时间,做延时用

Do '循环等待接收数据

DoEvents 字串8

If MSComm1.InBufferCount > 0 Then '串口有数据了

ReDataLen = MSComm1.InBufferCount '取数据长度

av = MSComm1.Input '将串口数据取出来

For i = 0 To ReDataLen - 1

FGetData = FGetData & Right("00" & Hex(av(i)), 2)

Next i

End If

If Len(FGetData) >= 6 Then

If Len(FGetData) > Val("&H" & Mid(FGetData, 5, 2)) * 2 + 8 Then

QReceiveData = FGetData

Exit Function

End If

End If

If GetTickCount - t1 > 2000 Then '2秒没收完就不收了

QReceiveData = ""

Exit Function

End If

Loop

End Function

Private Sub Timer2_Timer()

x1 = x1 + 1

Text10.Text = str(x1)

Text1.Text = str(p11)

Text2.Text = str(p12)

Text3.Text = str(p13)

Text4.Text = str(p14)

Text7.Text = str(p15)

If Text7.Text = 1 Then Text7.BackColor = RGB(255, 0, 255) 字串9

If Text7.Text = 0 Then Text7.BackColor = RGB(0, 255, 255)

'Text6.Text = str(p16)

Text9.Text = str(p17)

If Text9.Text = 1 Then Text9.BackColor = RGB(255, 0, 255)

If Text9.Text = 0 Then Text9.BackColor = RGB(0, 255, 255)

'Text8.Text = str(p18)

End Sub

上一页  [1] [2] 


本文关键字:程序  PLC入门plc技术 - PLC入门