vb.net以太网通信 vb以太网通讯控件( 三 )


MsgBox("还未与PLC建立联接!")
Exit Sub
End If
'
Call butRead_Click(Nothing, Nothing)
Call butWrite_Click(Nothing, Nothing)
'
If (Val(txtReRead.Text)0) Or (Val(txtReWrite.Text)0) Then
butScan.Text = "Cycle R/W"
Exit Sub
Else
ScanCount1 += 1
txtScanCnt.Text = ScanCount1
txtScanPrd.Text = (timeGetTime - tim)"ms"
End If
Timer1.Enabled = True
End Sub
Private Sub butBitTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butBitTest.Click
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim rd As Boolean
Dim re As Short
Dim mry As EntQsPlc_Asc.PlcClient.PlcMemory = cmbBitMry.SelectedIndex + 1
re = PLC.Bit_Test(Handle1, mry, CUShort(txtBitAdd.Text), rd)
txtBitTest.Text = rd
txtReBit.Text = re
End Sub
Private Sub butBitSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butBitSet.Click
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
【vb.net以太网通信 vb以太网通讯控件】End If
Dim re As Short
re = PLC.Bit_Set(Handle1, cmbBitMry.SelectedIndex + 1, Val(txtBitAdd.Text))
txtReBit.Text = re
End Sub
Private Sub butBitRst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butBitRst.Click
If Not EntLink1 Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim re As Short
re = PLC.Bit_Reset(Handle1, cmbBitMry.SelectedIndex + 1, Val(txtBitAdd.Text))
txtReBit.Text = re
End Sub
End Class
谁有VB和OMRON PLC 通信例子?。磕芊穹⒏鲈即耄?再次特别感谢!提供一个VB.NET与OMRON以太网通讯的代码,是我项目里面复制出来的:
Dim Handle1 As Int32 'PLC的连接句柄
Dim EntLink As Boolean '连接标志
Dim PLC As New FinsTcp.PlcClient '引用OMRON的通讯组件
Private Sub butLink_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butLink.Click
Dim re As Short
Dim restr As String = ""
re = PLC.EntLink(Trim(txtLocalIP.Text), Val(txtLocalPort.Text), Trim(txtRemoteIP.Text), Val(txtRemotePort.Text), "DEMO", Handle1)
txtReLink.Text = re.ToString
If re = 0 Then
EntLink = True
MsgBox("PLC联接成功! ")
Else
EntLink = False
MsgBox("PLC联接失败: "restr)
End If
End Sub
Private Sub butClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butClose.Click
Dim re As Short
EntLink = False
re = PLC.DeLink(Handle1)
txtReClose.Text = re.ToString
End Sub
Private Sub butRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butRead.Click
Dim re As Short
Dim i As Short
Dim RD() As Object
ReDim RD(Val(txtReadCnt.Text - 1))
If Not EntLink Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim mry As FinsTcp.PlcClient.PlcMemory = cmbReadMry.SelectedIndex + 1
Dim typ As FinsTcp.PlcClient.DataType = cmbReadType.SelectedIndex + 1
re = PLC.CmdRead(Handle1, mry, typ, CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
txtReRead.Text = re.ToString
lstRead.Items.Clear()
For i = 0 To UBound(RD) Step 1
If Not IsNothing(RD(i)) Then lstRead.Items.Add(RD(i))
Next i
If re0 Then
Timer1.Enabled = False
butScan.Text = "Cycle R/W"
End If
End Sub
Private Sub butWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butWrite.Click
Dim re As Short
Dim i As Short
Dim temp() As String
Dim WD() As Object
If Not EntLink Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If

推荐阅读