Exemplo n.º 1
0
        private void btnConnect_Click(object sender, RoutedEventArgs e)
        {
            UpdateInfo();
            int    baudRate;
            bool   baudOK = false;
            string sBaud  = cboBaud.Text.Trim();

            if (int.TryParse(sBaud, out baudRate))
            {
                baudOK = (baudRate >= 9600);
            }
            if (!baudOK)
            {
                UpdateInfo(String.Format((string)LocUtil.FindResource("base.msgInavidBaudRate"), sBaud));
                return;
            }

            if (robot.isConnected)
            {
                robot.Disconnect();
            }
            else
            {
                robot.Connect((string)portsComboBox.SelectedValue, baudRate, System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);
            }
            SetStatus();
        }
Exemplo n.º 2
0
        private void SetButtonLabel()
        {
            bool connected = robot.isConnected;

            btnConnect.Content    = LocUtil.FindResource(connected ? "btnConnectOff" : "btnConnect");
            btnNetConnect.Content = LocUtil.FindResource(connected ? "btnNetConnectOff" : "btnNetConnect");
            btnExecute.Content    = LocUtil.FindResource(connected ? "btnExecute" : "btnShowCommand");
        }
        private bool GoReadSettings()
        {
            bool result = ReadSettings();

            if (!result)
            {
                MessageBox.Show(LocUtil.FindResource("psx.msgReadFail"), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            return(result);
        }
 private void btnSave_Click(object sender, RoutedEventArgs e)
 {
     UpdateInfo();
     if (SaveSettings())
     {
         MessageBox.Show(LocUtil.FindResource("psx.msgSaveSuccess"));
     }
     else
     {
         MessageBox.Show(LocUtil.FindResource("psx.msgSaveFail"), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
 private bool SaveSettings()
 {
     for (int part = 0; part < 2; part++)
     {
         byte[] cmdData = new byte[80];
         for (int i = 0; i < 8; i++)
         {
             string sData = txtPsx[8 * part + i].Text;
             byte[] data  = UTIL.Str2B7Array(sData);
             if (data == null)
             {
                 UpdateInfo(string.Format(LocUtil.FindResource("psx.fmtInvalidSettings"), sData), UTIL.InfoType.error);
                 return(false);
             }
             int BasePos = 10 * i;
             for (int j = 0; j < 10; j++)
             {
                 cmdData[BasePos + j] = (byte)(j < data.Length ? data[j] : 0);
             }
         }
         byte startPos = (byte)(70 + 80 * part);
         int  tryCount = 0;
         bool success  = false;
         while ((tryCount < 3) && !success)
         {
             tryCount++;
             success = SaveRecord(startPos, cmdData);
             if (!success)
             {
                 Thread.Sleep(100);
             }
         }
         if (!success)
         {
             return(false);
         }
     }
     return(true);
 }
 private void btnConnect_Click(object sender, RoutedEventArgs e)
 {
     UpdateInfo();
     if (robot.isConnected)
     {
         robot.Disconnect();
     }
     else
     {
         int    speed  = 0;
         string sSpeed = cboSpeed.Text;
         if (!int.TryParse(sSpeed, out speed) || (speed < 9600) || (speed > 921600))
         {
             MessageBox.Show(LocUtil.FindResource("psx.msgInvalidSpeed"), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
             return;
         }
         robot.Connect((string)cboPorts.SelectedValue, speed, Parity.None, 8, StopBits.One);
     }
     if (robot.isConnected)
     {
         GoReadSettings();
     }
     SetStatus();
 }
        private void SetButtonLabel()
        {
            bool connected = robot.isConnected;

            btnConnect.Content = LocUtil.FindResource(connected ? "btnConnectOff" : "btnConnect");
        }