Programmable Logic Controller, disingkat PLC merupakan peralatan elektronik yang dibangun dari mikroprosesor untuk memonitor keadaan dari peralatan input untuk kemudian di analisa sesuai dengan kebutuhan perencana (programmer) untuk mengontrol keadaan output. Sinyal input diberikan kedalam input card.
Ada 2 jenis input card, yaitu :
Analog input card
Digital input card
Contoh untuk mengakses PLC :
1. Connect to PLC
Imports PLCcom
Public Class myTestClass
Private Device As PLCcomDevice
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
'create TCP_ISO_Device instance from PLCcomDevice
Device = New TCP_ISO_Device("192.168.1.2", 0, 2, ePLCType.S7_300_400_compatibel)
'or create MPI_Device instance from PLCcomDevice
'Device = New MPI_Device("COM2", 0, 2, eBaudrate.b38400, eSpeed.Speed187k, ePLCType.S7_300_400_compatibel)
'or create PPI_Device instance from PLCcomDevice
'Device = New PPI_Device("COM2", 0, 2, eBaudrate.b9600, ePLCType.S7_200_compatibel)
authentication.User = "" 'Enter User here
authentication.Serial = "" 'Enter Serial here
Device.Connecttimeout = 1000
Device.Readtimeout = 2000
Dim res As ConnectResult = Device.Connect()
MessageBox.Show(res.Message)
End Sub
End Class
2. Disconnect from PLC
Untuk memutuskan koneksi ke PCL hanya 1 baris perintah : Device.DisConnect()
3. Automatic connect to PLC
Imports PLCcom
Public Class myTestClass
'declare the Device
Private Device As PLCcomDevice
Private Sub btnConnect_Click(sender As Object, e As System.EventArgs)
'create TCP_ISO_Device instance from PLCcomDevice
Device = New TCP_ISO_Device("192.168.1.2", 0, 2, ePLCType.S7_300_400_compatibel)
'or create MPI_Device instance from PLCcomDevice
'Device = new MPI_Device("COM2", 0, 2, eBaudrate.b38400, eSpeed.Speed187k, ePLCType.S7_300_400_compatibel);
'or create PPI_Device instance from PLCcomDevice
'Device = new PPI_Device("COM2", 0, 2, eBaudrate.b9600, ePLCType.S7_200_compatibel);
authentication.User = ""
authentication.Serial = ""
'Set auto connect
'The connection is opened automatically when it is needed. If after the expiry of the given period, no more requests are sent, the connection is automatically closed.
Device.setAutoConnect(True, 10000)
End Sub
End Class
4 . Simple reading data from PLC
Imports PLCcom
Imports System.Windows.Forms
Namespace CodeDokuCSharp
Class newClass
Private Device As PLCcomDevice
Private Sub btnRead_Click(sender As Object, e As EventArgs)
'declare a ReadRequest object
'set the request parameters
'read 10 Bytes from DB100
Dim myReadRequest As New ReadDataRequest(eRegion.DataBlock, 100, 0, eDataType.[BYTE], 10)
'read from device
Dim res As ReadDataResult = Device.ReadData(myReadRequest)
'evaluate results
txtMessage.Text = res.Message
If res.Quality = OperationResult.eQuality.GOOD Then
For Each b As Byte In DirectCast(res.GetValues(), Byte())
txtResult.Text += b.ToString() & Environment.NewLine
Next
MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
End Class
End Namespace
Reference : https://www.plccom.net/en/plccom/for-s7/fors7-code-examples/