Esempio n. 1
0
        static public AOUStateData GetRandomStateData(uint time_ms)
        {
            AOUStateData stateData;

            AOUDataTypes.Time_ms_to_AOUModelTimeSecX10(time_ms, out stateData.time_hours, out stateData.time_sek_x_10_of_hour);

            stateData.UIButtons = 0;  stateData.Mode = 0; stateData.IMM = 0;  stateData.Valves = 0;
            stateData.seqState  = 0;   stateData.Power = 0; stateData.Energy = 0;

            /* Only temperature values will be set */
            stateData.bufHotTemp  = RealToWordX100(ValueGenerator.GetTBufferHotValue());
            stateData.bufMidTemp  = RealToWordX100(ValueGenerator.GetTBufferMidValue());
            stateData.bufColdTemp = RealToWordX100(ValueGenerator.GetTColdTankValue());

            stateData.coldTankTemp = RealToWordX100(ValueGenerator.GetTColdTankValue());
            stateData.hotTankTemp  = RealToWordX100(ValueGenerator.GetTHotTankValue());
            stateData.retTemp      = RealToWordX100(ValueGenerator.GetTReturnValveValue());

            stateData.coolerTemp = RealToWordX100(ValueGenerator.GetValveCoolantValue());
            stateData.heaterTemp = RealToWordX100(ValueGenerator.GetTheaterOilOutValue());

            stateData.BearHot = RealToWordX100(ValueGenerator.GetTHotTankValue());

            return(stateData);
        }
        /*
         * public static bool ParseWordTime(string textline, out UInt16 time_min_of_week, out UInt16 time_ms_of_min)
         * {
         *  long time_ms = 0;
         *  if (ParseLong(tagSubTagTime, textline, out time_ms))
         *  {
         *      if (time_ms > 283200)
         *      {
         *          long t2 = time_ms;
         *      }
         *      AOUDataTypes.AOUModelTimeSecX10_to_TimeMs(time_ms, out time_min_of_week, out time_ms_of_min);
         *      return true;
         *  }
         *  else
         *  {
         *      time_min_of_week = 0;
         *      time_ms_of_min = 0;
         *      return false;
         *  }
         * }
         */

        public static bool ParseWordTime_sek_x_10(string textline, out UInt16 time_hours, out UInt16 time_sek_x_10)
        {
            long time_s_x_10 = 0;

            if (ParseLong(tagSubTagTime, textline, out time_s_x_10))
            {
                AOUDataTypes.Time_ms_to_AOUModelTimeSecX10(time_s_x_10 * 100, out time_hours, out time_sek_x_10);
                return(true);
            }
            else
            {
                time_sek_x_10 = 0;
                time_hours    = 0;
                return(false);
            }
        }
Esempio n. 3
0
        public void SendCommandToPlc(AOUDataTypes.CommandType cmd, int value)
        {
            /*
                (temperature in C)	<cmd><tempHotTankFeedSet>195</tempHotTankFeedSet></cmd>	
                (temperature in C)	<cmd><tempColdTankFeedSet>25</tempColdTankFeedSet></cmd>	
                (s/cycle)	        <cmd><coolingTime>15</coolingTime></cmd>	
                (s/cycle)	        <cmd><heatingTime>10</heatingTime></cmd>	
                (s/cycle)	        <cmd><toolHeatingFeedPause>5</toolHeatingFeedPause></cmd>	
            */

            switch (cmd)
            {
                case AOUDataTypes.CommandType.tempHotTankFeedSet:
                    SendTagCommandToPlc("tempHotTankFeedSet", value); break;
                case AOUDataTypes.CommandType.tempColdTankFeedSet:
                    SendTagCommandToPlc("tempColdTankFeedSet", value); break;
                case AOUDataTypes.CommandType.coolingTime:
                    SendTagCommandToPlc("coolingTime", value); break;
                case AOUDataTypes.CommandType.heatingTime:
                    SendTagCommandToPlc("heatingTime", value); break;
                case AOUDataTypes.CommandType.toolHeatingFeedPause:
                    SendTagCommandToPlc("toolHeatingFeedPause", value); break;
                default:
                    SendTagCommandToPlc(cmd.ToString(), value); break;
            }
        }
Esempio n. 4
0
        protected void GetTextDataList()
        {
            long   time_ms = 0;
            string logMsg  = "";

            if (this.debugMode == AOUSettings.DebugMode.rawData)
            {
                return;
            }

            AOUStateData stateData;

            newPowerValues = new List <Power>();
            newLogMessages = new List <AOULogMessage>();

            string textDataStream = GetTextData();
            int    prevTextLength = textDataStream.Length;

            while (prevTextLength > 0)
            {
                Power tempPower  = new Power(0);
                bool  IsTempData = false;

                int           count = 0;
                string        tagContent;
                List <string> loglines;

                string nextTag = AOUInputParser.GetNextTag(textDataStream, out tagContent, out loglines, out count);
                foreach (string log in loglines)
                {
                    if (log.Length > 0)
                    {
                        newLogMessages.Add(new AOULogMessage(GetTime_ms(), log, 8, 0));
                    }
                }

                loglines = AOUInputParser.ParseBetweenTagsMessages(tagContent);
                foreach (string log in loglines)
                {
                    string logStr = log;
                    if (logStr.Length > 0)
                    {
                        if (logStr[0] == ',')
                        {
                            logStr = logStr.Substring(1);
                        }

                        if (logStr[logStr.Length - 1] == ',')
                        {
                            logStr = logStr.Substring(0, logStr.Length - 1);
                        }

                        log.Trim(new char[] { ',', ' ' });
                        newLogMessages.Add(new AOULogMessage(GetTime_ms(), logStr, 9, 0));
                    }
                }

                if (nextTag == AOUInputParser.tagState)
                {
                    AOUInputParser.ParseState(tagContent, out stateData);

                    if (!AOUDataTypes.IsUInt16NaN(stateData.Power))
                    {
                        currentPower = stateData.Power;
                    }

                    if (!AOUDataTypes.IsUInt16NaN(stateData.seqState))
                    {   /*
                         * 12 - "Unknown", 11 - "WOpenEnd", 10 - "WEjectEnd", 9 - "WEjectBegin", 8 - "WOpenBegin", 7 - "WCoolingEnd"
                         * 6 - "WInjectionEnd",  5 - "WInjectionBegin", 4 - "WColdAtMEntry", 3 - "WHotAtMEntry", 2 - "Idle", 1 - "Initial"
                         * NOTHING = 0, SQ_INITIAL, IDLE, SQ_WAIT_HOT_AT_MOULD_ENTRY, SQ_WAIT_COLD_AT_MOULD_ENTRY,
                         * SQ_WAIT_FOR_INJECTION_BEGIN, SQ_WAIT_FOR_INJECTION_END, SQ_WAIT_FOR_COOLING_END,
                         * SQ_WAIT_FOR_OPEN_BEGIN, SQ_WAIT_FOR_EJECT_BEGIN, SQ_WAIT_FOR_EJECT_END, SQ_WAIT_FOR_OPEN_END  */
                        currentSeqState = (AOUDataTypes.StateType)stateData.seqState;
                    }

                    if (!AOUDataTypes.IsUInt16NaN(stateData.Valves))
                    {
                        // -- VALVES -- <Valves>MMSS</Valves> MASK (e.g. “3F”), STATE Bits: 0/Hot valve, 1/Cold valve, 2/Return valve
                        currentHotValve    = (stateData.Valves & 1) != 0 ? 70 : 50; // Off=50, On=70
                        currentColdValve   = (stateData.Valves & 2) != 0 ? 70 : 50; // Off=50, On=70
                        currentReturnValve = (stateData.Valves & 4) != 0 ? 70 : 50; // Cold=50, Hot=70
                        // tempPower.ValveCoolant = (valveState & 8) != 0 ? 100 : 0; // ????
                    }

                    if (stateData.hotTankTemp < 500) // Temp data. ToDo better test
                    {
                        tempPower.ElapsedTime  = AOUDataTypes.AOUModelTimeSecX10_to_TimeMs(stateData.time_hours, stateData.time_sek_x_10_of_hour);
                        tempPower.THotTank     = stateData.hotTankTemp;
                        tempPower.TColdTank    = stateData.coldTankTemp;
                        tempPower.TReturnValve = stateData.retTemp;

                        tempPower.TReturnActual     = stateData.retTemp;  // Todo
                        tempPower.TReturnForecasted = stateData.retTemp;  // Todo

                        tempPower.TBufferCold = stateData.bufColdTemp;
                        tempPower.TBufferMid  = stateData.bufMidTemp;
                        tempPower.TBufferHot  = stateData.bufHotTemp;

                        tempPower.State = currentSeqState;

                        tempPower.ValveFeedCold = currentColdValve;
                        tempPower.ValveFeedHot  = currentHotValve;
                        tempPower.ValveReturn   = currentReturnValve;

                        tempPower.THeaterOilOut = stateData.heaterTemp;

                        tempPower.PowerHeating = currentPower;
                        IsTempData             = true; // Only add new power if temperature data

                        /* ToDo when ????
                         * tempPower.THeatExchangerCoolantOut = 0;
                         */
                        tempPower.ValveCoolant = stateData.coolerTemp; // ????? %
                    }


                    if (!AOUDataTypes.IsUInt16NaN(stateData.IMM))
                    {
                        // <IMM>MMSS</IMM>, 2 hex digits MASK (e.g. “3F”), and 2 hex digits STATE (e.g. “12”).
                        // IMM_OutIMMError: 0x01; IMM_OutIMMBlockInject: 0x02; IMM_OutIMMBlockOpen: 0x04; IMM_InIMMStop: 0x08;
                        // IMM_InCycleAuto: 0x10; IMM_InIMMInjecting: 0x20; IMM_InIMMEjecting: 0x40; IMM_InIMMToolClosed: 0x80;
                        switch (stateData.IMM)
                        {
                        case 0x01: currentIMMState = AOUDataTypes.IMMSettings.OutIMMError; break;

                        case 0x02: currentIMMState = AOUDataTypes.IMMSettings.OutIMMBlockInject; break;

                        case 0x04: currentIMMState = AOUDataTypes.IMMSettings.OutIMMBlockOpen; break;

                        case 0x08: currentIMMState = AOUDataTypes.IMMSettings.InIMMStop; break;

                        case 0x10: currentIMMState = AOUDataTypes.IMMSettings.InCycleAuto; break;

                        case 0x20: currentIMMState = AOUDataTypes.IMMSettings.InIMMInjecting; break;

                        case 0x40: currentIMMState = AOUDataTypes.IMMSettings.InIMMEjecting; break;

                        case 0x80: currentIMMState = AOUDataTypes.IMMSettings.InIMMToolClosed; break;

                        default: currentIMMState = AOUDataTypes.IMMSettings.Nothing; break;
                        }
                    }


                    if (!AOUDataTypes.IsUInt16NaN(stateData.UIButtons))
                    {
                        // UI>MMSS</UI> (hex) MM=8bit mask, SS=8bits. 2 hex digits MASK (e.g. “3F”), and 2 hex digits STATE (e.g. “12”).
                        // BUTTON_ONOFF: 0x0001  // Soft on/Off;  BUTTON_EMERGENCYOFF: 0x0002  // Hard Off
                        // BUTTON_MANUALOPHEAT: 0x0004  // Forced Heating; BUTTON_MANUALOPCOOL  0x0008  // Forced Cooling
                        // BUTTON_CYCLE: 0x0010  // Forced Cycling; BUTTON_RUN: 0x0020  // Run with IMM
                        byte mask  = AOUInputParser.HighByte(stateData.UIButtons);
                        byte state = AOUInputParser.LowByte(stateData.UIButtons);
                        switch (mask)
                        {
                        case 0x01: currentUIButtons.OnOffButton = (AOUDataTypes.ButtonState)state; break;

                        case 0x02: currentUIButtons.ButtonEmergencyOff = (AOUDataTypes.ButtonState)state; break;

                        case 0x04: currentUIButtons.ButtonForcedHeating = (AOUDataTypes.ButtonState)state; break;

                        case 0x08: currentUIButtons.ButtonForcedCooling = (AOUDataTypes.ButtonState)state; break;

                        case 0x10: currentUIButtons.ButtonForcedCycling = (AOUDataTypes.ButtonState)state; break;

                        case 0x20: currentUIButtons.ButtonRunWithIMM = (AOUDataTypes.ButtonState)state; break;

                        default: break;
                        }
                        // ToDo: Send message changed
                    }

                    if (!AOUDataTypes.IsUInt16NaN(stateData.Energy))
                    {
                        // <Energy>MMSS</Energy>, 2 hex digits MASK (e.g. “3F”), and 2 hex digits STATE (e.g. “12”).
                        currentEnergy = stateData.Energy;
                    }

                    if (stateData.Mode < Int16.MaxValue)
                    {
                        // <Mode>1</Mode> (int); 2 hex digits MASK (e.g. “3F”), and 2 hex digits STATE (e.g. “12”). Which???
                        // #define HT_STATE_INVALID: -999; #define HT_STATE_COLD: -1; #define HT_STATE_UNKNOWN: 0; #define HT_STATE_HOT 1
                        Int16 mode = stateData.Mode;
                        currentMode = (AOUDataTypes.HT_StateType)mode;
                    }
                }
                else if (nextTag == "seq")
                {
                    newLogMessages.Add(new AOULogMessage(GetTime_ms(), "seq:" + tagContent, 0, 0));
                }
                else if (nextTag == AOUInputParser.tagLog)
                {
                    if (AOUInputParser.ParseLog(tagContent, out time_ms, out logMsg))
                    {
                        AOULogMessage msg = new AOULogMessage(time_ms * 100, logMsg);
                        if (msg.prio == 0)
                        {
                            msg.prio = 1;
                        }
                        newLogMessages.Add(msg);
                    }
                }
                else if (nextTag.Length > 0)
                {
                    newLogMessages.Add(new AOULogMessage(GetTime_ms(), "Unknown tag:" + nextTag + " = " + tagContent, 0, 0));
                }


                if (AOUInputParser.ValidPowerTag(nextTag))
                {
                    if (IsTempData)
                    {
                        newPowerValues.Add(tempPower);
                    }
                }
                if (count == 0) // No more valid tags. Wait for more data
                {
                    break;
                }
                else
                {
                    textDataStream = textDataStream.Substring(count); // Delete handled tag
                }
            }
        }