谁有VB和OMRON PLC 通信例子?。磕芊穹⒏鲈即耄?再次特别感谢!提供一个VB.NET与OMRON以太网通讯vb.net以太网通信的代码vb.net以太网通信,是我项目里面复制出来的:
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建立联接vb.net以太网通信!")
Exit Sub
End If
Dim mry As FinsTcp.PlcClient.PlcMemory = cmbReadMry.SelectedIndex1
Dim typ As FinsTcp.PlcClient.DataType = cmbReadType.SelectedIndex1
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
ReDim WD(Val(txtWriteCnt.Text) - 1)
temp = Split(txtWrite.Text, vbCrLf)
【vb.net以太网通信 vb网络通信】For i = 0 To UBound(WD) Step 1
If iUBound(temp) Then
WD(i) = 0
Else
WD(i) = Trim(temp(i))
End If
Next i
Dim mry As FinsTcp.PlcClient.PlcMemory = cmbWriteMry.SelectedIndex1
Dim typ As FinsTcp.PlcClient.DataType = cmbWriteType.SelectedIndex1
re = PLC.CmdWrite(Handle1, mry, typ, CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
txtReWrite.Text = re.ToString
If re0 Then
Timer1.Enabled = False
butScan.Text = "Cycle R/W"
End If
End Sub
用vb.net实现网络通信用 vb.net socket通信
Dim th As Threading.Thread
2Dim tcpl As System.Net.Sockets.TcpListener
3
4Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5th = New System.Threading.Thread(New System.Threading.ThreadStart(AddressOf MyListen))
6th.Start()
7End Sub
8
9Public Sub SendMessage()Sub SendMessage(ByVal IP As String, ByVal SendMsg As String)
10Try
11If IP"" Then
12Dim tcpc As New System.Net.Sockets.TcpClient(IP, 5656)
13Dim tcpStream As Net.Sockets.NetworkStream = tcpc.GetStream
14Dim reqStream As New IO.StreamWriter(tcpStream)
15reqStream.Write(SendMsg)
16reqStream.Flush()
17tcpStream.Close()
18tcpc.Close()
19End If
20Catch ex As Exception
21MsgBox(ex.Message.ToString)
22End Try
23End Sub
24Private Sub MyListen()Sub MyListen()
25Try
26Dim ipAddress As System.Net.IPAddress = System.Net.Dns.Resolve(System.Net.Dns.GetHostName).AddressList(0)
27tcpl = New System.Net.Sockets.TcpListener(ipAddress, 5656)
28tcpl.Start()
29While True
30Dim s As System.Net.Sockets.Socket = tcpl.AcceptSocket()
31Dim MyBuffer(1024) As Byte
32Dim i As Integer
33i = s.Receive(MyBuffer)
34If i0 Then
35Dim lstrRec As String
36Dim j As Integer
37For j = 0 To i - 1
38TextBox1.Text= Chr(MyBuffer(j))","
39Next
40End If
41End While
42Catch ex As Exception
43MsgBox(ex.Message.ToString)
44End Try
45End Sub
46
47Private Sub Button1_Click()Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
48SendMessage("192.168.0.61", TextBox2.Text)
49End Sub
VB与VB.NET串口及以太网通迅关于串口通讯的问题:
很明显 , 你还不知道(不会、不习惯)使用事件驱动的方式接收数据 。
建议你仔细看看串口组件(无论VB6还是VB.net)的OnComm事件,你的问题很容易解决 。
关于以太网通讯:
在TCP通讯中端口确实可以重用 , 你百度一下“TCP端口重用”能查到很多示例 。
但绝大多数情况下不推荐端口重用,而应该采取服务器端建立连接池的方法 。
或者,干脆不用TCP,用UDP解决也可以 。
如何用vb.net通过以太网使用modulebus协议读写西门子s7-200 smart 能实现吗?没用过modbus通信写过,但是使用自由通信可以
VB.net带有通信控件,在里面设置波特率、奇偶效验、数据位、COM口
在PLC里做个自由通信就可以
vb.net以太网通信的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于vb网络通信、vb.net以太网通信的信息别忘了在本站进行查找喔 。
推荐阅读
- vm16无法创建虚拟机,vm无法创建新虚拟机
- 新款视频是什么样子,新视频素材
- 区块链技术广东,区块链技术与广东产业发展
- 小孩看电视摇头怎么办呀,孩子看电视晃头是什么病
- php怎么更改数据表 php怎么修改数据库内容
- mysql限制上传文件大小,mysql限制表大小
- 借钱下载,小虾借钱下载
- ios系统重装软件哪个好用,ios 重装
- linux导出图片命令行 linux 导出命令