Example #1
0
        private void CreateMainTask()
        {
            taskSimpleScheduler = new TaskSimpleScheduler();

            autoResetEvent.Reset();

            taskSimpleScheduler.StartNewTask("模拟业务", () =>
            {
                if (!this.IsStartSimulator)
                {
                    return;
                }

                // 心跳
                this.EquDber.Execute("update " + EntityReflectionUtil.GetTableName <EquQZDZYJSignal>() + " set TagValue=@TagValue where TagName=@TagName", new { TagName = GlobalVars.EquHeartbeatName, TagValue = DateTime.Now.ToString() });
                // 更新采样计划
                this.EquDber.Execute("update " + EntityReflectionUtil.GetTableName <EquQZDZYJPlan>() + " set DataFlag=1 where DataFlag=0");

                // 控制命令
                EquQZDZYJCmd pDCYJCmd = this.EquDber.Entity <EquQZDZYJCmd>("where DataFlag=0 order by CreateDate desc");
                if (pDCYJCmd != null)
                {
                    CmdHandle(pDCYJCmd);

                    autoResetEvent.WaitOne();
                }
            }, 3000);
        }
Example #2
0
        /// <summary>
        /// 皮带控制命令表
        /// </summary>
        /// <param name="output"></param>
        /// <returns></returns>
        public void SyncCmd(Action <string, eOutputType> output)
        {
            int res = 0;

            // 集中管控 > 第三方
            foreach (InfMakerControlCmd entity in AutoMakerDAO.GetInstance().GetWaitForSyncMakerControlCmd(this.MachineCode))
            {
                bool isSuccess = false;

                EquQZDZYJCmd qZDZYJCmd = this.EquDber.Get <EquQZDZYJCmd>(entity.Id);
                if (qZDZYJCmd == null)
                {
                    isSuccess = this.EquDber.Insert(new EquQZDZYJCmd
                    {
                        // 保持相同的Id
                        Id         = entity.Id,
                        CmdCode    = entity.CmdCode,
                        MakeCode   = entity.MakeCode,
                        ResultCode = eEquInfCmdResultCode.默认.ToString(),
                        DataFlag   = 0
                    }) > 0;
                }
                else
                {
                    isSuccess = true;
                }

                if (isSuccess)
                {
                    entity.SyncFlag = 1;
                    commonDAO.SelfDber.Update(entity);

                    res++;
                }
            }
            output(string.Format("同步控制命令 {0} 条(集中管控 > 第三方)", res), eOutputType.Normal);

            res = 0;
            // 第三方 > 集中管控
            foreach (EquQZDZYJCmd entity in this.EquDber.Entities <EquQZDZYJCmd>("where DataFlag=2"))
            {
                InfMakerControlCmd makerControlCmd = commonDAO.SelfDber.Get <InfMakerControlCmd>(entity.Id);
                if (makerControlCmd == null)
                {
                    continue;
                }

                // 更新执行结果等
                makerControlCmd.ResultCode = entity.ResultCode;
                makerControlCmd.DataFlag   = 3;

                if (commonDAO.SelfDber.Update(makerControlCmd) > 0)
                {
                    // 我方已读
                    entity.DataFlag = 3;
                    this.EquDber.Update(entity);

                    res++;
                }
            }
            output(string.Format("同步控制命令 {0} 条(第三方 > 集中管控)", res), eOutputType.Normal);
        }
Example #3
0
        private void CmdHandle(EquQZDZYJCmd input)
        {
            Task task = new Task((state) =>
            {
                EquQZDZYJCmd pDCYJCmd = state as EquQZDZYJCmd;
                OutputRunInfo(rtxtOutput, "处理命令,命令代码:" + pDCYJCmd.CmdCode + "  制样码:" + pDCYJCmd.MakeCode);

                if (pDCYJCmd.CmdCode == eEquInfMakerCmd.开始制样.ToString())
                {
                    EquQZDZYJPlan pDCYJPlan = this.EquDber.Entity <EquQZDZYJPlan>("where MakeCode=@MakeCode", new { MakeCode = pDCYJCmd.MakeCode });
                    if (pDCYJPlan != null)
                    {
                        Thread.Sleep(3000);
                        OutputRunInfo(rtxtOutput, "启动制样机");

                        // 更新系统状态为正在运行
                        this.EquDber.Execute("update " + EntityReflectionUtil.GetTableName <EquQZDZYJSignal>() + " set TagValue=@TagValue where TagName=@TagName", new { TagName = eSignalDataName.设备状态.ToString(), TagValue = eEquInfSamplerSystemStatus.正在运行.ToString() });

                        // 生成出样记录
                        foreach (CodeContent codeContent in CommonDAO.GetInstance().GetCodeContentByKind("样品类型"))
                        {
                            this.EquDber.Insert(new EquQZDZYJDetail
                            {
                                BarrelCode = Guid.NewGuid().ToString().Substring(0, 8).ToUpper(),
                                DataFlag   = 0,
                                StartTime  = DateTime.Now.AddSeconds(3),
                                EndTime    = DateTime.Now,
                                MakeCode   = pDCYJCmd.MakeCode,
                                MakeUser   = "******",
                                YPType     = codeContent.Code,
                                YPWeight   = 500
                            });

                            Thread.Sleep(2000);
                            OutputRunInfo(rtxtOutput, "制出样品:" + codeContent.Code);
                        }

                        // 更新命令
                        pDCYJCmd.ResultCode = eEquInfCmdResultCode.成功.ToString();
                        pDCYJCmd.DataFlag   = 2;
                        this.EquDber.Update(pDCYJCmd);

                        // 更新系统状态为就绪待机
                        this.EquDber.Execute("update " + EntityReflectionUtil.GetTableName <EquQZDZYJSignal>() + " set TagValue=@TagValue where TagName=@TagName", new { TagName = eSignalDataName.设备状态.ToString(), TagValue = eEquInfSamplerSystemStatus.就绪待机.ToString() });
                    }
                    else
                    {
                        OutputRunInfo(rtxtOutput, "未找到制样计划,制样码:" + pDCYJCmd.MakeCode);

                        pDCYJCmd.ResultCode = eEquInfCmdResultCode.失败.ToString();
                        pDCYJCmd.DataFlag   = 1;
                        this.EquDber.Update(pDCYJCmd);
                    }
                }
                else if (pDCYJCmd.CmdCode == eEquInfMakerCmd.停止制样.ToString())
                {
                    Thread.Sleep(3000);
                    OutputRunInfo(rtxtOutput, "停止制样机");

                    // 更新系统状态为就绪待机
                    this.EquDber.Execute("update " + EntityReflectionUtil.GetTableName <EquQZDZYJSignal>() + " set TagValue=@TagValue where TagName=@TagName", new { TagName = eSignalDataName.设备状态.ToString(), TagValue = eEquInfSamplerSystemStatus.就绪待机.ToString() });

                    // 更新命令
                    pDCYJCmd.ResultCode = eEquInfCmdResultCode.成功.ToString();
                    pDCYJCmd.DataFlag   = 2;
                    this.EquDber.Update(pDCYJCmd);
                }

                autoResetEvent.Set();
            }, input);

            task.Start();
        }