上位PC机有控制和读取PLC内部软元件的功能,需要添加三菱MX COMPONENT软件的类引用
Option Strict On
Imports ActUtlTypeLib
Imports ActProgTypeLib
Imports AxActUtlTypeLibPrivate Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load mycommunication.ActLogicalStationNumber = 1
back = mycommunication.Open()
If back <> 0 Then
MsgBox("连接失败")
GroupBox1.Enabled = False
IOToolStripMenuItem.Enabled = False
End If
End Sub
Private Sub Form1_Closing(sender As Object, e As EventArgs) Handles MyBase.FormClosing
back = mycommunication.Close()
End Sub
Private Sub BtnYSET_Click(sender As Object, e As EventArgs) Handles BtnYSET.Click
Dim a As String = TxtY.Text
Dim b As Boolean = False
b = Txt2Number(a, 8)
If b = True Then
mycommunication.SetDevice("Y" & TxtY.Text, 1)
LabelY显示.ForeColor = Color.Lime
Else
MsgBox("输入Y编号不正确")
Exit Sub
End If
End Sub
Private Sub BtnDWrite_Click(sender As Object, e As EventArgs) Handles BtnDWrite.Click
Dim a As String = TxtD.Text
Dim b As Boolean = False
Dim writevalue(1) As Int32
b = Txt2Number(a, 10)
If b = True Then
Try
writevalue(0) = Convert.ToInt32(TxtDValue.Text)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
If CheckBoxY32.Checked = True Then
Dim sharrBufferForDeviceValue(1) As Short
Dim byarrBufferByte() As Byte
byarrBufferByte = BitConverter.GetBytes(CInt(TxtDValue.Text))
sharrBufferForDeviceValue(0) = BitConverter.ToInt16(byarrBufferByte, 0)
sharrBufferForDeviceValue(1) = BitConverter.ToInt16(byarrBufferByte, 2)
mycommunication.WriteDeviceBlock2("D" & TxtD.Text, 2, sharrBufferForDeviceValue(0))
Else
If (writevalue(0) > 32767 OrElse writevalue(0) < -32768) Then
MsgBox("输入D数值超出界限")
Else
mycommunication.WriteDeviceBlock("D" & TxtD.Text, 1, writevalue(0))
End If
End If
Else
MsgBox("输入D编号不正确")
Exit Sub
End If
End Sub
Private Sub BtnDRead_Click(sender As Object, e As EventArgs) Handles BtnDRead.Click
Dim a As String = TxtD.Text
Dim b As Boolean = False
Dim readvalue(1) As Int32
b = Txt2Number(a, 10)
If b = True Then
If CheckBoxDR32.Checked = True Then
Dim Value32 As Integer
Dim bianhao As Integer
bianhao = Convert.ToInt32(TxtD.Text)
mycommunication.ReadDeviceBlock("D" & bianhao, 1, readvalue(0))
mycommunication.ReadDeviceBlock("D" & (bianhao 1), 1, readvalue(1))
If (readvalue(1) > 32767) Then
readvalue(1) = readvalue(1) - 65536
End If
Value32 = 65536 * readvalue(1) readvalue(0)
TxtDRead.Text = Value32.ToString
Else
mycommunication.ReadDeviceBlock("D" & TxtD.Text, 1, readvalue(0))
If (readvalue(0) > 32767) Then
TxtDRead.Text = (readvalue(0) - 65536).ToString
Else
TxtDRead.Text = readvalue(0).ToString
End If
End If
Else
MsgBox("输入D编号不正确")
Exit Sub
End If
End Sub
评论