使用S7.NET.DLL读取PLC数据

S7.NET.DLL基于西门子GET/PUT封装了读取以及写数据功能,下面是不成熟的程序,基本可以将数据从PLC读出,也可将数据写入PLC,仅供参考,以下是原代码:

Option Explicit On
'Imports System.Collections.ge
'Imports System.Linq
Imports System.Text
'Imports System.Threading.tas
Imports S7.Net

Public Class Form1
    Dim Rack As Short
    Dim slot As Short
    Dim IPAddress As String = “192.168.1.50”
    Dim CPUTypes As String
    'Dim PLC_Pallet = New Plc(CpuType.S7300, "192.168.1.1", Rack, slot)
    Dim PLC_Pallet = New Plc(CPUTypes, IPAddress, Rack, slot)
    Dim AppXls As Microsoft.Office.Interop.Excel.Application

 Private Sub Btn_Connect_Click(sender As Object, e As EventArgs) Handles Btn_Connect.Click
        CPUTypes = CStr(Combox_CPUType.Text)
        IPAddress = txtAddress.Text
        Rack = Short.Parse(txtRack.Text)
        slot = Short.Parse(txtSlot.Text)
        PLC_Pallet = New Plc(CpuType.S7300, IPAddress, Rack, slot)
        Try
            PLC_Pallet.Open()
        Catch ex As Exception
            MessageBox.Show("连接PLC设备失败")
        End Try
  End Sub

    Private Sub Btn_Write_Click(sender As Object, e As EventArgs) Handles Btn_Write.Click
        PLC_Pallet.Write(
"DB1.DBX0.1", True)
        PLC_Pallet.Write("DB1.DBD12.0", 123457)
 
  End Sub

    Private Sub Btn_Write_Click(sender As Object, e As EventArgs) Handles Btn_Write.Click
        PLC_Pallet.Write("DB1.DBX0.1", True)
        PLC_Pallet.Write("DB1.DBD12.0", 123457)
    End Sub

End Class

你可能感兴趣的:(VB.NET,开发语言,visual,studio,code)