private void ReadPIDSetup(SharedPreferences sp) { //保存的车型 radioButton_FourWheel.Checked = sp.GetBoolean("radioButton_carType", true); if (!radioButton_FourWheel.Checked) radioButton_BalanceCar.Checked = true; if (radioButton_FourWheel.Checked) //四轮车PID ReadPIDFourWheel(sp); else if (radioButton_BalanceCar.Checked) //直立车PID参数的获取 ReadPIDBalanceCar(sp); }
private void ReadPIDFourWheel(SharedPreferences sp) { //舵机PID参数 textBox_Steer_P.Text = sp.GetString("Steer_P", "1.0"); textBox_Steer_I.Text = sp.GetString("Steer_I", "1.0"); textBox_Steer_D.Text = sp.GetString("Steer_D", "1.0"); //电机PID参数 textBox_Motor_P.Text = sp.GetString("Motor_P", "1.0"); textBox_Motor_I.Text = sp.GetString("Motor_I", "1.0"); textBox_Motor_D.Text = sp.GetString("Motor_D", "1.0"); }
private void ReadPIDBalanceCar(SharedPreferences sp) { //直立PID textBox_Stand_P.Text = sp.GetString("Stand_P", "1.0"); textBox_Stand_I.Text = sp.GetString("Stand_I", "1.0"); textBox_Stand_D.Text = sp.GetString("Stand_D", "1.0"); //速度PID textBox_Speed_P.Text = sp.GetString("Speed_P", "1.0"); textBox_Speed_I.Text = sp.GetString("Speed_I", "1.0"); textBox_Speed_D.Text = sp.GetString("Speed_D", "1.0"); //方向PID textBox_Direction_P.Text = sp.GetString("Direction_P", "1.0"); textBox_Direction_I.Text = sp.GetString("Direction_I", "1.0"); textBox_Direction_D.Text = sp.GetString("Direction_D", "1.0"); }
private void LoadConfig(string fileName) { var sp = new SharedPreferences(fileName); if (sp.ConfigFileExists) { ReadPortSetup(sp); ReadPIDSetup(sp); ReadDIYNumberSetup(sp); ReadRealTimeSetup(sp); ReadOthers(sp); textBox_receive.Clear(); } else { //载入默认设置 ResetToDefaultSettings(); } }
private void DrawRealTimePannel(SharedPreferences sp, bool byInit) { panel_Electricity.AutoScroll = true; panel_Electricity.Controls.Clear(); var total = int.Parse(textBox_Realtime_Number.Text); for (var i = 0; i < total; i++) { var labelElect = new TextBox(); labelElect.Size = new Size(100, 20); //label大小 labelElect.Location = new Point(30 + 120*0, 30*(i + 1)); labelElect.Name = "txtElectName" + Convert.ToString(i + 1); labelElect.Text = @"实时变量" + Convert.ToString(i + 1); labelElect.TextAlign = HorizontalAlignment.Center; if (byInit) { var elecName = string.Format("textElectName{0}", i + 1); labelElect.Text = sp.GetString(elecName, "1.0"); } var txtBoxValue = new TextBox(); txtBoxValue.Size = new Size(50, 50); txtBoxValue.Location = new Point(30 + 120*1, 30*(i + 1)); txtBoxValue.Name = "txtElectValue" + Convert.ToString(i + 1); txtBoxValue.TextAlign = HorizontalAlignment.Center; if (byInit) { var elecValue = string.Format("txtElectValue{0}", i + 1); txtBoxValue.Text = sp.GetString(elecValue, "1.0"); } panel_Electricity.Controls.Add(labelElect); panel_Electricity.Controls.Add(txtBoxValue); } }
private void button_electricity_NumConfirm_Click(object sender, EventArgs e) { if (isRealTimeValide()) { var sp = new SharedPreferences(SavefileName); if (sp.ConfigFileExists) { DrawRealTimePannel(sp, false); } SaveConfig(SavefileName); } }
private void InitRealtime() { var sp = new SharedPreferences(SavefileName); if (sp.ConfigFileExists && isRealTimeValide()) { DrawRealTimePannel(sp, true); } }
private void AddControlsToPannel(SharedPreferences sp, int start, int end, bool byInit) { for (var i = start; i < end; i++) { var checkboxSelect = new CheckBox(); checkboxSelect.Size = new Size(50, 20); checkboxSelect.Location = new Point(30 + 70*0, 30*(i + 1)); checkboxSelect.Name = "checkBox_Def" + Convert.ToString(i + 1); checkboxSelect.Text = (i + 1).ToString(); if (byInit) { var checkState = string.Format("DIY_CheckState{0}", i + 1); checkboxSelect.Checked = sp.GetBoolean(checkState, true); } checkboxSelect.CheckedChanged += CheckboxSelectOnCheckedChanged; var txtBoxName = new TextBox(); txtBoxName.Size = new Size(50, 50); //textbox大小 txtBoxName.Location = new Point(30 + 70*1, 30*(i + 1)); txtBoxName.Name = @"txtName" + Convert.ToString(i + 1); txtBoxName.Text = @"Name" + Convert.ToString(i + 1); txtBoxName.TextAlign = HorizontalAlignment.Center; if (byInit) { var txtName_CustomPara = string.Format("DIY_TextName{0}", i + 1); txtBoxName.Text = sp.GetString(txtName_CustomPara, "数据"); } else { txtBoxName.Enabled = false; } var txtBoxValue = new TextBox(); txtBoxValue.Size = new Size(50, 50); //textbox大小 txtBoxValue.Location = new Point(30 + 70*2, 30*(i + 1)); txtBoxValue.Name = "txtValue" + Convert.ToString(i + 1); txtBoxValue.Text = @"1.0"; txtBoxValue.TextAlign = HorizontalAlignment.Center; if (byInit) { var txtValue_CustomPara = string.Format("DIY_TextValue{0}", i + 1); txtBoxValue.Text = sp.GetString(txtValue_CustomPara, "1.0"); } else { txtBoxValue.Enabled = false; } txtBoxValue.TextChanged += DIYTextboxValueChanged; var submitButton = new Button(); submitButton.Size = new Size(50, 20); //textbox大小 submitButton.Location = new Point(30 + 70*3, 30*(i + 1)); submitButton.Name = "buttonSubmit" + Convert.ToString(i + 1); submitButton.Text = @"修改"; submitButton.Click += SubmitButtonOnClick; if (!byInit) { submitButton.Enabled = false; } if (!checkboxSelect.Checked) { txtBoxName.Enabled = false; txtBoxValue.Enabled = false; submitButton.Enabled = false; } panel_add_DIYControls.Controls.Add(checkboxSelect); panel_add_DIYControls.Controls.Add(txtBoxName); panel_add_DIYControls.Controls.Add(txtBoxValue); panel_add_DIYControls.Controls.Add(submitButton); } }
private void DrawCustomParaPannel(bool byInit) { panel_add_DIYControls.AutoScroll = true; panel_add_DIYControls.Controls.Clear(); var total = int.Parse(textBox_DIY_Number.Text); var sp = new SharedPreferences(SavefileName); if (sp.ConfigFileExists) { AddControlsToPannel(sp, 0, total, byInit); } }
private void Init_CustomPara_DynamicControls() { var sp = new SharedPreferences(SavefileName); if (sp.ConfigFileExists && isCustomParaValidate()) { DrawCustomParaPannel(true); } }
private void ReadRealTimeSetup(SharedPreferences sp) { textBox_Realtime_Number.Text = sp.GetString("RealtimeNum", "1"); }
private void ReadPortSetup(SharedPreferences sp) { //读取选中的端口 if (_hasPorts) { //判断当前端口的数量,小于则表示是OK。 if (sp.GetInt32("selectedPort", 0) < comboBox_port.Items.Count) comboBox_port.SelectedIndex = sp.GetInt32("selectedPort", 0); else { comboBox_port.SelectedIndex = 0; } } //读取设置的波特率 comboBox_baudrate.SelectedIndex = sp.GetInt32("baudRate", 0); //读取设置的校验方式 comboBox_parity.SelectedIndex = sp.GetInt32("parity", 0); //读取设置的数据位 comboBox_databit.SelectedIndex = sp.GetInt32("dataBits", 0); //读取设置的停止位 comboBox_stopbit.SelectedIndex = sp.GetInt32("stopBits", 0); //读取自动发送数据时间间隔 textBox_sendPeriod.Text = sp.GetInt32("intervalTime", 500).ToString(); //读取接收方式 checkBox_receiveHex.Checked = sp.GetBoolean("acceptChar", true); //读取标志变量,即是否在接收框中显示信息。 showInfo = sp.GetBoolean("showInfo", true); button_receivepause.Text = showInfo ? "暂停接收显示" : "继续接收显示"; }
private void ReadOthers(SharedPreferences sp) { comboBoxCCDPath.SelectedIndex = sp.GetInt32("comboboxCCDPath", 0); }
private void ReadDIYNumberSetup(SharedPreferences sp) { textBox_DIY_Number.Text = sp.GetInt32("DIY_Number", 1).ToString(); }
private void InitzedGraph() { var myPane = zedGraph_local.GraphPane; myPane.Title.IsVisible = false; myPane.XAxis.Title.Text = "time"; myPane.YAxis.Title.Text = "Value"; //show grid myPane.XAxis.MajorGrid.IsVisible = true; myPane.YAxis.MajorGrid.IsVisible = true; // Align the Y axis labels so they are flush to the axis myPane.YAxis.Scale.Align = AlignP.Inside; // Manually set the axis range myPane.XAxis.Scale.Min = _xminScale; myPane.XAxis.Scale.Max = _xmaxScale; myPane.YAxis.Scale.Min = _yminScale; myPane.YAxis.Scale.Max = _ymaxScale; // Fill the axis background with a gradient myPane.Chart.Fill = new Fill(Color.White, Color.LightGray, 45.0f); // OPTIONAL: Show tooltips when the mouse hovers over a point zedGraph_local.IsShowPointValues = true; zedGraph_local.PointValueEvent += MyPointValueHandler; for (var i = 0; i < ScopeNumber; i++) { zedGrpahNames[i] = new ZedGrpahName(); coOb[i] = new CallObject(); } var sp = new SharedPreferences(SavefileName); for (var i = 0; i < ScopeNumber; i++) { zedGrpahNames[i].listZed.Add(Convert.ToDouble(zedGrpahNames[i].x), 0); var curve = string.Format("波形{0}", i + 1); //自己定义的变量名称 var txtName_CustomPara = string.Format("SCOPE_TextName{0}", i + 1); var getName = sp.GetString(txtName_CustomPara, @"波形" + Convert.ToString(i + 1)); zedGraph_local.GraphPane.AddCurve(getName.Trim() != "" ? getName : curve, zedGrpahNames[i].listZed, _colorLine[i%8], SymbolType.None); } refleshZedPane(zedGraph_local); }
private void GetCustomOldNames(List<bool> state, List<string> names, List<string> value) { SharedPreferences sp = new SharedPreferences(SavefileName); int oldNumber = 0; if(sp.ConfigFileExists) oldNumber = sp.GetInt32("DIY_Number", 1); for (var i = 0; i < oldNumber; i++) { var checkboxSelect = (CheckBox)panel_add_DIYControls.Controls.Find("checkBox_Def" + Convert.ToString(i + 1), true)[0]; state.Add(checkboxSelect.Checked); var txtBoxValue = (TextBox) panel_add_DIYControls.Controls.Find("txtValue" + Convert.ToString(i + 1), true)[0]; value.Add(txtBoxValue.Text); var txtBoxName = (TextBox)panel_add_DIYControls.Controls.Find("txtName" + Convert.ToString(i + 1), true)[0]; names.Add(txtBoxName.Text); } }
private void Init_pane_Scope() { var sp = new SharedPreferences(SavefileName); panel_Scope.AutoScroll = true; var total = ScopeNumber; for (var i = 0; i < total; i++) { var checkDrawing = new CheckBox(); checkDrawing.Size = new Size(15, 15); checkDrawing.Location = new Point(20 + i%8*77, 10 + i/8*60); checkDrawing.Name = "checkBox_Def" + Convert.ToString(i + 1); checkDrawing.Text = ""; var checkState = string.Format("SCOPE_CheckState{0}", i + 1); checkDrawing.Checked = sp.GetBoolean(checkState, false); checkDrawing.CheckedChanged += CheckDrawingOnCheckedChanged; var txtBoxName = new TextBox(); txtBoxName.Size = new Size(50, 20); //textbox大小 txtBoxName.Location = new Point(41 + i%8*77, 7 + i/8*60); txtBoxName.Name = "txtName" + Convert.ToString(i + 1); txtBoxName.TextAlign = HorizontalAlignment.Center; var txtName_CustomPara = string.Format("SCOPE_TextName{0}", i + 1); var getName = sp.GetString(txtName_CustomPara, @"波形" + Convert.ToString(i + 1)); txtBoxName.Text = getName.Trim() != "" ? getName : string.Format("波形{0}", i + 1); txtBoxName.BackColor = _colorLine[i%8]; txtBoxName.TextChanged += ScopeTextNameChanged; txtBoxName.Enabled = checkDrawing.Checked; var buttonNewForm = new Button(); buttonNewForm.Size = new Size(66, 23); buttonNewForm.Location = new Point(25 + i%8*77, 34 + i/8*60); buttonNewForm.Name = "buttonDraw" + Convert.ToString(i + 1); buttonNewForm.Text = @"独立图像"; buttonNewForm.Click += ButtonNewFormOnClick; buttonNewForm.Enabled = checkDrawing.Checked; panel_Scope.Controls.Add(checkDrawing); panel_Scope.Controls.Add(txtBoxName); panel_Scope.Controls.Add(buttonNewForm); } }
private static void WriteToFile(string fileName, Editor editor) { //================================================================= var sp = new SharedPreferences(fileName); sp.Save(editor); }