Ejemplo n.º 1
0
        private void Catalog1(ref DataTable dttPointsValue, DataTable dttPoints, byte[] bReceive, string sIP, int iPort, int iAddress, string sPointID)
        {
            EM3001.EM3001 objEM3001 = new EM3001.EM3001();
            try
            {
                float fInsideTemperature = BitConverter.ToSingle(bReceive, 9);
                float fOutsideTemperature = BitConverter.ToSingle(bReceive, 13);
                float fInsideWet = BitConverter.ToSingle(bReceive, 17);
                float fOutsideWet = BitConverter.ToSingle(bReceive, 21);
                float fAirAmpere = BitConverter.ToSingle(bReceive, 25);
                float fVoltage48 = BitConverter.ToSingle(bReceive, 29);
                string sFireAlarm = objEM3001.ConvertToBinary(bReceive[33])[3];
                string sHeatExchangerAlarm = objEM3001.ConvertToBinary(bReceive[33])[2];
                string sAirAlarm = objEM3001.ConvertToBinary(bReceive[33])[1];
                string sStifledAlarm = objEM3001.ConvertToBinary(bReceive[33])[0];
                string sFanSwitch = objEM3001.ConvertToBinary(bReceive[37])[3];
                string sAlarmSwitch = objEM3001.ConvertToBinary(bReceive[37])[2];
                string sAirASwitch = objEM3001.ConvertToBinary(bReceive[37])[1];
                string sAirBSwitch = objEM3001.ConvertToBinary(bReceive[37])[0];
                string sAO = objEM3001.AnalogOutput(bReceive[41]);
                byte bControlMode = bReceive[45];
                UInt32 uiSystemWorkingHour = BitConverter.ToUInt32(bReceive, 49);
                UInt32 uiAirFanerWorkingHour = BitConverter.ToUInt32(bReceive, 53);
                UInt32 uiAirConditionerAWorkingHour = BitConverter.ToUInt32(bReceive, 57);
                UInt32 uiAirConditionerBWorkingHour = BitConverter.ToUInt32(bReceive, 61);

                DataRow[] dtwPoint = SelectPoints(dttPoints, sIP, iPort, iAddress, sPointID);
                if (dtwPoint.Length == 0)
                {
                    g_oLogger.Trace(string.Format("請確認點位資料- {0}:{1}:{2}", sIP, iPort, iAddress));
                    return;
                }
                foreach (DataRow dtwData in dtwPoint)
                {
                    DataRow dtwPointsValue = null;
                    switch (dtwData["PointID"].ToString().Split('.')[dtwData["PointID"].ToString().Split('.').Length -1].ToLower())
                    {

                        case "insidetemperature":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fInsideTemperature.ToString("0.00");
                            break;
                        case "outsidetemperature":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fOutsideTemperature.ToString("0.00");
                            break;
                        case "insidewet":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fInsideWet.ToString("0.00");
                            break;
                        case "outsidewet":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fOutsideWet.ToString("0.00");
                            break;
                        case "airampere":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fAirAmpere.ToString("0.00");
                            break;
                        case "voltage48":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fVoltage48.ToString("0.00");
                            break;
                        case "firealarm":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sFireAlarm;
                            break;
                        case "heatexchangeralarm":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sHeatExchangerAlarm;
                            break;
                        case "airalarm":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAirAlarm;
                            break;
                        case "stifledalarm":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sStifledAlarm;
                            break;
                        case "fanswitch":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sFanSwitch;
                            break;
                        case "alarmswitch":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAlarmSwitch;
                            break;
                        case "airaswitch":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAirASwitch;
                            break;
                        case "airbswitch":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAirBSwitch;
                            break;
                        case "analogoutput":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAO;
                            break;
                        case "controlmode":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = objEM3001.ControlMode(bControlMode);
                            break;
                        case "systemworkinghour":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = uiSystemWorkingHour;
                            break;
                        case "airfanerworkinghour":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = uiAirFanerWorkingHour;
                            break;
                        case "airconditioneraworkinghour":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = uiAirConditionerAWorkingHour;
                            break;
                        case "airconditionerbworkinghour":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = uiAirConditionerBWorkingHour;
                            break;
                        default:
                            g_oLogger.Error("請確認PointID之內容、格式是否正確");
                            break;
                    }
                    dtwPointsValue["RecTime"] = DateTime.Now;
                    dttPointsValue.Rows.Add(dtwPointsValue);
                }
            }
            catch (Exception ex)
            {
                g_oLogger.ErrorException("ModbusTCP.Catalog1", ex);
                throw ex;
            }
        }
Ejemplo n.º 2
0
        private void StatusLog(ref DataTable dttPointsValue, DataTable dttPoints, byte[] bReceive, string sIP, int iPort, int iAddress, string sPointID)
        {
            EM3001.EM3001 objEM3001 = new EM3001.EM3001();
            try
            {
                byte bEventType = bReceive[9];
                DateTime dtRecTime = new DateTime(2000 + bReceive[11], bReceive[12], bReceive[13], bReceive[14], bReceive[15], bReceive[16]);
                int iOutsideTemperature = BitConverter.ToInt16(bReceive, 17) / 10;
                int iInsideTemperature = BitConverter.ToInt16(bReceive, 19) / 10;
                int iVoltage48 = BitConverter.ToInt16(bReceive, 27) / 10;
                string sFireAlarm = objEM3001.ConvertToBinary(bReceive[29])[3];
                string sHeatExchangerAlarm = objEM3001.ConvertToBinary(bReceive[29])[2];
                string sAirAlarm = objEM3001.ConvertToBinary(bReceive[29])[1];
                string sStifledAlarm = objEM3001.ConvertToBinary(bReceive[29])[0];
                string sFanSwitch = objEM3001.ConvertToBinary(bReceive[30])[3];
                string sAlarmSwitch = objEM3001.ConvertToBinary(bReceive[30])[2];
                string sAirASwitch = objEM3001.ConvertToBinary(bReceive[30])[1];
                string sAirBSwitch = objEM3001.ConvertToBinary(bReceive[30])[0];
                //string sAO = objEM3001.AnalogOutput(bReceive[31]);
                string sTemperatureControlMode = objEM3001.TemperatureControlMode(bReceive[32]);
                string sTemperatureControlDays = objEM3001.AssociateDays(bReceive[33]);
                string sAirAssociateDays = objEM3001.AirAssociateDays(bReceive[34]);
                string sSDState = objEM3001.SDState(bReceive[35]);

                DataRow[] dtwPoint = SelectPoints(dttPoints, sIP, iPort, iAddress, sPointID);
                if (dtwPoint.Length == 0)
                {
                    g_oLogger.Trace(string.Format("請確認點位資料- {0}:{1}", sIP, iPort));
                    return;
                }
                foreach (DataRow dtwData in dtwPoint)
                {
                    DataRow dtwPointsValue = null;
                    switch (dtwData["PointID"].ToString().Split('.')[dtwData["PointID"].ToString().Split('.').Length - 1].ToLower())
                    {
                        case "eventtype":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = objEM3001.EventType(bEventType);
                            break;
                        case "outsidetemperature":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = iOutsideTemperature.ToString("0.00");
                            break;
                        case "insidetemperature":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = iInsideTemperature.ToString("0.00");
                            break;
                        case "voltage48":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = iVoltage48.ToString("0.00");
                            break;
                        case "firealarm":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sFireAlarm;
                            break;
                        case "heatexchangeralarm":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sHeatExchangerAlarm;
                            break;
                        case "airalarm":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAirAlarm;
                            break;
                        case "stifledalarm":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sStifledAlarm;
                            break;
                        case "fanswitch":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sFanSwitch;
                            break;
                        case "alarmswitch":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAlarmSwitch;
                            break;
                        case "airaswitch":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAirASwitch;
                            break;
                        case "airbswitch":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAirBSwitch;
                            break;
                        case "temperaturecontrolmode":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sTemperatureControlMode;
                            break;
                        case "temperaturecontroldays":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sTemperatureControlDays;
                            break;
                        case "airassociatedays":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAirAssociateDays;
                            break;
                        case "sdstate":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sSDState;
                            break;
                        default:
                            break;
                    }
                    dtwPointsValue["RecTime"] = dtRecTime;
                    dttPointsValue.Rows.Add(dtwPointsValue);
                }
            }
            catch (Exception ex)
            {
                g_oLogger.ErrorException("ModbusTCP.StatusLog", ex);
                throw ex;
            }
        }