如何使用c#从PLC S7获取并显示图形高频数据点


  1. 我的项目必须以高采样率(大约1000个样本/秒(进行监控。我使用S7_通信协议。我没有理想的方法(1000个样本/秒(。也许我想我会创建一个1ms的计时器,每秒获取1个样本。但是有2000个样本,我不知道怎么做
  2. 实时显示图表。我想展示我从PLC得到的所有观点。并将其显示为高样本(1000样本/秒(的图形(自动滚动(

你给我一些概念吗?我使用s7.net lib在PLC和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)
{
}
}

让我告诉你,这种数据速率是不可能通过直接读取您的plc来实现的。我认为你可以通过PLC直接读取的最佳速率大约是10~20ms。对于高速监控数据,您必须需要一个特定的DAQ模块。

最新更新