- My project have to monitoring with high sample rate (about 1000 sample / second). I use S7_communication protocol. I don't have ideal to get it (1000sample/second). Maybe I think I will create a timer 1ms to get 1 sample per second. But with 2000 sample, I don't know how to do it.
- Show chart real-time. I wanna show all point that I got from PLC. And show that to graph (auto scroll) with high sample (1000 sample /second).
Do you give me some concept to do it? I use s7.net lib to communicate between PLC and myPC
Plc plc = null;
plc = new Plc(CpuType.S71200, "192.168.0.1", 0, 1);
public initPLC()
{
try
{
plc.Open();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void setTimer(double value)
{
aTimer = new System.Timers.Timer(value);
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
aTimer.Enabled = true;
}
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
if (plc.IsConnected)
{
RefreshValue();
}
}
private void RefreshValue()
{
ushort value1 = 0;
ushort value2 = 0;
bool[] tagArr = { false, false, false, false };
try
{
value1 = (ushort)plc.Read("DB4.DBW0"); //value1
tagArr[0] = true;
}
catch (Exception)
{
tagArr[0] = false;
}
//func
try
{
value2 = (ushort)plc.Read("DB4.DBW2"); //value2
tagArr[1] = true;
}
catch (Exception)
{
tagArr[1] = false;
}
try
{
bool _bit = (bool)plc.Read(DataType.Input, 0, 0, VarType.Bit, 1);
}
catch (Exception)
{
}
}