示例#1
0
        private void connectButton_Click(object sender, RoutedEventArgs e)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            UpdateInfo();
            batteryTimer.Stop();
            if (UBT.connected)
            {
                if (UBT.Disconnect())
                {
                    // ucComboDisplay.Refresh();
                    ucActionList.Refresh();
                    ucActionDetail.Refresh();
                    RefreshBoardConfig();
                }
            }
            else
            {
                if (UBT.Connect(portsComboBox.Text))
                {
                    UTIL.WriteRegistry(UTIL.KEY.LAST_CONNECTION, portsComboBox.Text);
                    // ucComboDisplay.Refresh();
                    ucActionList.Refresh();
                    RefreshBoardConfig();
                }
            }
            if (UBT.connected)
            {
                byte   mode;
                string ssid, ip;
                UInt16 port;
                if (UBT.GetNetwork(out mode, out ssid, out ip, out port))
                {
                    if (mode == 0)
                    {
                        lblSSID.Foreground = Brushes.Red;
                        lblSSID.Content    = "No Network";
                        lblIP.Content      = "";
                    }
                    else
                    {
                        lblSSID.Content = ssid;
                        lblIP.Content   = String.Format("{0}:{1}", ip, port);
                        switch (mode)
                        {
                        case 1:
                            lblSSID.Foreground = Brushes.LightBlue;
                            break;

                        case 2:
                            lblSSID.Foreground = Brushes.LightPink;
                            break;

                        default:
                            lblSSID.Foreground = Brushes.Red;
                            break;
                        }
                    }
                }
                else
                {
                    lblSSID.Foreground = Brushes.Red;
                    lblSSID.Content    = "Unknown Network";
                    lblIP.Content      = "";
                }
                UpdateBattery();
                batteryTimer.Start();
            }
            SetStatus();
            Mouse.OverrideCursor = null;
            // TODO: check servo setting
            if (UBT.connected)
            {
                if (SYSTEM.configObject.max_servo != UBT.config.maxServo)
                {
                    MessageBox.Show(String.Format("*** 舵机数目不符 ***\n\n上位机设定为: {0}\n主控板设定为: {1}\n舵机数目不符, 系统会出现不正常反应.\n\n请尽快修正错误设定", SYSTEM.configObject.max_servo, UBT.config.maxServo), "上位机跟主控有冲突", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
            }
        }
示例#2
0
        private void ToggleConnection(CONN_MODE connMode)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            UpdateInfo();
            backgroundTimer.Stop();
            bool success = false;

            if (robot.isConnected)
            {
                success = robot.Disconnect();
            }
            else
            {
                switch (connMode)
                {
                case CONN_MODE.Serial:
                    success = robot.Connect((string)portsComboBox.SelectedValue);
                    Thread.Sleep(100);     // Wait 0.1s to check if anything returned
                    if (robot.Available == 0)
                    {
                        break;
                    }
                    // Data returned immediately, possible reboot
                    UpdateInfo("Wait for reboot");
                    Thread.Sleep(SYSTEM.sc.waitRebootSec * 1000);
                    robot.ClearRxBuffer();
                    break;

                case CONN_MODE.Network:
                    int port;
                    if (int.TryParse(txtPort.Text, out port))
                    {
                        success = robot.Connect(txtIP.Text, port);
                    }
                    break;
                }
            }
            if (success)
            {
                if (robot.isConnected)
                {
                    PostConnection();
                }
                else
                {
                    PostDisconnect();
                }
            }
            if (robot.isConnected)
            {
                byte   mode;
                string ssid, ip;
                UInt16 port;
                if (UBT.GetNetwork(out mode, out ssid, out ip, out port))
                {
                    if (mode == 0)
                    {
                        lblSSID.Foreground = Brushes.Red;
                        lblSSID.Content    = "No Network";
                        lblIP.Content      = "";
                    }
                    else
                    {
                        lblSSID.Content = ssid;
                        lblIP.Content   = String.Format("{0}:{1}", ip, port);
                        switch (mode)
                        {
                        case 1:
                            lblSSID.Foreground = Brushes.LightBlue;
                            break;

                        case 2:
                            lblSSID.Foreground = Brushes.LightPink;
                            break;

                        default:
                            lblSSID.Foreground = Brushes.Red;
                            break;
                        }
                    }
                }
                else
                {
                    lblSSID.Foreground = Brushes.Red;
                    lblSSID.Content    = "Unknown Network";
                    lblIP.Content      = "";
                }

                string msg         = null;
                string currVersion = RCVersion.ToCode();
                if (RCVersion.IsOutdated())
                {
                    msg  = "你的固件并未达到上位机的要求, 部份功能可能会出错, 必须尽快更新";
                    msg += string.Format("\n\n你的固件版本:  {0}\n上位機最低要求: {1}", currVersion, RCVersion.TargetVersion.GetCode());
                }
                else if (SYSTEM.sc.autoCheckFirmware)
                {
                    if (string.IsNullOrWhiteSpace(UBT.robotInfo.version))
                    {
                        msg = "";
                    }
                    else
                    {
                        string latestVersion = Util.LatestVersion();
                        if (currVersion != latestVersion)
                        {
                            switch (SYSTEM.sc.firmwareType)
                            {
                            case SystemConfig.FIRMWARE.beta:
                                msg = "开发者测试版";
                                break;

                            case SystemConfig.FIRMWARE.hailzd:
                                msg = "海灵专用版";
                                break;

                            default:
                                msg = "正式发布版";
                                break;
                            }
                            msg += "固件己发布了新版本";
                            msg += string.Format("\n\n你的固件版本: {0}\n最新固件版本: {1}", currVersion, latestVersion);
                        }
                    }
                }
                if (!string.IsNullOrWhiteSpace(msg))
                {
                    msg += "\n\n请用 [机械人固件烧录] 功能, 更新你的固件";
                    MessageBox.Show(msg, "固件更新", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }

                if (UBT.config.version < data.BoardConfig.MIN_VERSION)
                {
                    MessageBox.Show(String.Format("侦测不到所需的固件 {0}, 部份功能可能会失效.\n请尝试重新连线, 或更新固件档.", RCVersion.TargetVersion.GetCode()),
                                    "读取设定档失败或设定档已过时", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }

                if (SYSTEM.configObject.max_servo != UBT.config.maxServo)
                {
                    MessageBox.Show(string.Format("上位机跟主控板的舵机数目设定不同\n上位机: {0} 舵机, 主控板: {1} 舵机\n请确定所选的机械人模型跟主控板是一致的\n或修改有关设定\n\n完成後, 请重新启动程式再连接.\n", SYSTEM.configObject.max_servo, UBT.config.maxServo),
                                    "舵机数目不配合", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }

                if (!SYSTEM.sc.disableBatteryUpdate)
                {
                    UpdateBattery();
                }
                backgroundTimer.Start();
            }
            UpdateEventHandlerStatus();
            SetStatus();
            Mouse.OverrideCursor = null;
        }
        private void ToggleConnection(CONN_MODE connMode)
        {
            Mouse.OverrideCursor = Cursors.Wait;
            UpdateInfo();
            backgroundTimer.Stop();
            bool success = false;

            if (robot.isConnected)
            {
                success = robot.Disconnect();
            }
            else
            {
                switch (connMode)
                {
                case CONN_MODE.Serial:
                    success = robot.Connect((string)portsComboBox.SelectedValue);
                    break;

                case CONN_MODE.Network:
                    int port;
                    if (int.TryParse(txtPort.Text, out port))
                    {
                        success = robot.Connect(txtIP.Text, port);
                    }
                    break;
                }
            }
            if (success)
            {
                if (robot.isConnected)
                {
                    PostConnection();
                }
                else
                {
                    PostDisconnect();
                }
            }
            if (robot.isConnected)
            {
                byte   mode;
                string ssid, ip;
                UInt16 port;
                if (UBT.GetNetwork(out mode, out ssid, out ip, out port))
                {
                    if (mode == 0)
                    {
                        lblSSID.Foreground = Brushes.Red;
                        lblSSID.Content    = "No Network";
                        lblIP.Content      = "";
                    }
                    else
                    {
                        lblSSID.Content = ssid;
                        lblIP.Content   = String.Format("{0}:{1}", ip, port);
                        switch (mode)
                        {
                        case 1:
                            lblSSID.Foreground = Brushes.LightBlue;
                            break;

                        case 2:
                            lblSSID.Foreground = Brushes.LightPink;
                            break;

                        default:
                            lblSSID.Foreground = Brushes.Red;
                            break;
                        }
                    }
                }
                else
                {
                    lblSSID.Foreground = Brushes.Red;
                    lblSSID.Content    = "Unknown Network";
                    lblIP.Content      = "";
                }

                if (SYSTEM.sc.autoCheckFirmware)
                {
                    string msg = null;
                    if (string.IsNullOrWhiteSpace(UBT.robotInfo.version))
                    {
                        msg = "";
                    }
                    else
                    {
                        string currVersion   = RCVersion.ToCode();
                        string latestVersion = (Util.IsBeta(currVersion) ? SYSTEM.firmwareBeta : SYSTEM.firmwareRelease);
                        if (RCVersion.IsOutdated())
                        {
                            msg = "固件版本太旧了, 必须尽快更新";
                        }
                        else if (currVersion != latestVersion)
                        {
                            msg = "己发布了新的固件";
                        }
                        if (!string.IsNullOrWhiteSpace(msg))
                        {
                            msg += string.Format("\n\n你的固件版本: {0}\n最新固件版本: {1}", currVersion, SYSTEM.firmwareBeta);
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(msg))
                    {
                        msg += "\n\n请用 [机械人固件烧录] 功能, 更新你的固件";
                        MessageBox.Show(msg, "固件更新", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                    }
                }

                if (UBT.config.version < data.BoardConfig.MIN_VERSION)
                {
                    MessageBox.Show("侦测不到所需的固件, 部份功能可能会失效.\n请尝试重新连线, 或更新固件档.", "读取设定档失败或设定档已过时", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }

                if (!SYSTEM.sc.disableBatteryUpdate)
                {
                    UpdateBattery();
                }
                backgroundTimer.Start();
            }
            UpdateEventHandlerStatus();
            SetStatus();
            Mouse.OverrideCursor = null;
        }