Exemplo n.º 1
0
        /// <summary>
        /// 向控制器发送控制命令
        /// </summary>
        /// <param name="Work"></param>
        public void SetControllerWorks(CCommandQueueItem Command)
        {
            lock (queSendingCommands)
            {
                if (queSendingCommands.Count <= 10)
                {
                    queSendingCommands.Enqueue(Command);
#if DEBUG
                    Trace.WriteLine(string.Format("Command Item Added >>> {0}", Command.ToString()));
                    Trace.WriteLine(string.Format("Commands remained {0}", queSendingCommands.Count.ToString()));
#endif
                }
            }
        }
Exemplo n.º 2
0
        private void bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            //int cdkey_daysleft = -1;
            //DateTime cdkey_expired = DateTime.MinValue;

            while (true)
            {
                bgw_RS232.ReportProgress(STAT_COMM_PORT_OPENING);
                if (!mControlBoard.Open()) // 如果打开串口失败
                {
                    strLastError = mControlBoard.LastError;

                    mBoardInfo.RS232Connected = false;
                    Thread.Sleep(1000);

                    /* 检查是否请求退出通讯过程 */
                    if (bgw_RS232.CancellationPending)
                    {
                        mControlBoard.Close();
                        return;
                    }

                    bgw_RS232.ReportProgress(STAT_COMM_PORT_INEXITSTENT);
                    Thread.Sleep(1000);
                }
                else
                {
                    bgw_RS232.ReportProgress(STAT_COMM_PORT_OPENED);

                    mBoardInfo.RS232Connected = true; // 成功连接到控制箱


                    while (true)
                    {
                        Thread.Sleep(300);

                        /* 查询控制器各项参数 */
                        if (mControlBoard.QueryStatus(ref mBoardInfo)) // 查询状态成功
                        {
                            bgw_RS232.ReportProgress(STAT_COMM_QUERY_FINISHED);
                        }
                        else    // 查询状态失败
                        {
                            queSendingCommands.Clear();
                            strLastError = mControlBoard.LastError;
                            bgw_RS232.ReportProgress(STAT_COMM_QUERY_ERR);
                            mControlBoard.Close();
                            Thread.Sleep(1000);
                            break;  // 如果查询状态失败,重新连接串口
                        }


                        /******************** Send control commands in quene *****************/
                        CCommandQueueItem cmd = null;
                        lock (queSendingCommands)
                        {
                            if (queSendingCommands.Count > 0)
                            {
                                cmd = queSendingCommands.Dequeue();
                            }
                        }
                        if (cmd != null)
                        {
                            Thread.Sleep(100);

                            switch (cmd.Command)
                            {
                            case CCommandQueueItem.ENUM_CMD.Start:
                                mControlBoard.StartCuring(cmd.Channel);
                                break;

                            case CCommandQueueItem.ENUM_CMD.Stop:
                                mControlBoard.StopCuring(cmd.Channel);
                                break;

                            case CCommandQueueItem.ENUM_CMD.SetTemper:
                                mControlBoard.SetTemperature(cmd.Channel, cmd.Temperature);
                                break;
                            }

#if DEBUG
                            Trace.WriteLine(string.Format("Command Send >>> {0}", cmd.ToString()));
                            Trace.WriteLine(string.Format("Commands remained {0}", queSendingCommands.Count.ToString()));
#endif
                        }


                        /* 检查是否请求退出通讯过程 */
                        if (bgw_RS232.CancellationPending)
                        {
                            mControlBoard.Close();
                            return;
                        }
                        /******************************************************************/


                        /* 检查cdkey是否正确 */

                        //int cdkey_avaliable = CStaticMethods.CheckLicenseAvaliable(CPublicVariables.Configuration.MachineCode, CStaticMethods.GetActiveCode(), CPublicVariables.Configuration.CDKEY, out cdkey_expired, out cdkey_daysleft);
                        //if (cdkey_avaliable != 0)    // CDKEY验证错误
                        //{
                        //    bgw_RS232.ReportProgress(STAT_COMM_LIC_ERR, cdkey_avaliable);
                        //    Thread.Sleep(1000);

                        //    /* 控制器恢复到初始状态 */
                        //    if (this.BoardInfo.ZeroPower == true)
                        //        this.SetControllerWorks(CMD_ZERO_PWR_OFF);  // 关闭零点电源

                        //    if (this.BoardInfo.PreheaterStatus == true)
                        //        this.SetControllerWorks(CMD_PREHEATER_OFF); // 关闭预加热

                        //    if (this.BoardInfo.HeaterLevel != CControlBoardInfo.Enum_HeaterLevel.LOW)   // 加热器调到最低档
                        //        this.SetControllerWorks(CMD_HEATER_LEVEL_LOW);

                        //    if (this.BoardInfo.FanOpened != 0)              // 关闭降温风扇
                        //        this.SetControllerWorks(CMD_COOL_FAN_OFF);

                        //}
                        //else
                        //{

                        //    bgw_RS232.ReportProgress(STAAT_COMM_LIC_OK);

                        //    /* 当前温度写入温度控制类,进行温度控制 */
                        //    mTemperatureTunner.SetTemperature(mBoardInfo.MovingAverageTemperatureInCabin);
                        //}


                        if (mControlBoard.CheckPortChanged())   /* 检查串口号是否在系统设置里做了更改 */
                        {
                            mControlBoard.Close();
                            break; // 如果串口号更改了,则重新打开控制器
                        }

                        /* 检查是否请求退出通讯过程 */
                        if (bgw_RS232.CancellationPending)
                        {
                            mControlBoard.Close();
                            return;
                        }
                    }
                }
            }
        }
 /// <summary>
 /// 向控制器发送控制命令
 /// </summary>
 /// <param name="Work"></param>
 public void SetControllerWorks(CCommandQueueItem Command)
 {
     lock(queSendingCommands)
     {
         if (queSendingCommands.Count <= 10)
         {
             queSendingCommands.Enqueue(Command);
     #if DEBUG
             Trace.WriteLine(string.Format("Command Item Added >>> {0}", Command.ToString()));
             Trace.WriteLine(string.Format("Commands remained {0}", queSendingCommands.Count.ToString()));
     #endif
         }
     }
 }