9. Get or set PLC time
Imports PLCcom
Public Class newClass
Private Device As PLCcomDevice
'see section 'connect' for declare and connect a PLCcom-Device
#Region "getPLCClockTime"
Private Sub btnGetPLCClockTime_Click(sender As Object, e As EventArgs) Handles btnGetPLCClockTime.Click
'execute function
Dim res As PLCClockTimeResult = Device.GetPLCClockTime()
'evaluate results
txtMessage.Text = (DateTime.Now.ToString() & ": ") + res.Message
If res.Quality.Equals(OperationResult.eQuality.GOOD) Then
txtResult.Text = res.PLCClockTime.ToString()
MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
#End Region
#Region "setPLCClockTime"
Private Sub btnSetPLCClockTime_Click(sender As Object, e As EventArgs) Handles btnSetPLCClockTime.Click
'execute function
Dim res As OperationResult = Device.SetPLCClockTime(DateTime.Now)
'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 Region
End Class
10. Reading system status list SSL
Imports PLCcom
Public Class newClass
Private Device As PLCcomDevice
'see section 'connect' for declare and connect a PLCcom-Device
Private Sub btnGetSSL_Click(sender As Object, e As EventArgs) Handles btnGetSSL.Click
' important!!! please search the id and index information in the plc-documentation
' You must convert the specified values hex in decimal
Dim SSL_ID As Integer = 306
'ID 132 (Hex)
Dim SSL_Index As Integer = 4
'Index 4 (Hex)
'execute function
Dim res As SystemStatusListResult = Device.GetSystemStatusList(SSL_ID, SSL_Index)
'evaluate results
txtMessage.Text = (DateTime.Now.ToString() & ": ") + res.Message
If res.Quality = OperationResult.eQuality.GOOD Then
Dim sb As New System.Text.StringBuilder()
For Each ssle As SystemStatusListResult.SystemStatusListItemEntry In res.SZLItemEntrys
For Each b As Byte In ssle.buffer
sb.Append(b.ToString())
sb.Append(" ")
Next
sb.Append(Environment.NewLine)
Next
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
11. Get diagnostic data
Imports PLCcom
Public Class newClass
Private Device As PLCcomDevice
'see section 'connect' for declare and connect a PLCcom-Device
Private Sub btnDiagnosticInfo_Click(sender As Object, e As EventArgs) Handles btnDiagnosticInfo.Click
'read the diagnosticinfo into DiagnosticInfoResult-object
'execute function
Dim res As DiagnosticInfoResult = Device.GetDiagnosticInfo()
'evaluate results
txtMessage.Text = (DateTime.Now.ToString() & ": ") + res.Message
If res.Quality = OperationResult.eQuality.GOOD Then
Dim sb As New System.Text.StringBuilder()
'step through the entries
For Each myDiagnosticInfoEntry As DiagnosticInfoEntry In res.DiagnosticInfoEntrys
sb.Append("Timestamp: " & myDiagnosticInfoEntry.DiagnosticTimestamp.ToString())
sb.Append(" ")
sb.Append("ID: " & myDiagnosticInfoEntry.DiagnosticID.ToString())
sb.Append(" ")
sb.Append("Message: " + myDiagnosticInfoEntry.DiagnosticText)
sb.Append(Environment.NewLine)
Next
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
12. Send password
Imports PLCcom
Public Class newClass
Private Device As PLCcomDevice
'see section 'connect' for declare and connect a PLCcom-Device
Private Sub btnSendPW_Click(sender As Object, e As EventArgs) Handles btnSendPW.Click
Dim res As OperationResult = Device.sendPassWord("EnterPW")
'evaluate results
txtMessage.Text = (DateTime.Now.ToString() & ": ") + res.Message
If res.Quality = 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
Reference : https://www.plccom.net/en/plccom/for-s7/fors7-code-examples/