Beispiel #1
0
        private void Catalog2_1(ref DataTable dttPointsValue, DataTable dttPoints, byte[] bReceive, string sIP, int iPort, int iAddress, string sPointID)
        {
            EM3001.EM3001 objEM3001 = new EM3001.EM3001();
            try
            {
                string sTemperatureControlMode = objEM3001.TemperatureControlMode(bReceive[9]);
                float fHHTempereture = BitConverter.ToSingle(bReceive, 13);
                float fHTempereture = BitConverter.ToSingle(bReceive, 17);
                float fLTempereture = BitConverter.ToSingle(bReceive, 21);
                float fLLTempereture = BitConverter.ToSingle(bReceive, 25);
                float fDiffTempereture = BitConverter.ToSingle(bReceive, 29);
                float fInsideOffsetTempereture = BitConverter.ToSingle(bReceive, 33);
                float fOutsideOffsetTempereture = BitConverter.ToSingle(bReceive, 37);
                byte bCoworkerModeDay = bReceive[41];
                byte bAirConditionerModeDay = bReceive[42];
                byte bAirFanerMinTime = bReceive[43];
                byte bAirConditionerMinTime = bReceive[44];
                string sAirConditionerSwapDuty = objEM3001.AirConditionerSwapDuty(bReceive[45]);
                DateTime dtSystem = new DateTime(2000 + bReceive[47], bReceive[48], bReceive[49]
                    , bReceive[50], bReceive[51], bReceive[52]);
                float fHighVoltage = BitConverter.ToSingle(bReceive, 53);
                float fLowVoltage = BitConverter.ToSingle(bReceive, 57);
                float fStopVoltage = BitConverter.ToSingle(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 "temperaturecontrolmode":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sTemperatureControlMode;
                            break;
                        case "hhtempereture":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fHHTempereture.ToString("0.00");
                            break;
                        case "htempereture":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fHTempereture.ToString("0.00");
                            break;
                        case "ltempereture":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fLTempereture.ToString("0.00");
                            break;
                        case "lltempereture":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fLLTempereture.ToString("0.00");
                            break;
                        case "difftempereture":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fDiffTempereture.ToString("0.00");
                            break;
                        case "insideoffsettempereture":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fInsideOffsetTempereture.ToString("0.00");
                            break;
                        case "outsideoffsettempereture":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fOutsideOffsetTempereture.ToString("0.00");
                            break;
                        case "coworkermodeday":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = bCoworkerModeDay;
                            break;
                        case "airconditionermodeday":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = bAirConditionerModeDay;
                            break;
                        case "airfanermintime":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = bAirFanerMinTime;
                            break;
                        case "airconditionermintime":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = bAirConditionerMinTime;
                            break;
                        case "airconditionerswapduty":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = sAirConditionerSwapDuty;
                            break;
                        case "systemtime":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = dtSystem.ToString("yyyy-MM-dd HH:mm:ss.fff");
                            break;
                        case "highvoltage":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fHighVoltage.ToString("0.00"); ;
                            break;
                        case "lowvoltage":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fLowVoltage.ToString("0.00"); ;
                            break;
                        case "stopvoltage":
                            dtwPointsValue = dttPointsValue.NewRow();
                            dtwPointsValue["EquipmentID"] = dtwData["EquipmentID"].ToString();
                            dtwPointsValue["PointID"] = dtwData["PointID"].ToString();
                            dtwPointsValue["PointValue"] = fStopVoltage.ToString("0.00"); ;
                            break;
                        default:
                            g_oLogger.Error("請確認PointID之內容、格式是否正確");
                            break;
                    }
                    dtwPointsValue["RecTime"] = DateTime.Now;
                    dttPointsValue.Rows.Add(dtwPointsValue);
                }
            }
            catch (Exception ex)
            {
                g_oLogger.ErrorException("ModbusTCP.Catalog2_1", ex);
                throw ex;
            }
        }
Beispiel #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;
            }
        }