using System; using System.Linq; using System.Collections.ObjectModel; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using SmartX; using ITC81DB_0H.Forms; using ITC81DB_0H.DialogForms; using ITC81DB_0H_ImageDll; namespace ITC81DB_0H.Controls { public partial class ControlCenterSystemBLDCMotorSetting : UserControl { #region Field private FormMenu m_ParentForm; private string CommID; private int MotorIndex; #endregion #region Constructor public ControlCenterSystemBLDCMotorSetting(FormMenu parent) { InitializeComponent(); this.ParentForm = parent; this.DefaultSetting(); this.InitializeDesign(); } #endregion #region Property public FormMenu ParentForm { get { return this.m_ParentForm; } private set { this.m_ParentForm = value; } } #endregion #region Method public void InitializeDesign() { Class1 images = new Class1(); if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.English) { } else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Chinese) { } else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Czech) { } else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.Russian) { } else if (this.ParentForm.ParentForm.SystemConfig1.Language == DataStore.LanguageID.German) { } else { } } private void DefaultSetting() { this.MotorIndex = 0; this.CommID = "A"; this.comboBoxMotorPoleNum.Items.Clear(); this.comboBoxMotorPoleNum.Items.Add("3"); this.comboBoxMotorPoleNum.Items.Add("6"); this.comboBoxMotorPoleNum.Items.Add("9"); this.comboBoxMotorPoleNum.Items.Add("12"); this.comboBoxMotorPoleNum.Items.Add("15"); this.VisibleMotorNum(this.ParentForm.ParentForm.SystemConfig2.BLDCMotorNum); } private void RefreshDisplay() { this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, this.CommID, CommunicationAddress.BLDCMotorParameterRead, ""); } public void DisplayRPM() { this.labelMotorRPM.Text = this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]._6734_MotorRPM; } public void VisibleMotorNum(int num) { Collection button = new Collection(); button.Clear(); button.Add(this.buttonMotor1); button.Add(this.buttonMotor2); button.Add(this.buttonMotor3); button.Add(this.buttonMotor4); for (int i = num; i < FormMain.BLDCMotorNum; i++) button[i].Visible = false; } public void UpdateAlarm(int index, Collection items) { this.listBoxAlarm.Items.Clear(); if (items[index]._6790_Alarm_FaultSignal == true) this.listBoxAlarm.Items.Add("Detect Fault Signal"); if (items[index]._6791_Alarm_HallSensorError == true) this.listBoxAlarm.Items.Add("Hall Sensor Error"); if (items[index]._6792_Alarm_MotorStop == true) this.listBoxAlarm.Items.Add("Motor stopped while operating"); } public void UpdateParameter(int index, Collection items) { this.labelVersionMajor.Text = items[index]._6730_VersionMajor + "."; this.labelVersionMinor.Text = items[index]._6731_VersionMinor + "."; this.labelVersionBuild.Text = items[index]._6732_VersionBuild; this.labelMotorRPM.Text = items[index]._6734_MotorRPM.ToString(); switch (items[index]._6735_MotorDirection) { case 0: this.labelMotorDirectionRead.Text = "None"; break; case 1: this.labelMotorDirectionRead.Text = "CW"; break; case 2: this.labelMotorDirectionRead.Text = "CCW"; break; default: this.labelMotorDirectionRead.Text = "None"; break; } switch (items[index]._6765_SelectOperMode) { case 0: this.labelSelectOperMode.Text = "MCU"; break; case 1: this.labelSelectOperMode.Text = "Manual"; break; default: this.labelMotorDirectionRead.Text = "MCU"; break; } } public void DisplayParameter(int index, Collection items) { this.labelMotorID.Text = items[index].MotorID.ToString(); this.labelMotorSpeed.Text = items[index]._6704_MotorSpeed.ToString(); this.comboBoxMotorPoleNum.SelectedIndex = items[index]._6705_PoleNum; this.labelAttenuatorRatio.Text = items[index]._6706_AttenuatorRatio.ToString(); if (items[index]._6764_OperDirection == 1) this.buttonMotorDirectionWrite.ButtonDown(); else this.buttonMotorDirectionWrite.ButtonUp(); } public void DisplayRefresh(SystemStatus status, Collection items) { this.ParentForm.ParentForm.CurrentSystemStatus.CurrentDisplay = DataStore.DisplayStore.SystemBLDCMotorSetting; this.ParentForm.ParentForm.SetDisplayMode(DataStore.DisplayMode.Menu); this.ParentForm.DisplayTitleRoot(this.ParentForm.ParentForm.CurrentSystemStatus); this.MotorIndex = 0; this.CommID = "A"; this.buttonMotor1.ButtonDown(); this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, this.CommID, CommunicationAddress.BLDCMotorParameterRead, ""); this.DisplayParameter(0, items); } #endregion #region Event Handler private void buttonMotor_Click(object sender, EventArgs e) { SmartX.SmartButton button = sender as SmartX.SmartButton; this.MotorIndex = int.Parse(button.Tag.ToString()); this.CommID = this.ParentForm.ParentForm.CurrentCommunicationID (this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex].MotorID); this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, this.CommID, CommunicationAddress.BLDCMotorParameterRead, ""); this.DisplayParameter(this.MotorIndex, this.ParentForm.ParentForm.CollectionBLDCParameter); } private void buttonDefaultSet_Click(object sender, EventArgs e) { DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 25); if (myDlg.ShowDialog() == DialogResult.Yes) { this.ParentForm.ParentForm.TransferData(CommunicationCommand.BLDCDefaultSet, CommunicationID.MainBoard); for (int i = 0; i < FormMain.BLDCMotorNum; i++) { this.ParentForm.ParentForm.CollectionBLDCParameter[i]._6704_MotorSpeed = 80; this.ParentForm.ParentForm.CollectionBLDCParameter[i]._6705_PoleNum = 1; this.ParentForm.ParentForm.CollectionBLDCParameter[i]._6706_AttenuatorRatio = 5; this.ParentForm.ParentForm.CollectionBLDCParameter[i]._6764_OperDirection = 1; } this.ParentForm.ParentForm.SaveBLDCMotorFile(this.ParentForm.ParentForm.CollectionBLDCParameter); //this.ParentForm.ParentForm.TransferBLDCMotorData // (this.CommID, this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]); } } private void buttonReboot_Click(object sender, EventArgs e) { DialogFormYesNo myDlg = new DialogFormYesNo(this.ParentForm.ParentForm.SystemConfig1.Language, 26); if (myDlg.ShowDialog() == DialogResult.Yes) { this.ParentForm.ParentForm.TransferData(CommunicationCommand.BLDCMCUReboot, CommunicationID.MainBoard); } } private void buttonRefresh_Click(object sender, EventArgs e) { this.RefreshDisplay(); } private void buttonStart_Click(object sender, EventArgs e) { if (this.buttonStart.ButtonStatus == SmartButton.BUTSTATUS.DOWN) { this.ParentForm.ParentForm.TransferData(CommunicationCommand.Start, this.CommID); this.timer.Start(); } else { this.ParentForm.ParentForm.TransferData(CommunicationCommand.Stop, this.CommID); this.timer.Stop(); } } private void labelMotorID_Click(object sender, EventArgs e) { string value = "", message = ""; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelMotorID.Text, 2, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.IntValue < 1 || myKeyPad.IntValue > 16) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message); myMsg.ShowDialog(); } else { this.labelMotorID.Text = myKeyPad.StringValue; this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex].MotorID = myKeyPad.IntValue; value = Helper.StringZeroFillDigits4(myKeyPad.StringValue); this.ParentForm.ParentForm.SaveBLDCMotorFile(this.ParentForm.ParentForm.CollectionBLDCParameter); this.ParentForm.ParentForm.TransferBLDCMotorData (this.CommID, this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]); } } } private void labelMotorSpeed_Click(object sender, EventArgs e) { string value = "", message = ""; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelMotorSpeed.Text, 3, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.IntValue < 0 || myKeyPad.IntValue > 100) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message); myMsg.ShowDialog(); } else { this.labelMotorSpeed.Text = myKeyPad.StringValue; this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]._6704_MotorSpeed = myKeyPad.IntValue; value = Helper.StringZeroFillDigits4(myKeyPad.StringValue); this.ParentForm.ParentForm.SaveBLDCMotorFile(this.ParentForm.ParentForm.CollectionBLDCParameter); this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, this.CommID, CommunicationAddress.BLDCMotorSpeed, value); } } } private void comboBoxMotorPoleNum_SelectedIndexChanged(object sender, EventArgs e) { string value = ""; this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]._6705_PoleNum = this.comboBoxMotorPoleNum.SelectedIndex; value = Helper.StringZeroFillDigits4(this.comboBoxMotorPoleNum.SelectedIndex.ToString()); this.ParentForm.ParentForm.SaveBLDCMotorFile(this.ParentForm.ParentForm.CollectionBLDCParameter); this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, this.CommID, CommunicationAddress.BLDCPoleNum, value); } private void labelAttenuatorRatio_Click(object sender, EventArgs e) { string value = "", message = ""; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelAttenuatorRatio.Text, 4, 0, false, this.ParentForm.ParentForm.SystemConfig1.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.IntValue < 1 || myKeyPad.IntValue > 9999) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.ParentForm.SystemConfig1.Language, message); myMsg.ShowDialog(); } else { this.labelAttenuatorRatio.Text = myKeyPad.StringValue; this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]._6706_AttenuatorRatio = myKeyPad.IntValue; value = Helper.StringZeroFillDigits4(myKeyPad.StringValue); this.ParentForm.ParentForm.SaveBLDCMotorFile(this.ParentForm.ParentForm.CollectionBLDCParameter); this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, this.CommID, CommunicationAddress.BLDCAttenuatorRatio, value); } } } private void buttonMotorDirectionWrite_Click(object sender, EventArgs e) { string value = ""; if (this.buttonMotorDirectionWrite.ButtonStatus == SmartButton.BUTSTATUS.DOWN) this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]._6764_OperDirection = 1; // CCW else this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]._6764_OperDirection = 0; // CW this.ParentForm.ParentForm.SaveBLDCMotorFile(this.ParentForm.ParentForm.CollectionBLDCParameter); value = Helper.StringZeroFillDigits4(this.ParentForm.ParentForm.CollectionBLDCParameter[this.MotorIndex]._6764_OperDirection.ToString()); this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Write, this.CommID, CommunicationAddress.BLDCOperDirection, value); this.RefreshDisplay(); } private void timer_Tick(object sender, EventArgs e) { this.ParentForm.ParentForm.TransferDataStream(CommunicationCommand.Read, this.CommID, CommunicationAddress.BLDCMotorRPM, ""); } #endregion } }