INT63DC_2C/INT63DC_2C/Forms/FormMotorSetting.cs

607 lines
28 KiB
C#

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 INT63DC_ImageDll;
using INT63DC_2C.DialogForms;
namespace INT63DC_2C.Forms
{
public partial class FormMotorSetting : Form
{
#region Field
private FormMain m_ParentForm;
private JudgmentSetItem SelectedJudgmentSetItem;
#endregion
#region Constructor
public FormMotorSetting(FormMain parent)
{
InitializeComponent();
this.ParentForm = parent;
this.InitializeDesign();
this.InitializeControl();
this.DefaultSetting();
}
#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();
switch (this.ParentForm.SystemConfig.Language)
{
case DataStore.LanguageID.Korean:
this.labelTitleMessage4.Text = "";
break;
case DataStore.LanguageID.English:
#region English
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.buttonOrigin.Text = "Origin";
this.buttonAlarmReset.Text = "Alarm Reset";
this.labelTitle.Text = "Motor settings";
this.labelTitleOriginOffsets.Text = "Origin offsets";
this.labelTitleOriginSpeed.Text = "Origin speed";
this.labelTitleSpeed1.Text = "Speed1";
this.labelTitleAcceleration1.Text = "Acceleration1";
this.labelTitleDeceleration1.Text = "Deceleration1";
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.labelTitleMessage3.Text = "Be sure to execute the origin after jog operation.";
this.labelTitleMessage4.Text = "";
#endregion
break;
case DataStore.LanguageID.Chinese:
#region Chinese
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.buttonOrigin.Text = "原点";
this.buttonAlarmReset.Text = "警报复位";
this.buttonStep.Text = "步";
this.labelTitle.Text = "设置电机";
this.labelTitleID.Text = "身份证";
this.labelTitleOriginOffsets.Text = "原点复位";
this.labelTitleOriginSpeed.Text = "原点速度";
this.labelTitleSpeed1.Text = "速度1";
this.labelTitleAcceleration1.Text = "加速 1";
this.labelTitleDeceleration1.Text = "减速 1";
this.labelTitlePosition0.Text = "位置0";
this.labelTitlePosition1.Text = "位置1";
this.labelTitlePosition2.Text = "位置2";
this.labelTitleMessage1.Text = "设置后请务必点击[全部保存]";
this.labelTitleMessage2.Text = "";
this.labelTitleMessage3.Text = "点转运行操作结束后务必实行原点复位.";
this.labelTitleMessage4.Text = "";
#endregion
break;
case DataStore.LanguageID.Czech:
#region Czech
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));
this.buttonOpen.Text = "Otevřít";
this.buttonClose.Text = "Zavřít";
this.buttonParameterRead.Text = "Přečíst vše";
this.buttonOrigin.Text = "Původ";
this.buttonAlarmReset.Text = "Reset alarmu";
this.buttonStep.Text = "Krok";
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.labelTitleAcceleration1.Text = "Zrychlení 1";
this.labelTitleDeceleration1.Text = "Zpomalení 1";
this.labelTitlePosition0.Text = "Pozice 0";
this.labelTitlePosition1.Text = "Pozice 1";
this.labelTitlePosition2.Text = "Pozice 2";
this.labelTitleMessage1.Text = "Po nastavení servozesilovače";
this.labelTitleMessage2.Text = "stiskněte EEPROM pro uložení.";
this.labelTitleMessage3.Text = "Ujistěte se, že jste provedli počátek po";
this.labelTitleMessage4.Text = "operaci krokování.";
#endregion
break;
case DataStore.LanguageID.German:
#region German
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));
this.buttonOpen.Text = "Öffnen";
this.buttonClose.Text = "Schließen";
this.buttonParameterRead.Text = "Alles lesen";
this.buttonOrigin.Text = "Ursprung";
this.buttonStep.Text = "Schritt";
this.labelTitle.Text = "Motoreinstellung";
this.labelTitleID.Text = "ID";
this.labelTitleOriginOffsets.Text = "Ursprungsoffset";
this.labelTitleOriginSpeed.Text = "Ursprungsgeschwindigkeit";
this.labelTitleSpeed1.Text = "Geschwindigkeit 1";
this.labelTitleAcceleration1.Text = "Beschleunigung 1";
this.labelTitleDeceleration1.Text = "Verzögerung 1";
this.labelTitlePosition0.Text = "Position 0";
this.labelTitlePosition1.Text = "Position 1";
this.labelTitlePosition2.Text = "Position 2";
this.labelTitleMessage1.Text = "Stellen Sie nach dem Einstellen des Servoantriebs";
this.labelTitleMessage2.Text = "sicher, dass Sie es durch Drücken von [EEPROM]";
this.labelTitleMessage3.Text = "Achten Sie darauf, den Nullpunkt nach dem";
this.labelTitleMessage4.Text = "Jog-Betrieb auszuführen.";
#endregion
break;
case DataStore.LanguageID.Japanese:
#region Japanese
this.buttonBack.DisableImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDisable));
this.buttonBack.DownImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackDown));
this.buttonBack.UpImage = new Bitmap(images.GetImage(ImageDll.ButtonImages.jpnBackUp));
this.buttonOrigin.Text = "原点";
this.buttonAlarmReset.Text = "アラㅡムリセット";
this.labelTitle.Text = "モㅡタㅡ 設定";
this.labelTitleOriginOffsets.Text = "原点オフセット";
this.labelTitleOriginSpeed.Text = "原点速度";
this.labelTitleSpeed1.Text = "速度";
this.labelTitleAcceleration1.Text = "加速度";
this.labelTitleDeceleration1.Text = "減速";
this.buttonParameterRead.Text = "全て読む";
this.buttonStep.Text = "ステップ";
this.labelTitlePosition0.Text = "位置 0";
this.labelTitlePosition1.Text = "位置 1";
this.labelTitlePosition2.Text = "位置 2";
this.labelTitleMessage1.Text = "サㅡボドライバを設定したら、";
this.labelTitleMessage2.Text = "EEPROMを押して保存します。";
this.labelTitleMessage3.Text = "ジョグ動作後は必ず原点復帰を実行してください。";
this.labelTitleMessage4.Text = "";
#endregion
break;
default:
break;
}
}
private void InitializeControl()
{
}
private void DefaultSetting()
{
this.SelectedJudgmentSetItem = new JudgmentSetItem();
}
private void ParameterAllRead()
{
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.ParentForm.ServoMotorRead2(1, ServoMotorParameterAddress.CMD16);
this.labelSpeed0.Text = this.ParentForm.ServoMotorRead1(1, ServoMotorParameterAddress.Speed0);
this.labelSpeed1.Text = this.ParentForm.ServoMotorRead1(1, ServoMotorParameterAddress.Speed1);
this.labelAcceleration1.Text = this.ParentForm.ServoMotorRead1(1, ServoMotorParameterAddress.Acceleration1);
this.labelDeceleration1.Text = this.ParentForm.ServoMotorRead1(1, ServoMotorParameterAddress.Deceleration1);
//this.labelPosition0.Text = this.ParentForm.ServoMotorRead2(1, ServoMotorParameterAddress.CMD0);
this.labelPosition1.Text = this.ParentForm.ServoMotorRead2(1, ServoMotorParameterAddress.CMD1);
//this.labelPosition2.Text = this.ParentForm.ServoMotorRead2(1, ServoMotorParameterAddress.CMD2);
splash.Finish();
this.Enabled = true;
}
public 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 if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
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 if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Japanese)
this.labelModusStatus.Text = "クロㅡズ";
else
this.labelModusStatus.Text = "CLOSE";
this.labelModusStatus.BackColor = Color.Crimson;
this.labelModusStatus.ForeColor = Color.White;
}
}
public void UpdateDisplayAlarmView(AlarmList alarm)
{
if (alarm.IsServoOff == true || alarm.IsServoAlarm == true || alarm.IsServoAlarmTorque == 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.IsServoAlarmTorque == true)
this.listBoxAlarmMessage.Items.Add("Servo Torque Alarm");
}
public void DisplayRefresh()
{
this.labelOrigin.Text = "0";
this.labelSpeed0.Text = "0";
this.labelSpeed1.Text = "0";
this.labelAcceleration1.Text = "0";
this.labelDeceleration1.Text = "0";
this.labelPosition0.Text = "0";
this.labelPosition1.Text = "0";
this.labelPosition2.Text = "0";
this.labelModusStatus.Visible = false;
this.buttonOpen.Visible = false;
this.buttonClose.Visible = false;
this.ModbusStatusDisplay(this.ParentForm.smartModbus.IsOpen);
this.ParentForm.LoadJudgmentSetFile(ref this.SelectedJudgmentSetItem, this.ParentForm.SystemConfig.ProductNumber - 1);
this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormMotorSetting;
this.ParentForm.TransferData(CommunicationCommand.ModeNormal, CommunicationID.MainBoard);
this.smartTimer2.Interval = 100;
this.smartTimer2.Start();
}
#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.ParentForm.ModbusOpen();
this.ModbusStatusDisplay(this.ParentForm.smartModbus.IsOpen);
}
private void buttonClose_Click(object sender, EventArgs e)
{
this.ParentForm.ModbusClose();
this.ModbusStatusDisplay(this.ParentForm.smartModbus.IsOpen);
}
private void buttonParameterRead_Click(object sender, EventArgs e)
{
this.ParameterAllRead();
}
private void buttonOrigin_Click(object sender, EventArgs e)
{
this.ParentForm.TransferData(CommunicationCommand.MotorOrigin, CommunicationID.MainBoard);
this.buttonBack.Enabled = true;
this.ParentForm.IsServoOrigin = false;
}
private void buttonStep_Click(object sender, EventArgs e)
{
this.ParentForm.TransferData(CommunicationCommand.MotorStep, CommunicationID.MainBoard);
}
private void buttonAlarmReset_Click(object sender, EventArgs e)
{
this.ParentForm.TransferData(CommunicationCommand.MotorAlarmReset, CommunicationID.MainBoard);
this.ParentForm.TransferData(CommunicationCommand.BuzzerOff, CommunicationID.MainBoard);
}
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.ParentForm.ServoMotorWrite(1, ServoMotorParameterAddress.SaveAllParameters, ServoMotorParameterAddress.EEPROM);
}
private void buttonHidden_Click(object sender, EventArgs e)
{
this.labelModusStatus.Visible = true;
this.buttonOpen.Visible = true;
this.buttonClose.Visible = true;
}
private void buttonJogCW_MouseDown(object sender, MouseEventArgs e)
{
this.buttonBack.Enabled = false;
this.ParentForm.TransferData(CommunicationCommand.MotorJogCwOn, CommunicationID.MainBoard);
}
private void buttonJogCW_MouseUp(object sender, MouseEventArgs e)
{
this.ParentForm.TransferData(CommunicationCommand.MotorJogCwOff, CommunicationID.MainBoard);
this.buttonJogCW.Enabled = false;
this.buttonJogCCW.Enabled = false;
this.smartTimer1.Start();
}
private void buttonJogCCW_MouseDown(object sender, MouseEventArgs e)
{
this.buttonBack.Enabled = false;
this.ParentForm.TransferData(CommunicationCommand.MotorJogCcwOn, CommunicationID.MainBoard);
}
private void buttonJogCCW_MouseUp(object sender, MouseEventArgs e)
{
this.ParentForm.TransferData(CommunicationCommand.MotorJogCcwOff, CommunicationID.MainBoard);
this.buttonJogCW.Enabled = false;
this.buttonJogCCW.Enabled = false;
this.smartTimer1.Start();
}
private void labelMotorParameterSetup_Click(object sender, EventArgs e)
{
SmartLabel label = sender as SmartLabel;
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;
}
if (label == this.labelOrigin)
{
#region Origin
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelOrigin.Text, 6, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue == 0)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.ParentForm.ServoMotorWrite2(1, ServoMotorParameterAddress.CMD16, myKeyPad.IntValue, label);
}
}
#endregion
}
else if (label == this.labelSpeed0)
{
#region Speed0 (원점 속도)
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.ParentForm.ServoMotorWrite1(1, ServoMotorParameterAddress.Speed0, myKeyPad.IntValue, label);
}
}
#endregion
}
else if (label == this.labelSpeed1)
{
#region Speed 1
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.ParentForm.ServoMotorWrite1(1, ServoMotorParameterAddress.Speed1, myKeyPad.IntValue, label);
this.SelectedJudgmentSetItem.FeedSpeed = int.Parse(label.Text);
this.ParentForm.SaveJudgmentSetFile(this.SelectedJudgmentSetItem, this.ParentForm.SystemConfig.ProductNumber - 1);
}
}
#endregion
}
else if (label == this.labelAcceleration1)
{
#region Acceleration1
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelAcceleration1.Text, 5, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 10000)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.ParentForm.ServoMotorWrite1(1, ServoMotorParameterAddress.Acceleration1, myKeyPad.IntValue, label);
}
}
#endregion
}
else if (label == this.labelDeceleration1)
{
#region Deceleration1
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelDeceleration1.Text, 5, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 10000)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.ParentForm.ServoMotorWrite1(1, ServoMotorParameterAddress.Deceleration1, myKeyPad.IntValue, label);
}
}
#endregion
}
else if (label == this.labelPosition0)
{
#region Position 0
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelPosition0.Text, 6, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue == 0)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.ParentForm.ServoMotorWrite2(1, ServoMotorParameterAddress.CMD0, myKeyPad.IntValue, label);
}
}
#endregion
}
else if (label == this.labelPosition1)
{
#region Position 1
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelPosition1.Text, 6, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue == 0)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.ParentForm.ServoMotorWrite2(1, ServoMotorParameterAddress.CMD1, myKeyPad.IntValue, label);
}
}
#endregion
}
else if (label == this.labelPosition2)
{
#region Position 2
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelPosition2.Text, 6, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue == 0)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.ParentForm.ServoMotorWrite2(1, ServoMotorParameterAddress.CMD2, myKeyPad.IntValue, label);
}
}
#endregion
}
}
private void pictureBoxAlarm_Click(object sender, EventArgs e)
{
if (this.listBoxAlarmMessage.Visible == false)
this.listBoxAlarmMessage.Visible = true;
else
this.listBoxAlarmMessage.Visible = false;
}
private void smartTimer1_Tick(object sender, EventArgs e)
{
this.smartTimer1.Stop();
this.buttonJogCW.Enabled = true;
this.buttonJogCCW.Enabled = true;
}
private void smartTimer2_Tick(object sender, EventArgs e)
{
this.smartTimer2.Stop();
this.ParameterAllRead();
}
#endregion
}
}