예제 #1
0
        /// <summary>
        /// 获取太阳能状态信息
        /// </summary>
        /// <param name="sendSolarEnergyStatus"></param>
        public void Query_SolarEnergyStatus_Info(Action <string> sendSolarEnergyStatus)
        {
            if (deviceInfo == null)
            {
                return;
            }
            StationList station = deviceInfo.StationList.Find(_ => _.PStationID == null);

            if (station == null)
            {
                return;
            }
            solarEnergyStatusList.Clear();

            LogServerManager.AddRunLog(OperationType.System, "查询本级太阳能状态");
            List <SolarEnergyList> solarEnergyList = deviceInfo.SolarEnergyList.FindAll(_ => _.CommunicationID.HasValue && _.CommunicationType == 1 && _.StationID == station.StationID);
            int mreCount = solarEnergyList.Count;
            MutipleThreadResetEvent tempMre = new MutipleThreadResetEvent(mreCount);

            solarEnergymre = tempMre;
            foreach (var item in solarEnergyList)
            {
                Guid SerialComID = item.CommunicationID.Value;
                //TODO:太阳能获取命令;
            }

            solarEnergymre.WaitAll(2000);
            #region 测试数据
            SolarEnergyStatusList solarEnergyStatus = new SolarEnergyStatusList();
            solarEnergyStatus.ID           = 1;
            solarEnergyStatus.DeviceID     = deviceInfo.SolarEnergyList.Find(_ => _.StationID == station.StationID).DeviceID;
            solarEnergyStatus.Name         = deviceInfo.SolarEnergyList.Find(_ => _.StationID == station.StationID).Name;
            solarEnergyStatus.Alarm        = 1;
            solarEnergyStatus.Humi         = "30";
            solarEnergyStatus.Resistance   = "220";
            solarEnergyStatus.SolarCurrent = "10";
            solarEnergyStatus.Time         = DateTime.Now;
            solarEnergyStatus.Temp         = "30";
            solarEnergyStatus.Voltage      = "220";
            solarEnergyStatusList.Add(solarEnergyStatus);
            #endregion

            string jsonContent = JsonConvert.SerializeObject(solarEnergyStatusList);
            sendSolarEnergyStatus(jsonContent);
            solarEnergymre.Dispose();
        }
예제 #2
0
        /// <summary>
        /// 获取UPS状态信息
        /// </summary>
        /// <param name="sendUPSStatus"></param>
        public void Query_UPSStatus_Info(Action <string> sendUPSStatus)
        {
            if (deviceInfo == null)
            {
                return;
            }
            StationList station = deviceInfo.StationList.Find(_ => _.PStationID == null);

            if (station == null)
            {
                return;
            }
            UPSStatusList.Clear();

            LogServerManager.AddRunLog(OperationType.System, "查询本级UPS状态");
            //Dictionary<Guid, SerialPort> SerialPortDic = serialCOMManager.GetSerialPortDic();
            List <UPSList>          UPSList  = deviceInfo.UPSList.FindAll(_ => _.CommunicationID.HasValue && _.CommunicationType == 1 && _.StationID == station.StationID);
            int                     mreCount = UPSList.Count;
            MutipleThreadResetEvent tempMre  = new MutipleThreadResetEvent(mreCount);

            upsmre = tempMre;
            foreach (var item in UPSList)
            {
                string falseMsg    = string.Empty;
                Guid   SerialComID = item.CommunicationID.Value;
                //if (!SerialPortDic.Keys.Contains(SerialComID))
                //    continue;
                //SerialPort sp = SerialPortDic[SerialComID];
                //try
                //{
                //    if (!sp.IsOpen)
                //    {
                //        sp.ReadBufferSize = 4096;//输入缓冲区大小
                //        sp.WriteBufferSize = 2048;//输出缓冲区大小
                //        sp.ReceivedBytesThreshold = 42;//081完整数据长度为42,所以设置阈值为42
                //        sp.DataReceived += SerialPort_UPS_DataReceived;
                //        sp.Open();

                //        byte[] buffer = Encoding.Default.GetBytes("Q1\r\n");
                //        sp.Write(buffer, 0, buffer.Length);
                //    }
                //}
                //catch
                //{
                //    sp.Close();
                //}
                byte[] buffer = Encoding.Default.GetBytes("Q1\r\n");
                serialCOMManager.WriteSerialCOM(SerialComID, buffer, out falseMsg);
            }

            upsmre.WaitAll(2000);
            #region 测试数据
            //UPSStatusList UPSStatus = new UPSStatusList();
            //UPSStatus.ID = 1;
            //UPSStatus.DeviceID = deviceInfo.UPSList.Find(_ => _.StationID == station.StationID).DeviceID;
            //UPSStatus.Name = deviceInfo.UPSList.Find(_ => _.StationID == station.StationID).Name;
            //UPSStatus.InVoltage = "220";
            //UPSStatus.LVoltage = "220";
            //UPSStatus.OutVoltage = "220";
            //UPSStatus.OutputLoad = "80";
            //UPSStatus.Freq = "9600";
            //UPSStatus.CellVoltage = "220";
            //UPSStatus.Temperature = "30";
            //UPSStatus.Alarm = "00000000";
            //UPSStatus.Time = DateTime.Now.ToString();
            //UPSStatusList.Add(UPSStatus);
            #endregion
            string jsonContent = JsonConvert.SerializeObject(UPSStatusList);
            sendUPSStatus(jsonContent);
            upsmre.Dispose();
            upsmre = null;
        }