Пример #1
0
        private void UpdateStatus()
        {
            //连接状态
            switch (focuserUser.GetLink())
            {
            case true:
                labelFocusLinkStat.Text      = "Focuser driver is connected.";
                labelFocusLinkStat.ForeColor = Color.Green;
                break;

            case false:
            default:
                labelFocusLinkStat.Text      = "Focuser driver is not connected.";
                labelFocusLinkStat.ForeColor = Color.Red;
                break;
            }

            //当前位置
            labelFocusCurPos.Text = focuserUser.GetCurPos().ToString("f3");

            //移动状态
            switch (focuserUser.GetMoveStatus())
            {
            case true:
                labelFocusCurStat.Text = "Moving...";
                break;

            case false:
            default:
                labelFocusCurStat.Text = "Stopped";
                break;
            }

            //温度
            labelFocusCurTemp.Text = focuserUser.GetCurTemp().ToString("f1");

            //进度条
            progressBarFocus.Value = (int)(focuserUser.GetCurPos() / 30.0 * 100);
        }
Пример #2
0
        //解析远程指令
        public void ResolveCmds(string msg)
        {
            try
            {
                string   deviceType, cmd, pos, step, temp, ismoving, lt;
                string[] cmdList = msg.Split(',');
                string   reply   = "";
                deviceType = cmdList[0];
                if (cmdList.Length < 3)
                {
                    return;
                }
                if (deviceType != "F")
                {
                    return;
                }
                cmd = cmdList[1];
                lt  = cmdList.Last();

                if (cmd == "MOVE")
                {
                    pos = cmdList[2];
                    //control device
                    m_focUser.FocuserMoveToPos(Convert.ToDouble(pos));
                    //send reply message
                    reply  = "R" + string.Join(",", cmdList, 0, cmdList.Length - 1);
                    reply += "," + "0" + "," + lt;
                    SendMessage(reply);
                }
                else if (cmd == "STOP")
                {
                    //control device
                    m_focUser.FocuserStop();

                    //send reply message
                    reply  = "R" + string.Join(",", cmdList, 0, cmdList.Length - 1);
                    reply += "," + "0" + "," + lt;
                    SendMessage(reply);
                }
                else if (cmd == "STEP")
                {
                    step = cmdList[2];
                    //control device
                    m_focUser.FocuserStepMove(Convert.ToDouble(step));
                    //send reply message
                    reply  = "R" + string.Join(",", cmdList, 0, cmdList.Length - 1);
                    reply += "," + "0" + "," + lt;
                    SendMessage(reply);
                }
                else if (cmd == "STATUS")
                {
                    //control device
                    pos      = m_focUser.GetCurPos().ToString("f3");
                    temp     = m_focUser.GetCurTemp().ToString("f1");
                    ismoving = (m_focUser.GetMoveStatus() ? 1 : 0).ToString();
                    //send reply message
                    reply  = "R" + string.Join(",", cmdList, 0, cmdList.Length - 1);
                    reply += "," + pos;
                    reply += "," + temp;
                    reply += "," + ismoving;
                    reply += "," + lt;
                    SendMessage(reply);
                }
                Console.WriteLine("send: {0}", reply);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("cmds error: {0}", ex.Message);
            }
        }