public SerialDF1forSLCMicroCom m_plc = new SerialDF1forSLCMicroCom();
public event EventHandler<CameraResultsEventArgs> ResultsAvailable;
System.Windows.Threading.DispatcherTimer plcPoll = new System.Windows.Threading.DispatcherTimer();
public void Read()
{
m_plc.Write("N7:0", "100");
m_plc.Write("N7:14", "100");
m_plc.Write("N7:15", "100");
m_plc.Write("N7:16", "100");
plcPoll.Interval = TimeSpan.FromMilliseconds(100);
plcPoll.IsEnabled = true;
plcPoll.Tick += plcPoll_Tick;
m_plc.DataReceived += m_plc_DataRecieved;
plcPoll.Start();
}
void plcPoll_Tick(object sender, EventArgs e)
{
m_plc.BeginRead("N7:0", 17);
//m_plc.BeginRead("C5:0.ACC", 7);
}
void m_plc_DataRecieved(object sender, MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs e)
{
CamCollection values = new CamCollection();
try
{
if (e.PlcAddress == "N7:0" && e.Values.Count == 17)
{
values.Camera1.Trigger = e.Values[0];
values.Camera1.CurInspectionTime = e.Values[4];
values.Camera1.MaxInspectionTime = e.Values[3];
values.Camera2.Trigger = e.Values[14];
values.Camera2.MaxInspectionTime = e.Values[6];
values.Camera2.CurInspectionTime = e.Values[7];
values.Camera4.Trigger = e.Values[16];
values.Camera4.CurInspectionTime = e.Values[13];
values.Camera4.MaxInspectionTime = e.Values[12];
values.Camera3.Trigger = e.Values[15];
values.Camera3.CurInspectionTime = e.Values[10];
values.Camera3.MaxInspectionTime = e.Values[9];
if (ResultsAvailable != null)
ResultsAvailable(this, new CameraResultsEventArgs { Camera1 = values.Camera1, Camera2 = values.Camera2, Camera3 = values.Camera3, Camera4 = values.Camera4 });
}
}
catch (Exception ex)
{
MessageBox.Show(String.Format("Error reading nValues: {0}", ex.ToString()));
plcPoll.Stop();
}
That's the part of code where is reading done.