// 链接
private void plcDeviceLink(string plcCom)
{
try
{
plc = new SiemensS7Net(SiemensPLCS.S200Smart, plcCom);
Boolean connectFlag = plc.ConnectServer().IsSuccess;
if (connectFlag)
{
isPLCConnected = true;
}
else
{
isPLCConnected = false;
}
}
catch (Exception ex)
{
UIMessageBox.ShowError("PLC连接失败:" + ex.Message);
}
}
// 读取数据,保存在栈中,并画在曲线上
private void serialPort_OxygenCheck_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
if (isWorking)
{
Thread.Sleep(50);
SerialPort sp = (SerialPort)sender;
string readStr = sp.ReadExisting();
stack.Push(readStr);
string[] readArr = readStr.Split(' ');
if (readArr.Length >= 19)
{
productIndex++;
string isOKStr = readStr.Split(' ')[3];
bool isOk = Convert.ToInt32(isOKStr) == 1 ? true : false;
if (isOk)
{
okNumber++;
}
else
{
ngNumber++;
}
//int totalNumber = okNumber + ngNumber;
pointX.Add(productIndex);
string testValue = readArr[8];
if (!testValue.IsDouble())
{
testValue = "0.00";
}
pointY.Add(Convert.ToDouble(testValue));
if(Convert.ToDouble(testValue) >= biggestValue)
{
biggestValue = Convert.ToDouble(testValue) + 1;
}
if(productIndex >= xBiggestValue)
{
xBiggestValue = productIndex + 50;
}
Invoke((EventHandler)delegate
{
lab_ProductCount.Text = productIndex.ToString();
uiLabel8.Text = okNumber.ToString();
uiLabel9.Text = ngNumber.ToString();
uiLabel14.Text = ((double)okNumber / (double)productIndex).ToString("F2");
});
Thread thread = new Thread(ResetData);
thread.IsBackground = true;
thread.Start();
}
}
}
catch(Exception ex)
{
UIMessageBox.ShowError(ex.Message);
}
}
11-27
3万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
03-12
3089
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-11
2047
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-22
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交