。
你能给我一些概念来做吗?我使用s7.netlib在myPC和PLC之间进行通信
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)
{
}
}发布于 2022-02-16 13:44:10
让我告诉你,这样的数据率是不可能通过直接阅读您的plc。我认为你能用PLC直接阅读的最好的速度是大约10~20毫秒。对于高速监控数据,您必须需要一个特定的DAQ模块。
https://stackoverflow.com/questions/70844755
复制相似问题