using System; using System.Linq; using System.Collections.ObjectModel; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Text; using System.Threading; using System.Windows.Forms; using SmartX; using INT99DC_ImageDll; using INT99DC_7C.DialogForms; namespace INT99DC_7C.Forms { public partial class FormMotorSetting : Form { #region Field private FormMain m_ParentForm; #endregion #region Constructor public FormMotorSetting(FormMain parent) { InitializeComponent(); this.ParentForm = parent; } #endregion #region Property public FormMain ParentForm { get { return this.m_ParentForm; } private set { this.m_ParentForm = value; } } #endregion #region Method private void InitializeDesign() { ImageDll images = new ImageDll(); if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Korean) { } else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.English) { this.labelTitle.Text = "Motor settings"; this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDisable)); this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackDown)); this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.engBackUp)); this.labelTitleOriginOffsets.Text = "Origin offsets"; this.labelTitleOriginSpeed.Text = "Origin speed"; this.labelTitleSpeed1.Text = "Speed1"; this.labelTitlePosition0.Text = "Position0"; this.labelTitlePosition1.Text = "Position1"; this.labelTitlePosition2.Text = "Position2"; this.labelTitleMessage1.Text = "After setting up the servo driver,"; this.labelTitleMessage2.Text = "press EEPROM to save."; this.buttonOrigin.Text = "Origin"; this.buttonAlarmReset.Text = "Alarm Reset"; this.buttonPosition0.Text = "Position 0"; this.buttonPosition1.Text = "Position 1"; this.buttonPosition2.Text = "Position 2"; } else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese) { this.labelTitle.Text = "设置电机"; this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDisable)); this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackDown)); this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.chnBackUp)); this.buttonOpen.Text = "开"; this.buttonClose.Text = "关闭"; this.buttonParameterRead.Text = "全部读取"; this.buttonEEPROM.Text = "全部保存"; this.labelTitleID.Text = "身份证"; this.labelTitleOriginOffsets.Text = "原点复位"; this.labelTitleOriginSpeed.Text = "原点速度"; this.labelTitleSpeed1.Text = "速度1"; this.labelTitlePosition0.Text = "位置0"; this.labelTitlePosition1.Text = "位置1"; this.labelTitlePosition2.Text = "位置2"; this.labelTitleMessage1.Text = "设置后请务必点击[全部保存]"; this.labelTitleMessage2.Text = ""; this.buttonOrigin.Text = "原点"; this.buttonAlarmReset.Text = "警报复位"; this.buttonStep.Text = "步"; this.buttonPosition0.Text = "位置 0"; this.buttonPosition1.Text = "位置 1"; this.buttonPosition2.Text = "位置 2"; } else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech) { this.labelTitle.Text = "Nastavení motoru"; this.labelTitleID.Text = "ID"; this.labelTitleOriginOffsets.Text = "Ofset(Původ)"; this.labelTitleOriginSpeed.Text = "Rychlost(Původ)"; this.labelTitleSpeed1.Text = "Rychlost 1"; this.labelTitlePosition0.Text = this.buttonPosition0.Text = "Pozice 0"; this.labelTitlePosition1.Text = this.buttonPosition1.Text = "Pozice 1"; this.labelTitlePosition2.Text = this.buttonPosition2.Text = "Pozice 2"; this.labelTitleMessage1.Text = "Po nastavení servozesilovače"; this.labelTitleMessage2.Text = "stiskněte EEPROM pro uložení."; this.buttonOrigin.Text = "Původ"; this.buttonAlarmReset.Text = "Reset alarmu"; this.buttonStep.Text = "Krok"; this.buttonOpen.Text = "Otevřít"; this.buttonClose.Text = "Zavřít"; this.buttonParameterRead.Text = "Přečíst vše"; this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDisable)); this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackDown)); this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.czeBackUp)); } else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German) { this.labelTitle.Text = "Motoreinstellung"; this.labelTitleID.Text = "ID"; this.labelTitleOriginOffsets.Text = "Ursprungsoffset"; this.labelTitleOriginSpeed.Text = "Ursprungsgeschwindigkeit"; this.labelTitleSpeed1.Text = "Geschwindigkeit 1"; this.labelTitleMessage1.Text = "Stellen Sie nach dem Einstellen des Servoantriebs"; this.labelTitleMessage2.Text = "sicher, dass Sie es durch Drücken von [EEPROM]"; this.labelTitlePosition0.Text = this.buttonPosition0.Text = "Position 0"; this.labelTitlePosition1.Text = this.buttonPosition1.Text = "Position 1"; this.labelTitlePosition2.Text = this.buttonPosition2.Text = "Position 2"; this.buttonOrigin.Text = "Ursprung"; this.buttonParameterRead.Text = "Alles lesen"; this.buttonOpen.Text = "Öffnen"; this.buttonClose.Text = "Schließen"; this.buttonStep.Text = "Schritt"; this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDisable)); this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackDown)); this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.gerBackUp)); } else { } } private void InitializeControl() { } private void DefaultSetting() { } private void ModbusStatusDisplay(bool isOpen) { if (isOpen == true) { if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech) this.labelModusStatus.Text = "Otevřít"; else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German) this.labelModusStatus.Text = "Öffnen"; else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese) this.labelModusStatus.Text = "开"; else this.labelModusStatus.Text = "OPEN"; this.labelModusStatus.BackColor = Color.DarkGreen; this.labelModusStatus.ForeColor = Color.White; } else { if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech) this.labelModusStatus.Text = "Zavřít"; else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.German) this.labelModusStatus.Text = "Schließen"; else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese) this.labelModusStatus.Text = "关闭"; else this.labelModusStatus.Text = "CLOSE"; this.labelModusStatus.BackColor = Color.Crimson; this.labelModusStatus.ForeColor = Color.White; } } public void ModbusOpen() { if (this.ParentForm.smartModbus.IsOpen == true) this.ParentForm.smartModbus.PortClose(); try { this.ParentForm.smartModbus.PortOpen(); Thread.Sleep(200); this.ModbusStatusDisplay(this.ParentForm.smartModbus.IsOpen); } catch { } } public void ModbusClose() { this.ParentForm.smartModbus.PortClose(); this.ModbusStatusDisplay(this.ParentForm.smartModbus.IsOpen); } private string ServoMotorRead1(int slaveAddress, int parameterAddress) { int value = 0; byte[] readData = new byte[2]; this.ParentForm.smartModbus.SlaveAddress = slaveAddress; this.ParentForm.smartModbus.ReadHoldingRegister(parameterAddress, 1, ref readData); Array.Reverse(readData); value = BitConverter.ToInt16(readData, 0); return string.Format("{0}", value); } private string ServoMotorRead2(int slaveAddress, int parameterAddress) { int value = 0; byte[] readData = new byte[4]; this.ParentForm.smartModbus.SlaveAddress = slaveAddress; this.ParentForm.smartModbus.ReadHoldingRegister(parameterAddress, 2, ref readData); byte[] readData1 = new byte[4]; readData1[0] = readData[1]; readData1[1] = readData[0]; readData1[2] = readData[3]; readData1[3] = readData[2]; value = BitConverter.ToInt32(readData1, 0); return string.Format("{0}", value); } private void ServoMotorWrite1(int slaveAddress, int parameterAddress, int value, SmartLabel label) { this.ParentForm.smartModbus.SlaveAddress = slaveAddress; if (this.ParentForm.smartModbus.WriteSingleRegister(parameterAddress, value) == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS) { //MessageBox.Show("쓰기완료"); } label.Text = this.ServoMotorRead1(slaveAddress, parameterAddress); } private void ServoMotorWrite2(int slaveAddress, int parameterAddress, int value, SmartLabel label) { byte[] data = BitConverter.GetBytes(value); byte[] readData1 = new byte[4]; readData1[0] = data[1]; readData1[1] = data[0]; readData1[2] = data[3]; readData1[3] = data[2]; this.ParentForm.smartModbus.SlaveAddress = slaveAddress; if (this.ParentForm.smartModbus.WriteMultipleRegister(parameterAddress, 2, readData1) == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS) { //MessageBox.Show("쓰기완료"); } label.Text = this.ServoMotorRead2(slaveAddress, parameterAddress); } private void ServoMotorWrite(int slaveAddress, int parameterAddress, int value) { this.ParentForm.smartModbus.SlaveAddress = slaveAddress; if (this.ParentForm.smartModbus.WriteSingleRegister(parameterAddress, value) == SmartX.SmartModbus.EXCEPTIONCODE.SUCCESS) { //MessageBox.Show("쓰기완료"); } } public void UpdateDisplayAlarmView(AlarmList alarm) { if (alarm.IsServoOff == true || alarm.IsServoAlarm == true || alarm.IsServoTorqueAlarmTorque == true) { this.pictureBoxAlarm.Visible = true; this.listBoxAlarmMessage.Visible = true; } else { this.pictureBoxAlarm.Visible = false; this.listBoxAlarmMessage.Visible = false; } this.listBoxAlarmMessage.Items.Clear(); if (alarm.IsServoOff == true) this.listBoxAlarmMessage.Items.Add("Servo OFF"); if (alarm.IsServoAlarm == true) this.listBoxAlarmMessage.Items.Add("Servo Alarm"); if (alarm.IsServoTorqueAlarmTorque == true) this.listBoxAlarmMessage.Items.Add("Servo Torque Alarm"); } public void DisplayRefresh() { this.labelServoLimit.Text = this.ParentForm.SystemConfig.ServoLimit.ToString(); if (this.ParentForm.SystemConfig.CurrentUser.Group == DataStore.UserGroup.Developer) { this.labelServoLimit.Visible = this.labelTitleServoLimit.Visible = true; } else this.labelServoLimit.Visible = this.labelTitleServoLimit.Visible = false; this.ModbusClose(); this.labelOrigin.Text = "0"; this.labelSpeed0.Text = "0"; this.labelSpeed1.Text = "0"; this.labelPosition0.Text = "0"; this.labelPosition1.Text = "0"; this.labelPosition2.Text = "0"; this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormMotorSetting; this.ParentForm.TransferData(CommunicationCommand.ModeNormal, CommunicationID.MainBoard); } #endregion #region Override Member protected override void OnLoad(EventArgs e) { base.OnLoad(e); this.InitializeDesign(); this.InitializeControl(); this.DefaultSetting(); } #endregion #region Event Handler private void buttonBack_Click(object sender, EventArgs e) { this.ParentForm.ChildFormMenu.DisplayRefresh(); ((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu); } private void buttonOpen_Click(object sender, EventArgs e) { this.ModbusOpen(); } private void buttonClose_Click(object sender, EventArgs e) { this.ModbusClose(); } private void buttonParameterRead_Click(object sender, EventArgs e) { if (this.ParentForm.smartModbus.IsOpen == false) { // 통신 연결상태를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(23, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); return; } this.ParentForm.smartModbus.ReadTimeout = 500; SmartSplash splash = new SmartSplash(); splash.CenterPosition = true; splash.AnimationInterval = 200; splash.LoadingImagePathname = "SmartLoading4"; splash.Start(); this.Enabled = false; // ServoMotor 1 this.labelOrigin.Text = this.ServoMotorRead2(1, ServoMotorParameterAddress.CMD17); this.labelSpeed0.Text = this.ServoMotorRead1(1, ServoMotorParameterAddress.Speed0); this.labelSpeed1.Text = this.ServoMotorRead1(1, ServoMotorParameterAddress.Speed1); this.labelPosition0.Text = this.ServoMotorRead2(1, ServoMotorParameterAddress.CMD0); this.labelPosition1.Text = this.ServoMotorRead2(1, ServoMotorParameterAddress.CMD1); this.labelPosition2.Text = this.ServoMotorRead2(1, ServoMotorParameterAddress.CMD2); splash.Finish(); this.Enabled = true; } private void buttonOrigin_Click(object sender, EventArgs e) { this.ParentForm.TransferData(CommunicationCommand.MotorOrigin, CommunicationID.MainBoard); // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.MotorOrigin, ""); } private void buttonPosition0_Click(object sender, EventArgs e) { this.ParentForm.TransferData(CommunicationCommand.MotorPosition0, CommunicationID.MainBoard); // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.MotorPosition0, ""); } private void buttonPosition1_Click(object sender, EventArgs e) { this.ParentForm.TransferData(CommunicationCommand.MotorPosition1, CommunicationID.MainBoard); // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.MotorPosition1, ""); } private void buttonPosition2_Click(object sender, EventArgs e) { this.ParentForm.TransferData(CommunicationCommand.MotorPosition2, CommunicationID.MainBoard); // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.MotorPosition2, ""); } private void buttonStep_Click(object sender, EventArgs e) { this.ParentForm.TransferData(CommunicationCommand.MotorStep, CommunicationID.MainBoard); // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.MotorStep, ""); } private void buttonAlarmReset_Click(object sender, EventArgs e) { this.ParentForm.TransferData(CommunicationCommand.MotorAlarmReset, CommunicationID.MainBoard); // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.MotorAlarmReset, ""); } private void buttonEEPROM_Click(object sender, EventArgs e) { if (this.ParentForm.smartModbus.IsOpen == false) { // 통신 연결상태를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(23, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); return; } this.ServoMotorWrite(1, ServoMotorParameterAddress.SaveAllParameters, ServoMotorParameterAddress.EEPROM); } private void labelMotorParameterSetup_Click(object sender, EventArgs e) { string before = "", after = ""; SmartLabel label = sender as SmartLabel; int positiveLimit = 0, negativeLimit = 0; if (label == null) return; if (this.ParentForm.smartModbus.IsOpen == false || label.Text.Trim() == "0") { // 통신 연결상태를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(23, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); return; } positiveLimit = this.ParentForm.SystemConfig.ServoLimit; negativeLimit = this.ParentForm.SystemConfig.ServoLimit * -1; if (label == this.labelOrigin) { #region Origin before = label.Text; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelOrigin.Text, 6, 0, false, this.ParentForm.SystemConfig.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.doubleValue < negativeLimit || myKeyPad.doubleValue > positiveLimit) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); } else { this.ServoMotorWrite2(1, ServoMotorParameterAddress.CMD17, myKeyPad.IntValue, label); after = label.Text; // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.MotorOriginOffset, "", before, after); } } #endregion } else if (label == this.labelSpeed0) { #region Speed0 (원점 속도) before = label.Text; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSpeed0.Text, 5, 0, false, this.ParentForm.SystemConfig.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.doubleValue < 0|| myKeyPad.doubleValue > 20000) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); } else { //this.labelSpeed0.Text = myKeyPad.StringValue; this.ServoMotorWrite1(1, ServoMotorParameterAddress.Speed0, myKeyPad.IntValue, label); after = label.Text; // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.MotorOriginSpeed, "", before, after); } } #endregion } else if (label == this.labelSpeed1) { #region Speed 1 before = label.Text; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSpeed1.Text, 5, 0, false, this.ParentForm.SystemConfig.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 20000) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); } else { //this.labelSpeed1.Text = myKeyPad.StringValue; this.ServoMotorWrite1(1, ServoMotorParameterAddress.Speed1, myKeyPad.IntValue, label); after = label.Text; // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.MotorSpeed, "", before, after); } } #endregion } else if (label == this.labelPosition0) { #region Position 0 before = label.Text; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelPosition0.Text, 6, 0, true, this.ParentForm.SystemConfig.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.doubleValue < negativeLimit || myKeyPad.doubleValue > positiveLimit) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); } else { this.ServoMotorWrite2(1, ServoMotorParameterAddress.CMD0, myKeyPad.IntValue, label); after = label.Text; // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.MotorPosition0, "", before, after); } } #endregion } else if (label == this.labelPosition1) { #region Position 1 before = label.Text; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelPosition1.Text, 6, 0, true, this.ParentForm.SystemConfig.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.doubleValue < negativeLimit || myKeyPad.doubleValue > positiveLimit) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); } else { this.ServoMotorWrite2(1, ServoMotorParameterAddress.CMD1, myKeyPad.IntValue, label); after = label.Text; // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.MotorPosition1, "", before, after); } } #endregion } else if (label == this.labelPosition2) { #region Position 2 before = label.Text; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelPosition2.Text, 6, 0, false, this.ParentForm.SystemConfig.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.doubleValue < negativeLimit || myKeyPad.doubleValue > positiveLimit) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); } else { this.ServoMotorWrite2(1, ServoMotorParameterAddress.CMD2, myKeyPad.IntValue, label); after = label.Text; // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.MotorPosition2, "", before, after); } } #endregion } } private void labelServoLimit_Click(object sender, EventArgs e) { string before = "", after = ""; before = this.labelServoLimit.Text; DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelServoLimit.Text, 6, 0, false, this.ParentForm.SystemConfig.Language); if (myKeyPad.ShowDialog() == DialogResult.OK) { if (myKeyPad.doubleValue == 0 || myKeyPad.doubleValue > 999999) { // 입력범위를 확인하세요 DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language); myMsg.ShowDialog(); } else { this.labelServoLimit.Text = myKeyPad.StringValue; after = this.labelServoLimit.Text; this.ParentForm.SystemConfig.ServoLimit = myKeyPad.IntValue; this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig); // Part 11 if (this.ParentForm.SystemConfig.IsPart11 == true) this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.MotorSorvoLimit, "", before, after); } } } private void pictureBoxAlarm_Click(object sender, EventArgs e) { if (this.listBoxAlarmMessage.Visible == false) this.listBoxAlarmMessage.Visible = true; else this.listBoxAlarmMessage.Visible = false; } #endregion } }