简体   繁体   中英

How would I get and show graph high frequency data point from PLC S7 with c#?

  1. 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.
  2. 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)
    {

    }

}

Let me tell you, this rate of data isn´t possible by direct reading your plc. The best rate I think you can read direct by your PLC is something about 10~20ms. For high speed monitoring data, you must need a specific DAQ module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM