예제 #1
0
        /// <summary>
        /// 保存指令下发记录
        /// </summary>
        /// <param name="cl"></param>
        public static void SaveCmdLog(CmdLog cl)
        {
            WebDBEntities2 entity = new WebDBEntities2();

            entity.CmdLogs.Add(cl);
            entity.SaveChanges();
        }
예제 #2
0
        /// <summary>
        /// 启动指令队列
        /// </summary>
        /// <param name="second">执行时间间隔,默认10分钟</param>
        public static void StartCmdQueue(int second = 600)
        {
            //最少一分钟跑一次
            if (second < 60)
            {
                second = 60;
            }
            ThreadPool.QueueUserWorkItem(p =>
            {
                while (true)
                {
                    try
                    {
                        List <CmdQueue> list = CmdLogic.GetCmdQueues();
                        InLogQueue("获取到待执行指令数量:" + list.Count(), LogLevel.Info, "local");
                        if (list.Count > 0)
                        {
                            foreach (var l in list)
                            {
                                //多个指令以_区分
                                string[] cmdCodes = l.CmdCode.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string code in cmdCodes)
                                {
                                    CmdConfig cmd      = CacheHelper.GetCachCmdConfig(code, l.Model);
                                    CmdLog log         = new CmdLog();
                                    log.CmdCode        = code;
                                    log.CmdName        = l.ExceTime + "分钟:" + cmd.CmdName;
                                    log.Imei           = l.IMEI;
                                    log.Param          = l.Param;
                                    log.IsSucess       = false;
                                    log.SendLoginName  = l.Notice;
                                    log.SendDate       = DateTime.Now;
                                    SendCmdModel model = DeviceData.SendCmd(code, l.APIDeviceId ?? 0, l.Model, CacheHelper.GetTokenByDeviceId(l.IMEI), l.Param);
                                    log.IsSucess       = model.State == 0;
                                    log.Notice         = "每隔" + l.ExceTime + "分钟下发主动监测。";
                                    log.Response       = model.Content + ":" + model.Message;
                                    log.ResponseTime   = DateTime.Now;
                                    CmdLogic.SaveCmdLog(log);//保存日志
                                }
                                CmdLogic.UpdateQueueTime(l);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        InLogQueue_Error(ex, "local");
                    }

                    Thread.Sleep(second * 1000);
                }
            });
        }
예제 #3
0
        public void SetCore(GrblCore core)
        {
            Core = core;
            Core.OnFileLoaded += OnFileLoaded;
            CmdLog.SetCom(core);

            PB.Bars.Add(new LaserGRBL.UserControls.DoubleProgressBar.Bar(Color.LightSkyBlue));
            PB.Bars.Add(new LaserGRBL.UserControls.DoubleProgressBar.Bar(Color.Pink));

            InitSpeedCB();
            InitPortCB();
            TimerUpdate();
        }
예제 #4
0
        public void SetCore(GrblCore core)
        {
            Core = core;
            Core.OnFileLoaded      += OnFileLoaded;
            Core.OnLoopCountChange += OnLoopCountChanged;

            CmdLog.SetCom(core);

            PB.Bars.Add(new PrintekLaserFoam.UserControls.DoubleProgressBar.Bar(Color.LightSkyBlue));
            PB.Bars.Add(new PrintekLaserFoam.UserControls.DoubleProgressBar.Bar(Color.Pink));

            InitSpeedCB();
            InitPortCB();

            RestoreConf();

            TimerUpdate();
        }
예제 #5
0
 internal void OnColorChange()
 {
     CmdLog.Invalidate();
 }
예제 #6
0
        public void TimerUpdate()
        {
            SuspendLayout();

            if (!Core.IsOpen && System.IO.Ports.SerialPort.GetPortNames().Length != CBPort.Items.Count)
            {
                InitPortCB();
            }

            PB.Maximum       = Core.ProgramTarget;
            PB.Bars[0].Value = Core.ProgramSent;
            PB.Bars[1].Value = Core.ProgramExecuted;

            string val = Tools.Utils.TimeSpanToString(Core.ProgramTime, Tools.Utils.TimePrecision.Minute, Tools.Utils.TimePrecision.Second, " ,", true);

            if (val != "now")
            {
                PB.PercString = val;
            }
            else if (Core.InProgram)
            {
                PB.PercString = "0 sec";
            }
            else
            {
                PB.PercString = "";
            }

            PB.Invalidate();



            /*
             * Idle: All systems are go, no motions queued, and it's ready for anything.
             * Run: Indicates a cycle is running.
             * Hold: A feed hold is in process of executing, or slowing down to a stop. After the hold is complete, Grbl will remain in Hold and wait for a cycle start to resume the program.
             * Door: (New in v0.9i) This compile-option causes Grbl to feed hold, shut-down the spindle and coolant, and wait until the door switch has been closed and the user has issued a cycle start. Useful for OEM that need safety doors.
             * Home: In the middle of a homing cycle. NOTE: Positions are not updated live during the homing cycle, but they'll be set to the home position once done.
             * Alarm: This indicates something has gone wrong or Grbl doesn't know its position. This state locks out all G-code commands, but allows you to interact with Grbl's settings if you need to. '$X' kill alarm lock releases this state and puts Grbl in the Idle state, which will let you move things again. As said before, be cautious of what you are doing after an alarm.
             * Check: Grbl is in check G-code mode. It will process and respond to all G-code commands, but not motion or turn on anything. Once toggled off with another '$C' command, Grbl will reset itself.
             */

            TT.SetToolTip(BtnConnectDisconnect, Core.IsOpen ? "Disconnect" : "Connect");

            BtnConnectDisconnect.UseAltImage = Core.IsOpen;
            BtnRunProgram.Enabled            = Core.CanSendFile;
            BtnRunProgram.Visible            = !Core.CanAbortProgram;
            BtnAbortProgram.Visible          = Core.CanAbortProgram;
            BtnOpen.Enabled = Core.CanLoadNewFile;

            bool old = TxtManualCommand.Enabled;

            TxtManualCommand.Enabled = Core.CanSendManualCommand;
            //if (old == false && TxtManualCommand.Enabled == true)
            //	TxtManualCommand.Focus();

            //CBProtocol.Enabled = !Core.IsOpen;
            CBPort.Enabled     = !Core.IsOpen;
            CBSpeed.Enabled    = !Core.IsOpen;
            TxtAddress.Enabled = !Core.IsOpen;

            CmdLog.TimerUpdate();

            if (!Core.IsOpen)
            {
                ComWrapper.WrapperType actualWrapper = (ComWrapper.WrapperType)Settings.GetObject("ComWrapper Protocol", ComWrapper.WrapperType.UsbSerial);
                if (actualWrapper != currentWrapper)
                {
                    currentWrapper = actualWrapper;
                    UpdateConf();
                }
            }

            ResumeLayout();
        }
예제 #7
0
        /// <summary>
        /// 下发指令
        /// </summary>
        /// <param name="cmdCode">指令code</param>
        /// <param name="deviceId">设备id</param>
        /// <returns></returns>
        public JsonResult AjaxSendCmd(string cmdCode, int deviceId, string param, int min)
        {
            BaseResult res = new BaseResult();
            Device     d   = DeviceLogic.GetDeviceById(deviceId);
            CmdConfig  cmd = CmdLogic.GetCmdConfigByCode(cmdCode, d.APIDeviceModel.Value);

            if ((d.APIDeviceModel ?? 0) <= 0)
            {
                res.Message = "指令下发失败,设备型号为空!";
                res.State   = State.Falid;
                return(Json(res));
            }
            CmdLog log = new CmdLog();

            log.CmdCode       = cmdCode;
            log.CmdName       = cmd.CmdName;
            log.Imei          = d.Imei;
            log.Param         = param;
            log.IsSucess      = false;
            log.SendLoginName = AuthUser.LoginName;
            //是否立即下发,不是的加入队列
            if ((cmd.IsNowSend ?? true) == false)//设置主动上传间隔
            {
                log.SendDate = DateTime.Now;
                if (min > 0)
                {
                    CmdQueue queue = new CmdQueue();
                    queue.APIDeviceId  = d.APIDeviceId;
                    queue.Model        = d.APIDeviceModel.Value;
                    queue.CmdCode      = cmdCode;
                    queue.Created      = DateTime.Now;
                    queue.LastExecTime = DateTime.Now;
                    queue.Param        = param;
                    queue.ExceTime     = min;
                    queue.IMEI         = d.Imei;
                    queue.Notice       = AuthUser.LoginName;
                    CmdLogic.SaveCmdQueue(queue);
                    SaveUserLog(AuthUser.LoginName + "设置了设备" + d.Imei + cmd.CmdName + ":" + min + "分钟", LogLevel.Info, AuthUser.LoginName, "AjaxSendCmd", "下发指令");
                }
                else
                {
                    CmdLogic.DelCmdQueue(cmdCode, d.APIDeviceId.Value);
                }
                log.CmdName = cmd.CmdName + ":" + min + "分钟";

                res.State   = State.Success;
                res.Message = "设置成功," + min + "分钟";
                //return Json(res);
            }
            else if (d != null)
            {
                log.SendDate = DateTime.Now;
                SendCmdModel model = DeviceData.SendCmd(cmdCode, d.APIDeviceId ?? 0, d.APIDeviceModel ?? 0, CacheHelper.GetToken(d.UserId), param);

                if (model.State != 0)
                {
                    res.State   = State.Falid;
                    res.Message = model.Content + ":" + model.Message;
                    SaveUserLog(AuthUser.LoginName + "下发设备" + d.Imei + "的" + cmd.CmdName + "指令失败:" + res.Message, LogLevel.Sensitive, AuthUser.LoginName, "AjaxSendCmd", "下发指令");
                }
                else
                {
                    log.IsSucess = true;
                    res.State    = State.Success;
                    res.Message  = model.Content;
                    SaveUserLog(AuthUser.LoginName + "下发设备" + d.Imei + "的" + cmd.CmdName + "指令:" + res.Message, LogLevel.Info, AuthUser.LoginName, "AjaxSendCmd", "下发指令");
                    //WriteLog( + res.Message);
                }
                log.Response     = model.State + "|" + res.Message;
                log.ResponseTime = DateTime.Now;
            }
            else
            {
                res.State   = State.NotFind;
                res.Message = "设备不存在";
                WriteLog(AuthUser.LoginName + "下发设备" + d.Imei + "的" + cmd + "指令失败:" + res.Message);
            }
            //保存指令下发记录
            CmdLogic.SaveCmdLog(log);
            if (res.Message.StartsWith("Off"))
            {
                res.Message = "设备不线,指令离线下发";
            }
            return(Json(res));
        }