コード例 #1
0
        private static void GetDicPLCData()
        {
            try
            {
                uint         str;
                RowDataPoint point   = null;
                string       openstr = "OK";
                object       readobj = null;
                RowDataPoint eqp     = null;
                foreach (var adapter in DicStatus)
                {
                    point = adapter.Value;
                    if (point != null)
                    {
                        Plc plc = OEMPLC.CreatePLC(CpuType.S7300, adapter.Key, 0, 2);    //new Plc(CpuType.S7300, "10.21.189.139", 0, 2);

                        try
                        {
                            openstr = plc.QMOpen();
                            if (openstr == "OK")
                            {
                                try
                                {
                                    readobj = plc.QMRead((DataType)point.datatype, point.dbNumber, point.startByte, (VarType)point.vartype, 1);
                                    // str = (UInt32)plc.QMRead((DataType)eqp.datatype, eqp.dbNumber, eqp.startByte, (VarType)eqp.vartype, 1);
                                    if (readobj != null)
                                    {
                                        str = Convert.ToUInt16(readobj);
                                        Console.WriteLine("OEM PLC Data " + adapter.Key + "  " + str);
                                        DicReal[adapter.Key] = str;
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Log.Error(ex.ToString());
                                }
                            }
                            else
                            {
                                DicReal[adapter.Key] = uint.MaxValue;

                                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());
            }
        }
コード例 #2
0
        private static void GetPLCData()
        {
            try
            {
                uint         str;
                ArrayList    list    = null;
                string       openstr = "OK";
                object       readobj = null;
                RowDataPoint eqp     = null;
                foreach (var adapter in OEMPoint)
                {
                    list = adapter.Value;
                    if (list != null)
                    {
                        Plc plc = OEMPLC.CreatePLC(CpuType.S7300, adapter.Key, 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 = Convert.ToUInt16(readobj);


                                            Console.WriteLine(eqp.TagID + " OEM  Value is: " + str);
                                            Log.Info("[OEM]" + eqp.TagID + "  " + str);
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Log.Error(ex.ToString());
                                    }
                                }
                            }
                            else
                            {
                                if (adapter.Key == IP1)
                                {
                                    SetOEM1EX();
                                }
                                else
                                {
                                    SetOEM2EX();
                                }

                                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());
            }
        }