private static void ReadPLC() { try { Plc plc = PLCSingleton.CreatePLC(CpuType.S7300, "10.21.189.139", 0, 2); //new Plc(CpuType.S7300, "10.21.189.139", 0, 2); plc.Open(); UInt32 str = (UInt32)plc.Read(DataType.DataBlock, 181, 0, VarType.DWord, 1); Console.WriteLine("Status " + str.ToString()); str = (UInt32)plc.Read(DataType.DataBlock, 181, 4, VarType.DWord, 1); Console.WriteLine("Operation " + str.ToString()); str = (UInt32)plc.Read(DataType.DataBlock, 181, 8, VarType.DWord, 1); Console.WriteLine("Program " + str.ToString()); str = (UInt32)plc.Read(DataType.DataBlock, 181, 12, VarType.DWord, 1); Console.WriteLine("First alarm " + str.ToString()); str = (UInt32)plc.Read(DataType.DataBlock, 181, 16, VarType.DWord, 1); Console.WriteLine("Current message " + str.ToString()); plc.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public static void GetFirstDataFromPLC() { try { UInt32 str = 0; ArrayList list = null; string openstr = "OK"; object readobj = null; PLCHisData plchis = null; foreach (var adapter in RowConfig.EqpPoint) { list = adapter.Value; if (list != null) { RowDataPoint eqp = (RowDataPoint)list[0]; Plc plc = PLCSingleton.CreatePLC(CpuType.S7300, eqp.IP, 0, 2); //new Plc(CpuType.S7300, "10.21.189.139", 0, 2); try { openstr = plc.QMOpen(); if (openstr == "OK") { foreach (var V in list) { eqp = (RowDataPoint)V; try { readobj = plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1); // str = (UInt32)plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1); if (readobj != null) { str = (UInt32)readobj; plchis = FrontData.dic[eqp.TagID]; plchis.Value = str; plchis.TagID = eqp.TagID; plchis.type = RowConfig.TagDic[plchis.TagID].type; plchis.refid = DTKAG.KAGCreateNewDT(eqp.TagID, plchis.type, str); plchis.Time = DateTime.Now; if (eqp.TagID == EqpName.FillerStatusTagID) { plchis.formid = PersisDTFiller.CL1NewDTFiller("", "", "", str); } } } catch (Exception ex) { Log.Error(ex.ToString()); } } plc.Close(); } else { SetEQPRealDataMax(eqp.EQP); Log.Error("[PLC][Link Fail] IP Address is : " + eqp.IP); Log.Error(openstr); } // throw new InvalidAddressException("To few periods for DB address"); } catch (Exception ex) { Log.Error(ex.ToString()); } } } } catch (Exception ex) { Log.Error(ex.ToString()); } }
public static void GetDataFromPLC() { try { UInt32 str = 0; ArrayList list = null; string openstr = "OK"; object readobj = null; foreach (var adapter in RowConfig.EqpPoint) { list = adapter.Value; if (list != null) { RowDataPoint eqp = (RowDataPoint)list[0]; Plc plc = PLCSingleton.CreatePLC(CpuType.S7300, eqp.IP, 0, 2); //new Plc(CpuType.S7300, "10.21.189.139", 0, 2); try { openstr = plc.QMOpen(); if (openstr == "OK") { foreach (var V in list) { eqp = (RowDataPoint)V; try { readobj = plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1); // str = (UInt32)plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1); if (readobj != null) { str = (UInt32)readobj; RealData.dic[eqp.TagID] = str; Console.WriteLine(eqp.TagID + " Value is: " + str); } } catch (Exception ex) { Log.Error(ex.ToString()); } } } else { SetEQPRealDataMax(eqp.EQP); Log.Error("[PLC][Link Fail] IP Address is : " + eqp.IP); Log.Error(openstr); } // throw new InvalidAddressException("To few periods for DB address"); plc.Close(); } catch (Exception ex) { Log.Error(ex.ToString()); } } } } catch (Exception ex) { Log.Error(ex.ToString()); } }