Esempio n. 1
0
 void connect()
 {
     try
     {
         //电表连接
         TcpMeter          = new TCPSGInterface(Constants.METER_IP);
         MeterDataAccessor = new TCPAmmeterData(TcpMeter);
         SmartMeterData    = new CSmartMeterData();
         //数据库连接
         publicSQL = new PublicSQL(UID, PASSWD, DB);
         error     = false;
     }
     catch (Exception e)
     {
         error = true;
         //Console.WriteLine("{0}", e.ToString());
         Console.WriteLine("Connect Fail");
     }
 }
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        ///   public async void ThreadProcAcqSmartMeterData()
        public async void ThreadProcAcqSmartMeterData()
        {
            byte[] bholdregs1 = null;

            TCPSGInterface  meter1       = new TCPSGInterface(Constants.METER_SERVER_IP, context);
            TCPAmmeterData  meterData1   = new TCPAmmeterData(meter1);
            List <LoadData> loadDatalist = new List <LoadData>();

            List <LoadIDResult> loadIDResultListForDisBug = null;
            int currentCount = 0;

            while (meteracqflag)
            {
                try
                {
                    CSmartMeterData csmartMeterData1 = new CSmartMeterData();
                    csmartMeterData1.getActive_Power(meterData1.read_active_Power());
                    csmartMeterData1.getReactive_Power(meterData1.read_Reactive_Power());
                    csmartMeterData1.getCurrent(meterData1.read_current());
                    csmartMeterData1.getVoltage_Vph_n(meterData1.read_voltage_Vph_n());
                    csmartMeterData1.getActive_Energy(meterData1.read_active_Energy());

                    float  activePower1   = csmartMeterData1.smartMeterData.Total_Active_Power_65;
                    float  reactivePower1 = csmartMeterData1.smartMeterData.Reactive_Power_Total_67;
                    float  current1       = csmartMeterData1.smartMeterData.Current_a_13;
                    float  voltage1       = csmartMeterData1.smartMeterData.Voltage_Va_n_1;
                    double activeEnergy1  = csmartMeterData1.smartMeterData.Active_Energy_Import_Tariff_1_801;

                    DateTime dt = DateTime.Now;
                    loadDatalist.Add(new LoadData(activePower1, reactivePower1, dt));
                    currentCount++;
                    LoadIDResult itemtest = new LoadIDResult();
                    if (currentCount == 10)
                    {
                        loadIDResultList = LoadIdentification.handleHisLogDBMethodWindow(loadDatalist);

                        currentCount = 0;

                        loadDatalist = new List <LoadData>();
                    }

                    context.Post((s) =>
                    {
                        //可以在此访问UI线程中的对象,因为代理本身是在UI线程的上下文中执行的
                        TxtAP.Text = String.Format("{0:F}", activePower1) + "W";
                        TxtRP.Text = String.Format("{0:F}", reactivePower1) + "Var";
                        if (currentCount == 0)
                        {
                            if (loadIDResultList.Count > 0)
                            {
                                foreach (LoadIDResult item in loadIDResultList)
                                {
                                    if (currentLoadList.Count > 0)
                                    {
                                        try
                                        {
                                            foreach (LoadIDResult curitem in currentLoadList)
                                            {
                                                if (curitem.Name.Equals(item.Name))
                                                {
                                                    if (item.Event_type != curitem.Event_type)
                                                    {
                                                        currentLoadList.Remove(curitem);
                                                    }
                                                }
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }

                                    if (item.Event_type == EVENT_TYPE.ON)
                                    {
                                        currentLoadList.Add(item);
                                    }
                                }
                            }
                        }
                    }
                                 , null);
                }
                catch
                {
                }
                await Task.Delay(500);
            }
        }