public MainWindow() { InitializeComponent(); LocUtil.SetDefaultLanguage(this); foreach (System.Windows.Controls.MenuItem item in miLanguages.Items) { if (item.Tag.ToString().Equals(LocUtil.GetCurrentCultureName(this))) { item.IsChecked = true; } } robot.InitObject(UpdateInfo); robot.SetSerialPorts(portsComboBox); robot.SetNetConnection(txtIP, txtPort); SetDefaultCommandType(); SetStatus(); }
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"); }