9. Get or set PLC time
using System;
using PLCcom;
using System.Windows.Forms;
namespace CodeDokuCSharp
{
class newClass
{
PLCcomDevice Device;
//see section 'connect' for declare and connect a PLCcom-Device
#region getPLCClockTime
private void btnGetPLCClockTime_Click(object sender, EventArgs e)
{
//execute function
PLCClockTimeResult res = Device.GetPLCClockTime();
//evaluate results
txtMessage.Text = DateTime.Now.ToString() + ": " + res.Message;
if (res.Quality.Equals(OperationResult.eQuality.GOOD))
{
txtResult.Text = res.PLCClockTime.ToString();
MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
#endregion
#region setPLCClockTime
private void btnSetPLCClockTime_Click(object sender, EventArgs e)
{
//execute function
OperationResult res = Device.SetPLCClockTime(DateTime.Now);
//evaluate results
txtMessage.Text = DateTime.Now.ToString() + ": " + res.Message;
if (res.Quality.Equals(OperationResult.eQuality.GOOD))
{
MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
#endregion
}
}
10. Reading system status list SSL
using System;
using PLCcom;
using System.Windows.Forms;
namespace CodeDokuCSharp
{
class newClass
{
PLCcomDevice Device;
//see section 'connect' for declare and connect a PLCcom-Device
private void btnGetSSL_Click(object sender, EventArgs e)
{
// important!!! please search the id and index information in the plc-documentation
// You must convert the specified values hex in decimal
int SSL_ID = 306; //ID 132 (Hex)
int SSL_Index = 4; //Index 4 (Hex)
//execute function
SystemStatusListResult res = Device.GetSystemStatusList(SSL_ID, SSL_Index);
//evaluate results
txtMessage.Text = DateTime.Now.ToString() + ": " + res.Message;
if (res.Quality == OperationResult.eQuality.GOOD)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
foreach (SystemStatusListResult.SystemStatusListItemEntry ssle in res.SZLItemEntrys)
{
foreach (byte b in ssle.buffer)
{
sb.Append(b.ToString());
sb.Append(" ");
}
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);
}
}
}
}
11. Get diagnostic data
using System;
using PLCcom;
using System.Windows.Forms;
namespace CodeDokuCSharp
{
class newClass
{
PLCcomDevice Device;
//see section 'connect' for declare and connect a PLCcom-Device
private void btnDiagnosticInfo_Click(object sender, EventArgs e)
{
//read the diagnosticinfo into DiagnosticInfoResult-object
//execute function
DiagnosticInfoResult res = Device.GetDiagnosticInfo();
//evaluate results
txtMessage.Text = DateTime.Now.ToString() + ": " + res.Message;
if (res.Quality == OperationResult.eQuality.GOOD)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
//step through the entries
foreach (DiagnosticInfoEntry myDiagnosticInfoEntry 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);
}
txtResult.Text = sb.ToString();
MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
12. Send password
using System;
using PLCcom;
using System.Windows.Forms;
namespace CodeDokuCSharp
{
class newClass
{
PLCcomDevice Device;
//see section 'connect' for declare and connect a PLCcom-Device
private void btnSendPW_Click(object sender, EventArgs e)
{
OperationResult res = Device.sendPassWord("EnterPW");
//evaluate results
txtMessage.Text = DateTime.Now.ToString() + ": " + res.Message;
if (res.Quality == OperationResult.eQuality.GOOD)
{
MessageBox.Show("OK", "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show(res.Message, "Result:", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}
Reference : https://www.plccom.net/en/plccom/for-s7/fors7-code-examples/