private void temp_Cal(object sender, RoutedEventArgs e)
 {
    
         M2BDbSetting dbset = new M2BDbSetting();
         DBStruct tmp = new DBStruct();
         tmp.DBID = 0x8d;
         tmp.DBValue = (uint)water_temp.Value;
         dbset._DBGroup.Add(tmp);
         byte[] sendcmd = dbset.EnCode();
         lock (this)
         {
             comunication.Getinstance().AddtoSend(sendcmd, (byte)sendcmd.Length);
         }
         MessageBox.Show("Set Temp Finished");
    
 }
 private void Cal_Button_Click(object sender, RoutedEventArgs e)
 {
     M2BDbSetting dbset = new M2BDbSetting();
     DBStruct tmp = new DBStruct();
     tmp.DBID = _CalPartNo;
     tmp.DBValue = (uint)CalInport1.Value;
     dbset._DBGroup.Add(tmp);
     byte[] sendcmd = dbset.EnCode();
     lock (this)
     {
         comunication.Getinstance().AddtoSend(sendcmd, (byte)sendcmd.Length);
     }
     //MessageBox.Show("SET DB");
 }
Esempio n. 3
0
        private void DealWithComCmd(object obj)
        {
            int i = int.Parse(obj.ToString());
            CommandCmdDef.ComCmd crtcmd = (CommandCmdDef.ComCmd)i;
            M2BTest tmp;
            byte[] SendCmd;
            try
            {
                switch (crtcmd)
                {
                    case CommandCmdDef.ComCmd.MAINTENCE_GET:
                        //DONE:GET ALL MAITENCE DATA
                        M2BMaintenance maintencecmd = new M2BMaintenance();
                        SendCmd = maintencecmd.EnCode();
                        comunication.Getinstance().AddtoSend(SendCmd, (byte)SendCmd.Length);
                        break;
                    case CommandCmdDef.ComCmd.DB_SET:
                       //TODO:设置数据库
                        M2BDbSetting dbset = new M2BDbSetting();
                        dbset._DBGroup.Add(new DBStruct() { DBID = (byte)_crtDBItem.DBID, DBValue = (UInt32)_crtDBItem.DBvalue });
                        SendCmd = dbset.EnCode();
                        comunication.Getinstance().AddtoSend(SendCmd, (byte)SendCmd.Length);
                        break;
                    case CommandCmdDef.ComCmd.UPDATE_FIRM:
                    case CommandCmdDef.ComCmd.UPDATE_RCP:
                        /*
                         * first get filename to be update
                         * second calc the file size ,do packge the com cmd 128 max/per packge
                         * set the pbvalue & set the info msg
                         * send the first packge wait until error or transfer finish.
                         */
                        FileStream fs=null;
                        BinaryReader bw=null;
                        _EvoUpdate.Info = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "ready to transfer file " + _EvoUpdate.RcpFileName;
                        _EvoUpdate.Clearfiletable();
                        _EvoUpdate.FileType = (crtcmd == CommandCmdDef.ComCmd.UPDATE_RCP) ? M2BTransfer.TYPE_FILE : M2BTransfer.TYPE_Program; 
                        try
                        {
                            fs = new FileStream((crtcmd == CommandCmdDef.ComCmd.UPDATE_RCP ? _EvoUpdate.RcpFileName : _EvoUpdate.FirmFileName), FileMode.Open);
                            bw = new BinaryReader(fs);

                            int packagenum = 0;
                            bool isLastPkg = false;
                            if (fs.Length >= 128)
                            {
                                packagenum = (int)(fs.Length / 128);
                            }
                            if (fs.Length % 128 != 0)
                            {
                                isLastPkg = true;
                            }
                            if (isLastPkg)
                            {
                                _EvoUpdate.TotalAmount = packagenum + 1;

                            }
                            else
                            {
                                _EvoUpdate.TotalAmount = packagenum;

                            }
                            for (int cnt = 0; cnt < packagenum; cnt++)
                            {
                                byte[] inbuf = bw.ReadBytes(128);
                                _EvoUpdate.AddtoHashMap(cnt, inbuf);
                            }
                            if (isLastPkg)
                            {
                                byte[] lastbuf = bw.ReadBytes((int)fs.Length - 128 * packagenum);
                                _EvoUpdate.AddtoHashMap(packagenum, lastbuf);
                            }
                            _EvoUpdate.Info = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss ") + "Current file Total package : " + _EvoUpdate.TotalAmount.ToString();
                            ThreadPool.QueueUserWorkItem(new WaitCallback(TransferFile), _EvoUpdate);
                        }
                        catch (Exception err)
                        {

                            throw;
                        }
                        finally
                        {
                            if (bw!=null)
                            {
                                bw.Close();
                            }
                            if (fs!=null)
                            {
                                fs.Close();
                            }
                        }

                        break;
                    
                    case CommandCmdDef.ComCmd.MAKE_INGERDIENT_DELETE:
                    case CommandCmdDef.ComCmd.MAKE_INGERDIENT_MODIFY:
                    case CommandCmdDef.ComCmd.MAKE_INGERDIENT_ADD:
                    case CommandCmdDef.ComCmd.MAKE_INGERDIENT_REVIEW:
                    case CommandCmdDef.ComCmd.MAKE_INGERDIENT_BACKUP:

                        GetAllMachineParam();
                        M2BMakeIngredient m2bMakeIngredient = new M2BMakeIngredient((byte)_CrtIngredient.Type);
                        m2bMakeIngredient.ID = _CrtIngredient.ID;
                        m2bMakeIngredient.operatetype = (byte)(crtcmd - 0x70);
                        switch (_CrtIngredient.Type)
                        {
                            case IngredientType.ESPRESSO:
                                break;
                            case IngredientType.FILTERBREW:
                                M2BMakeIngredient.FilterBrewPhaseStep steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                /*
                                 * Filter brewer process	Phase 1	Phase 2	Phase 3	Phase 4	Phase 5	Phase 6	Phase 7	Phase 8	Phase 9
                                                            Brew motor	X sec	wait Xs	X sec	wait Xs	X sec	wait Xs	X sec	wait Xs	Run to switch
                                                            Brew motor speed	20-100%	0%	20-100%	0%	20-100%	0%	20-100%	0%	100%
                                                            Water valve	X ml																														
                                                            Grinder	X sec																															
                                 * Run brew motor for X seconds with X PWM (speed), start water valve and dispense X ml. start grinder and run X seconds.
                                 * When to start water+grinder could be selected between ex. “Time” – you set start/stop time manually, “Start of phase” – grinder+water will start when brewer reach a start of a phase, “End of phase” – grinder+water will start when brewer reach a end of a phase.
                                 */
                                steptmp.grinder1Type = (UInt16)_CrtIngredient._FilterBrew.Grind1Type;
                                steptmp.grinder2Type = (UInt16)_CrtIngredient._FilterBrew.Grind2Type;
                                steptmp.grinder1powder =(UInt16)( ((_CrtIngredient._FilterBrew.Grind1Cnt / 10) << 8) + (_CrtIngredient._FilterBrew.Grind1Cnt % 10));
                                steptmp.grinder2powder = (UInt16)(((_CrtIngredient._FilterBrew.Grind2Cnt / 10) << 8) + (_CrtIngredient._FilterBrew.Grind2Cnt % 10));
                                steptmp.motorWaitTime = 0;
                                steptmp.WaterFlowTime = (UInt16)(_CrtIngredient._FilterBrew.WaterVolume * 1000 / MachineParam.BrewFlowRate);
                                m2bMakeIngredient._ProcessFilterBrew.FilterBrewPhaseGroup.Add(steptmp);
                                /*Pause brew motor for X Seconds (this phase is now called “Pre Brew”)
                                 */
                                steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                steptmp.grinder1powder =0;
                                steptmp.grinder2powder =0;
                                steptmp.motorWaitTime = _CrtIngredient._FilterBrew.Tm_Pre;
                                steptmp.WaterFlowTime = 0;
                                m2bMakeIngredient._ProcessFilterBrew.FilterBrewPhaseGroup.Add(steptmp);
                                steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                /*Pause brew motor for X Seconds (this phase is now called “Extraction time”)
                                 */
                                steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                steptmp.grinder1Type = 0;
                                steptmp.grinder2Type =0;
                                steptmp.grinder1powder = 0;
                                steptmp.grinder2powder = 0;
                                steptmp.motorWaitTime = _CrtIngredient._FilterBrew.Tm_Press;
                                steptmp.WaterFlowTime = 0;
                                m2bMakeIngredient._ProcessFilterBrew.FilterBrewPhaseGroup.Add(steptmp);
                                steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                /*Pause brew motor for X Seconds (this phase is now called “Decompress time”)
                                 */
                                steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                steptmp.grinder1Type = 0;
                                steptmp.grinder2Type =0;
                                steptmp.grinder1powder = 0;
                                steptmp.grinder2powder = 0;
                                steptmp.motorWaitTime = _CrtIngredient._FilterBrew.Tm_Depress;
                                steptmp.WaterFlowTime = 0;
                                m2bMakeIngredient._ProcessFilterBrew.FilterBrewPhaseGroup.Add(steptmp);
                                steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                /*Pause brew motor for X Seconds (this phase is now called “Empty time”) coffee comes out in cup
                                 */
                                steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                steptmp.grinder1Type = 0;
                                steptmp.grinder2Type =0;
                                steptmp.grinder1powder = 0;
                                steptmp.grinder2powder = 0;
                                steptmp.motorWaitTime = _CrtIngredient._FilterBrew.Tm_DelayOpen;
                                steptmp.WaterFlowTime = 0;
                                m2bMakeIngredient._ProcessFilterBrew.FilterBrewPhaseGroup.Add(steptmp);
                                steptmp = new M2BMakeIngredient.FilterBrewPhaseStep();
                                m2bMakeIngredient._ProcessFilterBrew.PhaseCount = 5;
                                m2bMakeIngredient._ProcessFilterBrew.postionDown = _CrtIngredient._FilterBrew.ActionDownPostion;
                                m2bMakeIngredient._ProcessFilterBrew.postionUp = _CrtIngredient._FilterBrew.ActionUpPostion;

                                break; 
                            case IngredientType.FRESHMILK:
                                /*
                                 * Hot milk process	Phase 1	Phase 2	Phase 3	Phase 4		
                                    Clean water valve	1,5s																			4s								
                                    Milk pump	6,5s	10s	X ml	14s		
                                    Milk pump speed	75%	75%	75%	75%		
                                    Milk heaters	Allow	Allow	Allow	Allow		
                                    Valve to driptray	6,5s	5s																				3s		
                                    Valve to cup											1,5s	X ml	11s				
                                    Milk valve (fridge)						10s	X ml												
                                    Milk Whipper											1,5s	X ml	12s			
                                    Whipper speed											20-100%	20-100%	20-100%			
                                    Mixer bowl flush valve																																1,5s
                                Action steps	
Action 1 – Phase 1 (Initial cleaning)	Start the clean water valve from hot water tank, milk pump at 75% PWM, and no current (OFF) to the 3/2 valve to make it towards milk waste. Heaters are allowed to work towards Prio temp. Heaters shall have option to be turned OFF during the process to be able to make cold milk as well.
Action 2 – Phase 2 (pre fill up)	Once phase 1 is finished we activate the 3/2 valve in the fridge to start pumping milk into the system. For 5 seconds we still have the other 3/2 valve towards milk waste since there is some water left in the tubing, it also takes around 5 seconds to fill all tubes and heaters with milk. After 5 seconds we then swap 3/2 valve (turn it ON) towards the mixer bowl, at the same time we start the whipper.
Action 3 – Phase 3 (dispense milk)	Now we just continue run the pump at 75% and the 3/2 valves are active to pump milk and direct it towards mixer bowl. To determine how long these components shall run the milk use a fixed flow, 18ml/s. if you want ex. 150ml milk it means that components will run for 8,3 seconds in this step.
Action 4 – Phase 4 (After cleaning)	Now we start the water valve from the tank again and close the valve in fridge for milk. We still dispense towards the mixer bowl since we want as much remaining milk/water in the system to go into the cup. The last 3 seconds we turn off the 3/2 valve towards the mixer so the last part goes into the milk waste instead. When all internal flushing is done we activate the water valve in tank for chocolate (mixer flush valve) for 1.5s to rinse the mixer bowl properly in the end.
** Valve to milk waste/mixer is same 3/2 valve. If no current and valve is off = towards drip tray, if you activate valve with current = towards cup.
Heaters have two temperature settings, “Idle temp” and “Prio temp”. When machine is standing still and no one using machine the heaters will keep the Idle temperature setting. Ex 60°C. When you start a milk drink the heaters are allowed to heat up and use the Prio temperature during the process. Ex. 75°C. When drink is finished the heaters go back and use the Idle setting again. 
                                 * 
                                 */
                                m2bMakeIngredient._ProcessFreshMilk.dispenseMilkTime = (UInt16)(_CrtIngredient._FreshMilk.MilkVolume * 1000 / MachineParam.Mixer1FlowRate);
                                m2bMakeIngredient._ProcessFreshMilk.preFlushTime = (UInt16)(_CrtIngredient._FreshMilk.Preflush * 1000 / MachineParam.Mixer1FlowRate);
                                m2bMakeIngredient._ProcessFreshMilk.aftFlushTime = (UInt16)(_CrtIngredient._FreshMilk.AfterFlush * 1000 / MachineParam.Mixer1FlowRate);
                                m2bMakeIngredient._ProcessFreshMilk.heaterAction = _CrtIngredient._FreshMilk.HeaterFlag;
                                m2bMakeIngredient._ProcessFreshMilk.whipperSpeed = (byte)_CrtIngredient._FreshMilk.WhipperSpeed;
                                break;
                            case IngredientType.INSTANTPOWDER:
                                /*
                                 *  Action step	
                                    Action 1 – Pre flush	First we must dispense a little water so we have water in the mixer bowl before we start canister and whipper. Normally 15ml or 1 sec
                                    Action 2 – Pause	Here we have a pause so the water have time to fall down from tank through the tubes and into the mixer bowl.
                                    Action 3 – Dispense	We can now start all components such as water valve, canister and whipper at X PWM. When the setting that have longest time is finished it goes to next step.
                                    Action 4 – Pause	Another pause to make all water/drink empty the mixer bowl. 
                                    Action 5 – After flush	Run water again to flush out all remains, normally 15ml or 1 sek.
                                 * 
                                 */
                                m2bMakeIngredient._ProcessInstantPowder.canisterCnt = 2;
                                UInt32 canisterpowder = (UInt32)((_CrtIngredient._InstantPowder.PackageOneType << 16 )+ (((_CrtIngredient._InstantPowder.PackageOneAmt / 10) << 8) + (_CrtIngredient._InstantPowder.PackageOneAmt % 10)));
                                m2bMakeIngredient._ProcessInstantPowder.canisterPowderGroup.Add(canisterpowder);
                                canisterpowder = (UInt32)((_CrtIngredient._InstantPowder.PackageTwoType << 16 )+ (((_CrtIngredient._InstantPowder.PackageTwoAmt / 10) << 8) + (_CrtIngredient._InstantPowder.PackageTwoAmt % 10)));
                                m2bMakeIngredient._ProcessInstantPowder.canisterPowderGroup.Add(canisterpowder);
                                m2bMakeIngredient._ProcessInstantPowder.MixIndex = (byte)_CrtIngredient._InstantPowder.MixIndex;
                                m2bMakeIngredient._ProcessInstantPowder.waterDispenseTime = (UInt16)(_CrtIngredient._InstantPowder.WaterVolume * 1000 / MachineParam.Mixer1FlowRate);
                                m2bMakeIngredient._ProcessInstantPowder.preFlushTime = (UInt16)(_CrtIngredient._InstantPowder.PreFlush * 1000 / MachineParam.Mixer1FlowRate);
                                m2bMakeIngredient._ProcessInstantPowder.aftFlushTime = (UInt16)(_CrtIngredient._InstantPowder.AfterFlush * 1000 / MachineParam.Mixer1FlowRate);
                                m2bMakeIngredient._ProcessInstantPowder.pauseTime = 1500;
                                m2bMakeIngredient._ProcessInstantPowder.pauseTime1 = 2000;
                                m2bMakeIngredient._ProcessInstantPowder.whipperSpeed = (byte)_CrtIngredient._InstantPowder.WhipperSpeed;
                                m2bMakeIngredient._ProcessInstantPowder.waterType = _CrtIngredient._InstantPowder.WaterType;
                                break;
                            case IngredientType.Water:
                                m2bMakeIngredient._ProcessWater.WaterType = _CrtIngredient._Water.WaterType;
                                m2bMakeIngredient._ProcessWater.DispenseTm = (UInt16)(_CrtIngredient._Water.WaterVolume * 1000 / MachineParam.HotwaterFlowRate);
                                break;
                            case IngredientType.NoSelect:
                                break;
                            default:
                                break;
                        }
                        SendCmd = m2bMakeIngredient.EnCode();
                        comunication.Getinstance().AddtoSend(SendCmd, (byte)SendCmd.Length);
                         break;
                    case CommandCmdDef.ComCmd.MAKE_BAVERAGE_ADD:
                    case CommandCmdDef.ComCmd.MAKE_BAVERAGE_DELETE:
                    case CommandCmdDef.ComCmd.MAKE_BAVERAGE_BACKUP:
                    case CommandCmdDef.ComCmd.MAKE_BAVERAGE_MODIFY:
                    case CommandCmdDef.ComCmd.MAKE_BAVERAGE_REVIEW:
                         M2BMakeBeverage cmdtmp = new M2BMakeBeverage(_CrtRecipeInfo._publicInfo);
                        cmdtmp.ID = _CrtRecipeInfo.ID;
                        cmdtmp.operatetype =(byte) (crtcmd - 0x80);
                        foreach (var item in _CrtRecipeInfo._lstIngredientStep)
                        {
                            M2BMakeBeverage.IngredientStep steptmp = new M2BMakeBeverage.IngredientStep();
                            steptmp.ID = item.ID;
                            steptmp._Type = item._Type;
                            steptmp.startTime = item.StartTime;
                            steptmp.percent = item.ScaleRate;
                            cmdtmp.igredientStepGroup.Add(steptmp);
                        }
                        cmdtmp.ingredientCnt = (byte)_CrtRecipeInfo._lstIngredientStep.Count;
                        SendCmd = cmdtmp.EnCode();
                        comunication.Getinstance().AddtoSend(SendCmd, (byte)SendCmd.Length);
                        break;
                    case CommandCmdDef.ComCmd.TEST_START:
                        tmp = new M2BTest((byte)_CrtDeviceUnit.DeviceID, M2BTest.Turn_on_always, _CrtDeviceUnit.Speed);
                        SendCmd = tmp.EnCode();
                        comunication.Getinstance().AddtoSend(SendCmd, (byte)SendCmd.Length);
                        break;
                    case CommandCmdDef.ComCmd.TEST_STOP:
                        tmp = new M2BTest((byte)_CrtDeviceUnit.DeviceID, M2BTest.Turn_off);
                        SendCmd = tmp.EnCode();
                        comunication.Getinstance().AddtoSend(SendCmd, (byte)SendCmd.Length);
                        break;
                    case CommandCmdDef.ComCmd.UI_COM_SET:
                        _TestSet = new EVOTestForm();
                        _TestSet.Show();
                        _TestSet.Closed += _TestSet_Closed;
                        break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            
        }