using HslCommunication.Profinet.Siemens; using iWare_SCADA_BusinessLogical.BLL; using iWare_SCADA_BusinessLogical.Utils; using iWare_SCADA_Model; using Newtonsoft.Json.Linq; using Spire.Pdf.HtmlConverter; using System; using System.Collections.Generic; using System.Data.Entity.Core.Common.CommandTrees; using System.Data.Entity.Validation; using System.Data.SqlTypes; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace iWare_SCADA_BusinessLogical { /// /// 测试内容 /// public class MyTest { public static readonly MyTest Instance = new MyTest(); string WorkingProcedure = ""; public MyTest() { } public void DataCaptureStart() { DataCaptureConfig _dataCaptureConfig = new DataCaptureConfig() { DataCapturePLCType = (int)SiemensPLCS.S1200, PLCIP = "192.168.216.5", PLCPort = 102, DbNumber = "1141", Offset = "746.0", DataCaptureColumnType = "string" }; var plcService = PLCManger.GetSinglePLCService(_dataCaptureConfig); if (plcService == null) { SystemValue.lbl_Alert_HMIBeartBeatMonitor = $"{RandomHelper.GenerateRandomCode(4)} 没有找到{_dataCaptureConfig.WorkingProcedure}的PLC设备"; return; } if (plcService != null && !plcService.IsConnected) { plcService.Close(); plcService.OpenService(); } var str = $"读取OP35上线二维码"; var str2 = $"读取OP35下线二维码"; Dictionary beartBeatDic = new Dictionary(); beartBeatDic.Add(false, DateTime.Now); bool BeartBeatMonitorflag = true; while (true) { try { //_dataCaptureConfig if (plcService == null || !plcService.IsConnected) { SystemValue.lbl_Alert_HMIBeartBeatMonitor = $" {RandomHelper.GenerateRandomCode(4)} {_dataCaptureConfig.WorkingProcedure} PLC连接已断开,正在尝试打开!"; plcService.Close(); plcService.OpenService(); Thread.Sleep(100); continue; } else { try {//获取设备plc的心跳 var value = plcService.ReadValuePoint(_dataCaptureConfig.DbNumber, _dataCaptureConfig.Offset, PLCManger.GetTypeForString(_dataCaptureConfig.DataCaptureColumnType)); Log4NetHelper.WriteInfoLog(LogType.FormMain, str + $",值:{value}"); var value2 = plcService.ReadValuePoint("4", "920.0", PLCManger.GetTypeForString("string")); Log4NetHelper.WriteInfoLog(LogType.FormMain, str2 + $",值:{value2}"); var str3 = $"读取OP35 SPC二维码"; var value3 = plcService.ReadValuePoint("4", "716.0", PLCManger.GetTypeForString("string")); Log4NetHelper.WriteInfoLog(LogType.FormMain, str3 + $",值:{value3}"); var str4 = $"读取OP35 OP3502A测量二维码"; var value4 = plcService.ReadValuePoint("2901", "514.0", PLCManger.GetTypeForString("string")); Log4NetHelper.WriteInfoLog(LogType.FormMain, str4 + $",值:{value4}"); var str5 = $"读取OP35 NOOK推出二维码"; var value5 = plcService.ReadValuePoint("4", "818", PLCManger.GetTypeForString("string")); Log4NetHelper.WriteInfoLog(LogType.FormMain, str5 + $",值:{value5}"); } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, str + $",读取异常1:", ex); } } } catch (Exception ex) { Log4NetHelper.WriteErrorLog(LogType.FormMain, str + $",异常:", ex); } finally { Thread.Sleep(1000); } } } } }