vb.net 2010与三菱PLC通讯
3个回答
展开全部
为何不使用三菱的MX Component部件呢?在三菱官网可以下载4.08版本,支持VS2010,你可以在MX软件的手册上找到例程。
追问
我电脑WIN7的装不了啊,有没有别的方法呢?
追答
4.08版本已经支持win8.1了。
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
刚好有个FX5U的以太网的代码:
Public Class Form1
Dim Handle1 As Int32
Dim PLC As New EntFxPlc.PlcClient '基于EntFxPlc.DLL新建实例
Dim EntLink As Boolean
Dim ScanCount As Long
Dim ScanRet As Short
Declare Function timeGetTime Lib "winmm.dll" () As UInt32
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CenterToScreen()
cmbReadMry.Items.Clear()
cmbReadMry.Items.Add("X")
cmbReadMry.Items.Add("Y")
cmbReadMry.Items.Add("M")
cmbReadMry.Items.Add("D")
cmbWriteMry.Items.Clear()
cmbWriteMry.Items.Add("X")
cmbWriteMry.Items.Add("Y")
cmbWriteMry.Items.Add("M")
cmbWriteMry.Items.Add("D")
cmbBitMry.Items.Clear()
cmbBitMry.Items.Add("X")
cmbBitMry.Items.Add("Y")
cmbBitMry.Items.Add("M")
cmbReadType.Items.Clear()
cmbReadType.Items.Add("INT16")
cmbReadType.Items.Add("UINT16")
cmbReadType.Items.Add("DINT32")
cmbReadType.Items.Add("HEX32")
cmbReadType.Items.Add("REAL32")
cmbReadType.Items.Add("BIN16")
cmbWriteType.Items.Clear()
cmbWriteType.Items.Add("INT16")
cmbWriteType.Items.Add("UINT16")
cmbWriteType.Items.Add("DINT32")
cmbWriteType.Items.Add("HEX32")
cmbWriteType.Items.Add("REAL32")
cmbWriteType.Items.Add("BIN16")
cmbReadMry.SelectedIndex = 3
cmbWriteMry.SelectedIndex = 3
cmbBitMry.SelectedIndex = 2
cmbReadType.SelectedIndex = 0
cmbWriteType.SelectedIndex = 0
lstRead.Items.Clear()
txtWrite.Text = ""
txtWrite2.Text = ""
cmbCmdType.SelectedIndex = 0
End Sub
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), CUShort(Val(txtLocalPort.Text)), Trim(txtRemoteIP.Text), CUShort(Val(txtRemotePort.Text)), "DEMO", Handle1, 1000, CBool(cmbCmdType.SelectedIndex))
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
EntLink = False
ScanRet = PLC.DeLink(Handle1)
txtReClose.Text = ScanRet.ToString
End Sub
Private Sub butRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butRead.Click
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 var1 As Integer = cmbReadType.SelectedIndex + 1
Dim typ As EntFxPlc.PlcClient.DataType = var1
Select Case cmbReadMry.SelectedIndex
Case 0 : ScanRet = PLC.CmdRead(Handle1, EntFxPlc.PlcClient.PlcMemory.DI, typ, CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
Case 1 : ScanRet = PLC.CmdRead(Handle1, EntFxPlc.PlcClient.PlcMemory.DQ, typ, CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
Case 2 : ScanRet = PLC.CmdRead(Handle1, EntFxPlc.PlcClient.PlcMemory.MR, typ, CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
Case 3 : ScanRet = PLC.CmdRead(Handle1, EntFxPlc.PlcClient.PlcMemory.DR, typ, CUShort(Val(txtReadAdd.Text)), CUShort(Val(txtReadCnt.Text)), RD)
End Select
txtReRead.Text = ScanRet.ToString
lstRead.Items.Clear()
For i = 0 To UBound(RD) Step 1
If Not IsNothing(RD(i)) Then
lstRead.Items.Add(RD(i))
Else
lstRead.Items.Add("0")
End If
Next i
End Sub
Private Sub butWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butWrite.Click
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)
For i = 0 To UBound(WD) Step 1
If i > UBound(temp) Then
WD(i) = 0
Else
WD(i) = Trim(temp(i))
End If
Next i
Dim var1 As Integer = cmbWriteType.SelectedIndex + 1
Dim typ As EntFxPlc.PlcClient.DataType = var1
Select Case cmbWriteMry.SelectedIndex
Case 0 : ScanRet = PLC.CmdWrite(Handle1, EntFxPlc.PlcClient.PlcMemory.DI, typ, CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
Case 1 : ScanRet = PLC.CmdWrite(Handle1, EntFxPlc.PlcClient.PlcMemory.DQ, typ, CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
Case 2 : ScanRet = PLC.CmdWrite(Handle1, EntFxPlc.PlcClient.PlcMemory.MR, typ, CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
Case 3 : ScanRet = PLC.CmdWrite(Handle1, EntFxPlc.PlcClient.PlcMemory.DR, typ, CUShort(Val(txtWriteAdd.Text)), CUShort(Val(txtWriteCnt.Text)), WD)
End Select
txtReWrite.Text = ScanRet.ToString
End Sub
Private Sub butScan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butScan.Click
If Not EntLink Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
If butScan.Text = "Cycle R/W" Then
ScanCount = 0
Timer1.Enabled = True
butScan.Text = "Stop R/W"
Else
Timer1.Enabled = False
butScan.Text = "Cycle R/W"
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Dim tim As Integer = timeGetTime
If Not EntLink Then
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
ScanCount += 1
txtScanCnt.Text = ScanCount
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 EntLink Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim rd As Boolean
Dim re As Short
Select Case cmbBitMry.SelectedIndex
Case 0 : re = PLC.Bit_Test(Handle1, EntFxPlc.PlcClient.PlcMemory.DI, CUShort(Val(txtBitAdd.Text)), rd)
Case 1 : re = PLC.Bit_Test(Handle1, EntFxPlc.PlcClient.PlcMemory.DQ, CUShort(Val(txtBitAdd.Text)), rd)
Case 2 : re = PLC.Bit_Test(Handle1, EntFxPlc.PlcClient.PlcMemory.MR, CUShort(Val(txtBitAdd.Text)), rd)
End Select
txtBitTest.Text = rd.ToString
txtReBit.Text = re.ToString
End Sub
Private Sub butBitSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butBitSet.Click
If Not EntLink Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim re As Short
Select Case cmbBitMry.SelectedIndex
Case 0 : re = PLC.Bit_Set(Handle1, EntFxPlc.PlcClient.PlcMemory.DI, CUShort(Val(txtBitAdd.Text)))
Case 1 : re = PLC.Bit_Set(Handle1, EntFxPlc.PlcClient.PlcMemory.DQ, CUShort(Val(txtBitAdd.Text)))
Case 2 : re = PLC.Bit_Set(Handle1, EntFxPlc.PlcClient.PlcMemory.MR, CUShort(Val(txtBitAdd.Text)))
End Select
txtReBit.Text = re.ToString
End Sub
Private Sub butBitRst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butBitRst.Click
If Not EntLink Then
MsgBox("还未与PLC建立联接!")
Exit Sub
End If
Dim re As Short
Select Case cmbBitMry.SelectedIndex
Case 0 : re = PLC.Bit_Reset(Handle1, EntFxPlc.PlcClient.PlcMemory.DI, CUShort(Val(txtBitAdd.Text)))
Case 1 : re = PLC.Bit_Reset(Handle1, EntFxPlc.PlcClient.PlcMemory.DQ, CUShort(Val(txtBitAdd.Text)))
Case 2 : re = PLC.Bit_Reset(Handle1, EntFxPlc.PlcClient.PlcMemory.MR, CUShort(Val(txtBitAdd.Text)))
End Select
txtReBit.Text = re.ToString
End Sub
End Class
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Q系列搜一下ComQsPlc.DLL, EntQsPlc.DLL;
FX系列搜一下ComFxPlc.DLL, EntFxPlc.DLL;
FX系列搜一下ComFxPlc.DLL, EntFxPlc.DLL;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询