Wednesday, February 1, 2023

Contoh Mengakses PLC Dengan Visual Basic.Net - II

 

5. Simple writing data to PLC

Imports PLCcom

Imports System.Windows.Forms

 

Class newClass

    Private Device As PLCcomDevice

    'see section 'connect' for declare and connect a PLCcom-Device

 

    Private Sub btnWrite_Click(sender As Object, e As EventArgs)

        'declare a WriteDataRequest object and

        'write 4 bytes in DB100 at Startbyte 0

        Dim myWriteRequest As New WriteDataRequest(eRegion.DataBlock, 100, 0)

        'add writable Data here

        myWriteRequest.addByte(New Byte() {11, 12, 13, 14})

        'write

        Dim res As WriteDataResult = Device.WriteData(myWriteRequest)

 

        'evaluate results

        txtMessage.Text = (DateTime.Now.ToString() & ": ") + res.Message

        If res.Quality.Equals(OperationResult.eQuality.GOOD) Then

            MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Else

            MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If

    End Sub

End Class


6. Optimized reading and writing of data

Imports PLCcom

 

Namespace CodeDokuCSharp

    Class newClass

        Private Device As PLCcomDevice 'see section 'connect' for declare and connect a PLCcom-Device

 

        Private Sub btnoptReadWrite_Click(sender As Object, e As EventArgs)

 

            Dim myRequestSet As ReadWriteRequestSet = New ReadWriteRequestSet()

             

            //set optimize options

            myRequestSet.SetOperationOrder(eOperationOrder.WRITE_BEVOR_READ)

            myRequestSet.SetReadOptimizationMode(eReadOptimizationMode.AUTO)

            myRequestSet.SetWriteOptimizationMode(eWriteOptimizationMode.CROSS_AREAS)

             

             

            'declare a ReadRequest object set the request parameters, 'in this case => read 10 Bytes from DB1 at Byte 0

            Dim myReadDataRequest As ReadDataRequest = New ReadDataRequest(eRegion.DataBlock, _

            1, _

            0, _

            eDataType.[BYTE], _

            10)

             

            'add the read request to the request set

            myRequestSet.AddRequest(myReadDataRequest)

            Dim myWriteRequest As WriteDataRequest = New WriteDataRequest(eRegion.DataBlock, 100, 0)

                           

            'add writable Data here

            'in  this case => write 4 bytes in DB100

            myWriteRequest.addByte(New Byte() { 11, 12, 13, 14 })

             

            'add the write request to the request set

            myRequestSet.AddRequest(myWriteRequest)

             

            '....... add more requests to request set

             

            'read, write and getting the results

            Dim results As ReadWriteResultSet = Device.ReadWriteData(myRequestSet)

             

            'evaluate results

            'evaluate the results of read operations...

            For Each res As ReadDataResult In results.GetReadDataResults()

                

            Next

             

            '...and evaluate the results of write operations

            For Each res As WriteDataResult In results.GetWriteDataResults()

                

            Next

 

        End Sub

    End Class

End Namespace


7. Get basic info from PLC

Imports PLCcom

Public Class newClass

    Private Device As PLCcomDevice

    'see section 'connect' for declare and connect a PLCcom-Device

    Private Sub getGetPLCBasicInfo_Click(sender As Object, e As EventArgs) Handles getGetPLCBasicInfo.Click

        'execute function

        Dim res As BasicInfoResult = Device.GetBasicInfo()

 

        'evaluate results

        txtMessage.Text = (DateTime.Now.ToString() & ": ") + res.Message

        If res.Quality = OperationResult.eQuality.GOOD Then

            Dim sb As New System.Text.StringBuilder()

            sb.Append("Device Name: ")

            sb.Append(res.Name)

            sb.Append(Environment.NewLine)

            sb.Append("Order Number: ")

            sb.Append(res.OrderNumber)

            sb.Append(Environment.NewLine)

            sb.Append("Module Version: ")

            sb.Append(res.ModuleVersion)

            sb.Append(Environment.NewLine)

            sb.Append("Firmware Version: ")

            sb.Append(res.FirmwareVersion)

            sb.Append(Environment.NewLine)

            txtResult.Text = sb.ToString()

            MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Else

            MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If

    End Sub

 

End Class


8. Get mode and state from CPU

Imports PLCcom

Public Class newClass

    Private Device As PLCcomDevice

    'see section 'connect' for declare and connect a PLCcom-Device

    Private Sub btnGetCPUMode_Click(sender As Object, e As EventArgs) Handles btnGetCPUMode.Click

        'execute function

        Dim res As CPUModeInfoResult = Device.GetCPUMode()

 

        'evaluate results

        txtMessage.Text = (DateTime.Now.ToString() & ": ") + res.Message

        If res.Quality = OperationResult.eQuality.GOOD Then

            txtResult.Text = ("CPU Mode = " & res.CPUModeInfo.ToString()) + Environment.NewLine & "CPU State = " & res.CPUStateInfo.ToString()

            MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)

        Else

            MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)

        End If

    End Sub

End Class


Reference : https://www.plccom.net/en/plccom/for-s7/fors7-code-examples/

Memunculkan Simbol & Emoji Pada OS Mac

  Memunculkan Simbol & Emoji  1. Buka aplikasi Pages / Notes pada Macbook. 2. Klik pada Menubar Edit --> Pilih Emoji and Symbols a...