INT69DC_7C/INT69DC_7C/Forms/FormCommunication.cs

1793 lines
76 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using SmartX;
using INT69DC_ImageDll;
using INT69DC_7C.DialogForms;
namespace INT69DC_7C.Forms
{
public partial class FormCommunication : Form
{
#region Field
private FormMain m_ParentForm;
#endregion
#region Constructor
public FormCommunication(FormMain parent)
{
InitializeComponent();
this.ParentForm = parent;
this.InitializeDesign();
this.InitializeControl();
this.DefaultSetting();
}
#endregion
#region Property
public FormMain ParentForm
{
get { return this.m_ParentForm; }
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 = "Communication";
this.labelStaticTcpOperationMode.Text = "Operation mode";
this.labelStaticTcpMode.Text = "mode";
this.labelStaticSerialBaudrate.Text = "Baudrate";
this.labelStaticSerialMode.Text = "Mode";
this.labelHelp.Text = "When IP configuration is changed, it is normally connected after rebooting.";
this.buttonTcpSave1.Text = "SAVE";
this.buttonTcpSave2.Text = "SAVE";
this.buttonSerialSave.Text = "SAVE";
this.buttonStart.Text = "START";
this.buttonStop.Text = "STOP";
this.buttonSend.Text = "SEND";
this.buttonSerialSend.Text = "SEND";
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));
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Chinese)
{
this.labelTitle.Text = "通讯设置";
this.labelStaticTcpOperationMode.Text = "运转模式";
this.labelStaticTcpMode.Text = "模式";
this.labelStaticSerialBaudrate.Text = "波特率";
this.labelStaticSerialMode.Text = "模式";
this.labelHelp.Text = "更改IP配置时重启后正常连接.";
this.buttonTcpSave1.Text = "保存";
this.buttonTcpSave2.Text = "保存";
this.buttonSerialSave.Text = "保存";
this.buttonStart.Text = "开启";
this.buttonStop.Text = "停止";
this.buttonSend.Text = "发送";
this.buttonSerialSend.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));
}
else if (this.ParentForm.SystemConfig.Language == DataStore.LanguageID.Czech)
{
this.labelTitle.Text = "Nastavení komunikace";
this.labelStaticTcpOperationMode.Text = "operační mód";
this.labelStaticTcpMode.Text = "Režim";
this.labelStaticSerialBaudrate.Text = "Přenosová rychlost";
this.labelStaticSerialMode.Text = "Režim";
this.labelHelp.Text = "Při změně konfigurace IP se po restartu normálně připojí.";
this.buttonTcpSave1.Text = "Uložit";
this.buttonTcpSave2.Text = "Uložit";
this.buttonSerialSave.Text = "Uložit";
this.buttonStart.Text = "Start";
this.buttonStop.Text = "Stop";
this.buttonSend.Text = "poslat";
this.buttonSerialSend.Text = "poslat";
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 = "Kommunikationseinstellungen";
this.labelStaticTcpOperationMode.Text = "Betriebsmodus";
this.labelStaticTcpMode.Text = "Modus";
this.labelStaticSerialBaudrate.Text = "Baudrate";
this.labelStaticSerialMode.Text = "Modus";
this.labelHelp.Text = "Wenn die IP-Konfiguration geändert wird, wird die Verbindung nach dem Neustart normal hergestellt.";
this.buttonTcpSave1.Text = "Speichern";
this.buttonTcpSave2.Text = "Speichern";
this.buttonSerialSave.Text = "Speichern";
this.buttonStart.Text = "Start";
this.buttonStop.Text = "Stop";
this.buttonSend.Text = "senden";
this.buttonSerialSend.Text = "senden";
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()
{
this.comboBoxOperationMode.Items.Clear();
this.comboBoxOperationMode.SelectedIndexChanged -= new EventHandler(this.comboBoxOperationMode_SelectedIndexChanged);
this.comboBoxOperationMode.Items.Add("None");
this.comboBoxOperationMode.Items.Add("Server");
this.comboBoxOperationMode.Items.Add("Client");
this.comboBoxOperationMode.SelectedIndex = 0;
this.comboBoxOperationMode.SelectedIndexChanged += new EventHandler(this.comboBoxOperationMode_SelectedIndexChanged);
this.comboBoxMode.Items.Clear();
this.comboBoxMode.SelectedIndexChanged -= new EventHandler(this.comboBoxMode_SelectedIndexChanged);
this.comboBoxMode.Items.Add("None");
this.comboBoxMode.Items.Add("OPT2");
this.comboBoxMode.Items.Add("OPT3");
this.comboBoxMode.Items.Add("Modbus");
this.comboBoxMode.Items.Add("OPT5");
this.comboBoxMode.SelectedIndex = 0;
this.comboBoxMode.SelectedIndexChanged += new EventHandler(this.comboBoxMode_SelectedIndexChanged);
this.comboBoxSerial3BaudRate.Items.Clear();
this.comboBoxSerial3BaudRate.SelectedIndexChanged -= new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3BaudRate.Items.Add(9600);
this.comboBoxSerial3BaudRate.Items.Add(19200);
this.comboBoxSerial3BaudRate.Items.Add(38400);
this.comboBoxSerial3BaudRate.Items.Add(115200);
this.comboBoxSerial3BaudRate.SelectedIndex = 0;
this.comboBoxSerial3BaudRate.SelectedIndexChanged += new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3Mode.Items.Clear();
this.comboBoxSerial3Mode.SelectedIndexChanged -= new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3Mode.Items.Add("None");
this.comboBoxSerial3Mode.Items.Add("OPT1");
this.comboBoxSerial3Mode.Items.Add("OPT2");
this.comboBoxSerial3Mode.Items.Add("OPT3");
this.comboBoxSerial3Mode.Items.Add("OPT4");
this.comboBoxSerial3Mode.Items.Add("Printer");
this.comboBoxSerial3Mode.Items.Add("OPT5");
this.comboBoxSerial3Mode.SelectedIndex = 0;
this.comboBoxSerial3Mode.SelectedIndexChanged += new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
}
private void DefaultSetting()
{
string[] sValue;
#region TCP
if (this.ParentForm.SystemConfig.IsEthernetEnable == true)
{
this.buttonStart.Enabled = true;
this.buttonStop.Enabled = true;
}
else
{
this.buttonStart.Enabled = false;
this.buttonStop.Enabled = false;
}
this.labelServerStatus.Text = "-";
this.labelClientStatus.Text = "-";
this.labelConnectedIP.Text = "-";
// Host IP
if (this.ParentForm.SystemConfig.EthernetServerAddress == "")
{
this.ParentForm.SystemConfig.EthernetServerAddress = "0.0.0.0";
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
}
sValue = this.ParentForm.SystemConfig.EthernetServerAddress.Split('.');
this.labelHostIP1.Text = sValue[0];
this.labelHostIP2.Text = sValue[1];
this.labelHostIP3.Text = sValue[2];
this.labelHostIP4.Text = sValue[3];
this.labelHostPort.Text = this.ParentForm.SystemConfig.EthernetServerPort.ToString();
this.labelLocalPort.Text = this.ParentForm.SystemConfig.EthernetLocalPort.ToString();
//this.labelLocalPort.Text = this.ParentForm.smartTCPMultiServer.Port.ToString();
this.buttonTcpSave1.Enabled = false;
this.buttonTcpSave2.Enabled = false;
#endregion
#region Serial
this.comboBoxSerial3BaudRate.SelectedIndexChanged -= new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3BaudRate.SelectedIndex = this.ParentForm.SystemConfig.Serial3BaudRate;
this.comboBoxSerial3BaudRate.SelectedIndexChanged += new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3Mode.SelectedIndexChanged -= new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3Mode.SelectedIndex = this.ParentForm.SystemConfig.Serial3Mode;
if (this.comboBoxSerial3Mode.SelectedIndex == 5)
this.comboBoxSerial3BaudRate.Enabled = false;
this.comboBoxSerial3Mode.SelectedIndexChanged += new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
if (this.ParentForm.SystemConfig.Serial3Mode != 0)
this.buttonSerialSend.Enabled = true;
else
this.buttonSerialSend.Enabled = false;
if (this.ParentForm.SystemConfig.EquipmentMode == 2 && this.ParentForm.SystemConfig.Serial3Mode == 1)
{
this.labelTitleTimeout.Visible = true;
this.labelABFoodTimeoutInterval.Visible = true;
}
else if (this.ParentForm.SystemConfig.EquipmentMode == 1 && this.ParentForm.SystemConfig.IsIndividualTransmission == true)
{
this.labelTitleTimeout.Text = "Interval";
this.labelTitleTimeout.Visible = true;
this.labelABFoodTimeoutInterval.Visible = true;
}
else
{
this.labelTitleTimeout.Visible = false;
this.labelABFoodTimeoutInterval.Visible = false;
}
if (this.ParentForm.SystemConfig.IsOptFeedbackBoardUse == true)
{
this.comboBoxSerial3BaudRate.Enabled = false;
this.comboBoxSerial3Mode.Enabled = false;
}
#endregion
}
private void EthernetStart()
{
string detail = "";
this.buttonStart.Enabled = true;
this.buttonStop.Enabled = true;
if (this.ParentForm.SystemConfig.EthernetOperationMode == 1)
{
detail = "Server";
if (string.Compare(this.ParentForm.smartConfigs.IPSettings.DeviceIP, "0.0.0.0") == 0)
{
if (this.labelServerStatus.Text != ">Addr Err")
this.labelServerStatus.Text = ">Addr Err";
this.timerServer.Enabled = false;
}
else
{
this.ParentForm.EthernetServerStart();
if (this.timerServer.Enabled == false)
this.timerServer.Enabled = true;
}
}
else if (this.ParentForm.SystemConfig.EthernetOperationMode == 2)
{
detail = "Client";
this.ParentForm.EthernetClientConnect();
}
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.TryEthernetStart, detail);
}
private void EthernetStop()
{
string detail = "";
if (this.ParentForm.SystemConfig.EthernetOperationMode == 1)
{
detail = "Server";
this.timerServer.Enabled = false;
this.ParentForm.EthernetServerStop();
if (this.labelServerStatus.Text != ">Stop")
this.labelServerStatus.Text = ">Stop";
}
else if (this.ParentForm.SystemConfig.EthernetOperationMode == 2)
{
detail = "Client";
this.ParentForm.EthernetClientDisconnect();
}
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingOperation.TryEthernetStop, detail);
}
private void EthernetDataTestSend()
{
string data = "";
if (this.ParentForm.SystemConfig.EthernetMode == 1)
data = this.ParentForm.Protocol_OPT2(this.ParentForm.SystemConfig, this.ParentForm.CollectionWeightData);
else if (this.ParentForm.SystemConfig.EthernetMode == 2)
data = this.ParentForm.Protocol_OPT3(this.ParentForm.SystemConfig, this.ParentForm.CollectionWeightData, this.ParentForm.CurrentProductItem);
else if (this.ParentForm.SystemConfig.EthernetMode == 4)
data = this.ParentForm.Protocol_OPT5(this.ParentForm.SystemConfig, this.ParentForm.CollectionWeightData, this.ParentForm.CurrentProductItem);
switch (this.ParentForm.SystemConfig.EthernetOperationMode)
{
case 1:
if (this.ParentForm.smartTCPMultiServer.ClientInfoList != null)
{
foreach (SmartTCPMultiServer.CLIENTSINFOS info in this.ParentForm.smartTCPMultiServer.ClientInfoList)
{
this.ParentForm.EthernetServerSendMessage(info, data);
}
}
break;
case 2:
this.ParentForm.EthernetSendMessage(data);
break;
default:
break;
}
}
private void EthernetDataTestSend(int lane)
{
string data = "";
if (this.ParentForm.SystemConfig.EthernetMode == 1)
data = this.ParentForm.Protocol_OPT2(this.ParentForm.SystemConfig, this.ParentForm.CollectionWeightData[lane - 1], lane);
else if (this.ParentForm.SystemConfig.EthernetMode == 2)
data = this.ParentForm.Protocol_OPT3(this.ParentForm.SystemConfig, this.ParentForm.CollectionWeightData[lane - 1], lane, this.ParentForm.CurrentProductItem);
else if (this.ParentForm.SystemConfig.EthernetMode == 4)
data = this.ParentForm.Protocol_OPT5(this.ParentForm.SystemConfig, this.ParentForm.CollectionWeightData[lane - 1], lane, this.ParentForm.CurrentProductItem);
switch (this.ParentForm.SystemConfig.EthernetOperationMode)
{
case 1:
if (this.ParentForm.smartTCPMultiServer.ClientInfoList != null)
{
foreach (SmartTCPMultiServer.CLIENTSINFOS info in this.ParentForm.smartTCPMultiServer.ClientInfoList)
{
this.ParentForm.EthernetServerSendMessage(info, data);
}
}
break;
case 2:
this.ParentForm.EthernetSendMessage(data);
break;
default:
break;
}
}
private void UpdateProtocolDescriptionCom3Display()
{
if (this.comboBoxSerial3Mode.SelectedIndex == 1)
{
#region OPT1
this.labelProtocolDescriptionCOM3_1.Text = "Private use";
this.labelProtocolDescriptionCOM3_2.Text = "";
#endregion
}
else if (this.comboBoxSerial3Mode.SelectedIndex == 2)
{
#region OPT2
if (this.ParentForm.SystemConfig.EquipmentMode == 1 || this.ParentForm.SystemConfig.EquipmentMode == 3
|| this.ParentForm.SystemConfig.EquipmentMode == 7)
{
if (this.ParentForm.SystemConfig.IsIndividualTransmission == false)
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],";
this.labelProtocolDescriptionCOM3_2.Text = "{GRD[1],WEIGHT[6]} * n,ETX[1]";
}
else
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],LANE[2],GRD[1],";
this.labelProtocolDescriptionCOM3_2.Text = "WEIGHT[6],ETX[1]";
}
}
else
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],LANE[2],GRD[1],";
this.labelProtocolDescriptionCOM3_2.Text = "WEIGHT[6],ETX[1]";
}
#endregion
}
else if (this.comboBoxSerial3Mode.SelectedIndex == 3)
{
#region OPT3
if (this.ParentForm.SystemConfig.EquipmentMode == 1 || this.ParentForm.SystemConfig.EquipmentMode == 3
|| this.ParentForm.SystemConfig.EquipmentMode == 7)
{
if (this.ParentForm.SystemConfig.IsIndividualTransmission == false)
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],PASS[6],";
this.labelProtocolDescriptionCOM3_2.Text = "{GRD[1],WEIGHT[6]} * n,ETX[1]";
}
else
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],PASS[6],LANE[2],";
this.labelProtocolDescriptionCOM3_2.Text = "GRD[1],WEIGHT[6],ETX[1]";
}
}
else
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],PASS[6],LANE[2],";
this.labelProtocolDescriptionCOM3_2.Text = "GRD[1],WEIGHT[6],ETX[1]";
}
#endregion
}
else if (this.comboBoxSerial3Mode.SelectedIndex == 4)
{
#region OPT4
if (this.ParentForm.SystemConfig.EquipmentMode == 1 || this.ParentForm.SystemConfig.EquipmentMode == 3
|| this.ParentForm.SystemConfig.EquipmentMode == 7)
{
if (this.ParentForm.SystemConfig.IsIndividualTransmission == false)
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],";
this.labelProtocolDescriptionCOM3_2.Text = "{SIGN[1],WEIGHT[6]} * n,ETX[1]";
}
else
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],LANE[2],";
this.labelProtocolDescriptionCOM3_2.Text = "SIGN[1],WEIGHT[6],ETX[1]";
}
}
else
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],LANE[2],";
this.labelProtocolDescriptionCOM3_2.Text = "SIGN[1],WEIGHT[6],ETX[1]";
}
#endregion
}
else if (this.comboBoxSerial3Mode.SelectedIndex == 5)
{
#region Printer
this.labelProtocolDescriptionCOM3_1.Text = "NO[4], LANE[2], GRADE[1], WEIGHT[6],";
this.labelProtocolDescriptionCOM3_2.Text = "COUNT[9]";
#endregion
}
else if (this.comboBoxSerial3Mode.SelectedIndex == 6)
{
#region OPT5
if (this.ParentForm.SystemConfig.EquipmentMode == 1 || this.ParentForm.SystemConfig.EquipmentMode == 3
|| this.ParentForm.SystemConfig.EquipmentMode == 7)
{
if (this.ParentForm.SystemConfig.IsIndividualTransmission == false)
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],UNDER[6],PASS[6],OVER[6],";
this.labelProtocolDescriptionCOM3_2.Text = "TARE[6],{GRD[1],WEIGHT[6]} * n,ETX[1]";
}
else
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],UNDER[6],PASS[6],OVER[6],";
this.labelProtocolDescriptionCOM3_2.Text = "TARE[6],LANE[2],GRD[1],WEIGHT[6],ETX[1]";
}
}
else
{
this.labelProtocolDescriptionCOM3_1.Text = "STX[1],ID[5],NO[4],UNDER[6],PASS[6],OVER[6],";
this.labelProtocolDescriptionCOM3_2.Text = "TARE[6],LANE[2],GRD[1],WEIGHT[6],ETX[1]";
}
#endregion
}
else
{
#region None
this.labelProtocolDescriptionCOM3_1.Text = "COM3 Protocol Description";
this.labelProtocolDescriptionCOM3_2.Text = "COM3 Protocol Description";
#endregion
}
}
private void LocalIPEnable(bool enable)
{
Color tempColor;
if (enable == true)
tempColor = Color.Black;
else
tempColor = Color.Gray;
#region Color
this.labelLocalIP1.ForeColor = tempColor;
this.labelLocalIP2.ForeColor = tempColor;
this.labelLocalIP3.ForeColor = tempColor;
this.labelLocalIP4.ForeColor = tempColor;
this.labelLocalSubnetMask1.ForeColor = tempColor;
this.labelLocalSubnetMask2.ForeColor = tempColor;
this.labelLocalSubnetMask3.ForeColor = tempColor;
this.labelLocalSubnetMask4.ForeColor = tempColor;
this.labelLocalGateway1.ForeColor = tempColor;
this.labelLocalGateway2.ForeColor = tempColor;
this.labelLocalGateway3.ForeColor = tempColor;
this.labelLocalGateway4.ForeColor = tempColor;
#endregion
#region Enable
this.labelLocalIP1.Enabled = enable;
this.labelLocalIP2.Enabled = enable;
this.labelLocalIP3.Enabled = enable;
this.labelLocalIP4.Enabled = enable;
this.labelLocalSubnetMask1.Enabled = enable;
this.labelLocalSubnetMask2.Enabled = enable;
this.labelLocalSubnetMask3.Enabled = enable;
this.labelLocalSubnetMask4.Enabled = enable;
this.labelLocalGateway1.Enabled = enable;
this.labelLocalGateway2.Enabled = enable;
this.labelLocalGateway3.Enabled = enable;
this.labelLocalGateway4.Enabled = enable;
#endregion
}
private void UpdateLocalIPAddressDisplay()
{
string[] sValue;
// Local IP
sValue = this.ParentForm.smartConfigs.IPSettings.DeviceIP.Split('.');
if (sValue.Length == 4)
{
this.labelLocalIP1.Text = sValue[0];
this.labelLocalIP2.Text = sValue[1];
this.labelLocalIP3.Text = sValue[2];
this.labelLocalIP4.Text = sValue[3];
}
// Local Subnet Mask
sValue = this.ParentForm.smartConfigs.IPSettings.SubNetMask.Split('.');
if (sValue.Length == 4)
{
this.labelLocalSubnetMask1.Text = sValue[0];
this.labelLocalSubnetMask2.Text = sValue[1];
this.labelLocalSubnetMask3.Text = sValue[2];
this.labelLocalSubnetMask4.Text = sValue[3];
}
// Local GateWay
sValue = this.ParentForm.smartConfigs.IPSettings.GateWay.Split('.');
if (sValue.Length == 4)
{
this.labelLocalGateway1.Text = sValue[0];
this.labelLocalGateway2.Text = sValue[1];
this.labelLocalGateway3.Text = sValue[2];
this.labelLocalGateway4.Text = sValue[3];
}
}
private void UpdateLocalIPConfigurationDisplay()
{
this.radioButtonLocalIpDHCP.Click -= new EventHandler(this.radioButtonLocalIpDHCP_Click);
// Local IP DHCP
if (this.ParentForm.smartConfigs.IPSettings.DHCPEnable == 1)
{
this.radioButtonLocalIpDHCP.Checked = true;
this.LocalIPEnable(false);
}
else
{
this.radioButtonLocalIpStatic.Checked = true;
this.LocalIPEnable(true);
}
this.radioButtonLocalIpDHCP.Click += new EventHandler(this.radioButtonLocalIpDHCP_Click);
}
private void UpdateDisplaySettingData(int index)
{
switch (index)
{
case 3 : // Modbus
this.labelTitleStartAddress.Visible = true;
this.labelStartAddress.Visible = true;
this.labelStartAddress.Text = this.ParentForm.SystemConfig.ModbusTcpStartAddress.ToString();
break;
default:
this.labelTitleStartAddress.Visible = false;
this.labelStartAddress.Visible = false;
break;
}
}
private void UpdateDisplayFormat(int index)
{
if (index == 1)
{
#region OPT2
this.labelProtocolDescriptionEthernet_1.Text = "STX[1],ID[5],NO[4],";
this.labelProtocolDescriptionEthernet_2.Text = "{GRD[1],WEIGHT[6]} * n,ETX[1]";
#endregion
}
else if (index == 2)
{
#region OPT3
this.labelProtocolDescriptionEthernet_1.Text = "STX[1],ID[5],NO[4],PASS[6],";
this.labelProtocolDescriptionEthernet_2.Text = "{GRD[1],WEIGHT[6]} * n,ETX[1]";
#endregion
}
else if (index == 4)
{
#region OPT5
this.labelProtocolDescriptionEthernet_1.Text = "STX[1],ID[5],NO[4],UNDER[6],PASS[6],OVER[6],";
this.labelProtocolDescriptionEthernet_2.Text = "TARE[6],{GRD[1],WEIGHT[6]} * n,ETX[1]";
#endregion
}
else
{
this.labelProtocolDescriptionEthernet_1.Text = "";
this.labelProtocolDescriptionEthernet_2.Text = "";
}
}
public void DisplayLabelLocalPort(bool bValue)
{
if (bValue == false)
{
this.labelLocalPort.Enabled = false;
this.labelLocalPort.BackColor = Color.Silver;
}
else
{
this.labelLocalPort.Enabled = true;
this.labelLocalPort.BackColor = Color.White;
}
}
public void UpdateEthernetStatusDisplay(string value)
{
if (this.labelClientStatus.Text != value)
this.labelClientStatus.Text = value;
}
public void DisplayRefresh()
{
string value = "";
this.ParentForm.SystemConfig.CurrentForm = DataStore.FormStore.FormCommunication;
#region TCP
// Local IP DHCP
this.UpdateLocalIPConfigurationDisplay();
// Local IP
this.UpdateLocalIPAddressDisplay();
// Format
this.UpdateDisplayFormat(this.ParentForm.SystemConfig.EthernetMode);
// Setting Data visible
this.UpdateDisplaySettingData(this.ParentForm.SystemConfig.EthernetMode);
this.comboBoxMode.SelectedIndexChanged -= new EventHandler(this.comboBoxMode_SelectedIndexChanged);
this.comboBoxOperationMode.SelectedIndexChanged -= new EventHandler(this.comboBoxOperationMode_SelectedIndexChanged);
this.comboBoxMode.SelectedIndex = this.ParentForm.SystemConfig.EthernetMode;
this.comboBoxOperationMode.SelectedIndex = this.ParentForm.SystemConfig.EthernetOperationMode;
this.comboBoxMode.SelectedIndexChanged += new EventHandler(this.comboBoxMode_SelectedIndexChanged);
this.comboBoxOperationMode.SelectedIndexChanged += new EventHandler(this.comboBoxOperationMode_SelectedIndexChanged);
this.labelHostPort.Text = this.ParentForm.SystemConfig.EthernetServerPort.ToString();
this.labelLocalPort.Text = this.ParentForm.SystemConfig.EthernetLocalPort.ToString();
// Modbus
if (this.comboBoxMode.SelectedIndex == 3)
{
this.buttonDataSend.Visible = true;
this.button1LaneSend.Visible = true;
this.button10LaneSend.Visible = true;
}
else
{
this.buttonDataSend.Visible = false;
this.button1LaneSend.Visible = false;
this.button10LaneSend.Visible = false;
}
if (this.comboBoxOperationMode.SelectedIndex == 1)
{
this.buttonStart.Enabled = true;
this.buttonStop.Enabled = true;
if (string.Compare(this.ParentForm.smartConfigs.IPSettings.DeviceIP, "0.0.0.0") == 0)
{
if (this.labelServerStatus.Text != ">Addr Err")
this.labelServerStatus.Text = ">Addr Err";
this.timerServer.Enabled = false;
}
else
{
this.ParentForm.EthernetServerStart();
if (this.timerServer.Enabled != true)
this.timerServer.Enabled = true;
}
}
else if (this.comboBoxOperationMode.SelectedIndex == 2)
{
this.buttonStart.Enabled = true;
this.buttonStop.Enabled = true;
this.ParentForm.EthernetClientConnect();
}
else
{
this.buttonStart.Enabled = false;
this.buttonStop.Enabled = false;
this.labelServerStatus.Text = "-";
this.labelClientStatus.Text = "-";
this.labelConnectedIP.Text = "-";
}
this.buttonTcpSave1.Enabled = false;
this.buttonTcpSave2.Enabled = false;
#endregion
#region Serial
this.comboBoxSerial3BaudRate.SelectedIndexChanged -= new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3BaudRate.SelectedIndex = this.ParentForm.SystemConfig.Serial3BaudRate;
this.comboBoxSerial3BaudRate.SelectedIndexChanged += new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3Mode.SelectedIndexChanged -= new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.comboBoxSerial3Mode.SelectedIndex = this.ParentForm.SystemConfig.Serial3Mode;
this.comboBoxSerial3Mode.SelectedIndexChanged += new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
if (this.ParentForm.SystemConfig.Serial3Mode != 0)
this.buttonSerialSend.Enabled = true;
else
this.buttonSerialSend.Enabled = false;
value = this.ParentForm.SystemConfig.ABFoodTimeoutInterval.ToString();
if (this.labelABFoodTimeoutInterval.Text != value)
this.labelABFoodTimeoutInterval.Text = value;
this.buttonSerialSave.Enabled = false;
this.UpdateProtocolDescriptionCom3Display();
#endregion
}
#endregion
#region Event Handler
private void buttonBack_Click(object sender, EventArgs e)
{
//this.EthernetStop();
this.ParentForm.ChildFormMenu.DisplayRefresh();
((FormMain)(Owner)).smartForm.Show((int)DataStore.FormStore.FormMenu);
}
private void buttonStart_Click(object sender, EventArgs e)
{
this.EthernetStart();
}
private void buttonStop_Click(object sender, EventArgs e)
{
this.EthernetStop();
}
private void buttonSend_Click(object sender, EventArgs e)
{
if (this.ParentForm.SystemConfig.EthernetMode != 3)
{
if (this.ParentForm.SystemConfig.EquipmentMode == 2)
this.EthernetDataTestSend(1);
else
this.EthernetDataTestSend();
}
else
{
this.ParentForm.ModbusCommonDataSend();
}
}
private void timerServer_Tick(object sender, EventArgs e)
{
if (this.ParentForm.smartTCPMultiServer.IsStart == true)
{
if (this.labelServerStatus.Text != ">Start")
this.labelServerStatus.Text = ">Start";
this.smartListBoxClientList.ClearAll();
this.labelClientCount.Text = "-";
this.labelConnectedIP.Text = "-";
if (this.ParentForm.smartTCPMultiServer.ClientInfoList != null)
{
for (int i = 0; i < this.ParentForm.smartTCPMultiServer.ClientInfoList.Length; i++)
{
this.smartListBoxClientList.AddItem(
this.ParentForm.smartTCPMultiServer.ClientInfoList[i].strID + ", " +
this.ParentForm.smartTCPMultiServer.ClientInfoList[i].strIPAddress);
}
this.labelClientCount.Text = this.ParentForm.smartTCPMultiServer.ClientInfoList.Length.ToString();
this.labelConnectedIP.Text = this.ParentForm.smartTCPMultiServer.ClientInfoList[0].strIPAddress;
}
}
else
{
if (this.labelServerStatus.Text != ">Stop")
this.labelServerStatus.Text = ">Stop";
this.smartListBoxClientList.ClearAll();
this.labelClientCount.Text = "-";
}
}
private void comboBoxOperationMode_SelectedIndexChanged(object sender, EventArgs e)
{
string before = "", after = "";
if (this.ParentForm.SystemConfig.EthernetOperationMode == 1)
before = "Server";
else if (this.ParentForm.SystemConfig.EthernetOperationMode == 2)
before = "Client";
else
before = "None";
if (this.comboBoxOperationMode.SelectedIndex == 1)
{
#region Server
this.ParentForm.EthernetClientDisconnect();
this.buttonStart.Enabled = true;
this.buttonStop.Enabled = true;
#endregion
}
else if (this.comboBoxOperationMode.SelectedIndex == 2)
{
#region Client
this.labelServerStatus.Text = "-";
this.timerServer.Enabled = false;
this.ParentForm.EthernetServerStop();
this.ParentForm.EthernetClientDisconnect();
this.buttonStart.Enabled = true;
this.buttonStop.Enabled = true;
#endregion
}
else
{
#region None
this.timerServer.Enabled = false;
this.ParentForm.EthernetServerStop();
this.ParentForm.EthernetClientDisconnect();
this.buttonStart.Enabled = false;
this.buttonStop.Enabled = false;
this.labelServerStatus.Text = "-";
this.labelClientStatus.Text = "-";
this.labelConnectedIP.Text = "-";
#endregion
}
this.ParentForm.SystemConfig.EthernetOperationMode = this.comboBoxOperationMode.SelectedIndex;
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
after = this.comboBoxOperationMode.SelectedItem.ToString();
// Part11
if (this.ParentForm.SystemConfig.IsPart11 == true)
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPOpMode, "", before, after);
}
private void comboBoxMode_SelectedIndexChanged(object sender, EventArgs e)
{
string before = "", after = "";
if (this.ParentForm.SystemConfig.EthernetMode == 1)
before = "OPT2";
else if (this.ParentForm.SystemConfig.EthernetMode == 2)
before = "OPT3";
else if (this.ParentForm.SystemConfig.EthernetMode == 3)
before = "Modbus";
else if (this.ParentForm.SystemConfig.EthernetMode == 4)
before = "OPT5";
else
before = "None";
if (this.comboBoxMode.SelectedIndex == 3) // Modbus 사용 시
{
this.buttonDataSend.Visible = true;
this.button1LaneSend.Visible = true;
this.button10LaneSend.Visible = true;
}
else
{
this.buttonDataSend.Visible = false;
this.button1LaneSend.Visible = false;
this.button10LaneSend.Visible = false;
}
this.ParentForm.SystemConfig.EthernetMode = this.comboBoxMode.SelectedIndex;
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
this.UpdateDisplaySettingData(this.ParentForm.SystemConfig.EthernetMode);
this.UpdateDisplayFormat(this.ParentForm.SystemConfig.EthernetMode);
after = this.comboBoxMode.SelectedItem.ToString();
// Part11
if (this.ParentForm.SystemConfig.IsPart11 == true)
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPComMode, "", before, after);
}
private void labelStartAddress_Click(object sender, EventArgs e)
{
string before = "", after = "";
before = this.labelStartAddress.Text;
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelStartAddress.Text, 5, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 65535)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.labelStartAddress.Text = myKeyPad.StringValue;
this.ParentForm.SystemConfig.ModbusTcpStartAddress = myKeyPad.IntValue;
after = this.labelStartAddress.Text;
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
// Part11
if (this.ParentForm.SystemConfig.IsPart11 == true)
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.Mod_StartAddr, "", before, after);
}
}
}
private void radioButtonLocalIpDHCP_Click(object sender, EventArgs e)
{
string before = "", after = "";
if (this.ParentForm.smartConfigs.IPSettings.DHCPEnable == 0)
before = "Static";
else
before = "DHCP";
DialogFormYesNo myDlg;
if (this.radioButtonLocalIpStatic.Checked == true)
myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 15); // 로컬IP주소 수동으로 설정하시겠습니까?
else
myDlg = new DialogFormYesNo(this.ParentForm.SystemConfig.Language, 16); // 로컬IP주소 자동으로 설정하시겠습니까?
if (myDlg.ShowDialog() == DialogResult.Yes)
{
if (this.radioButtonLocalIpDHCP.Checked == true)
{
this.ParentForm.smartConfigs.IPSettings.DHCPEnable = 1;
this.LocalIPEnable(false);
this.UpdateLocalIPAddressDisplay();
after = "DHCP";
}
else
{
this.ParentForm.smartConfigs.IPSettings.DHCPEnable = 0;
this.LocalIPEnable(true);
after = "Static";
try
{
this.UpdateLocalIPAddressDisplay();
}
catch
{
this.ParentForm.smartConfigs.IPSettings.DeviceIP = "192.168.3.10";
this.ParentForm.smartConfigs.IPSettings.SubNetMask = "255.255.255.0";
this.ParentForm.smartConfigs.IPSettings.GateWay = "192.168.3.1";
this.UpdateLocalIPAddressDisplay();
}
}
this.ParentForm.smartConfigs.IPSettings.Save();
this.ParentForm.smartConfigs.IPSettings.SetApply();
// Part 11
if (this.ParentForm.SystemConfig.IsPart11 == true)
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPLocalIPConfig, "", before, after);
DialogFormMessage msg = new DialogFormMessage(18, this.ParentForm.SystemConfig.Language);
msg.ShowDialog();
}
else
{
this.DisplayRefresh();
}
}
private void labelLocalIP1_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalIP1.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalIP1.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalIP2_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalIP2.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalIP2.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalIP3_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalIP3.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalIP3.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalIP4_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalIP4.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalIP4.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalSubnetMask1_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalSubnetMask1.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalSubnetMask1.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalSubnetMask2_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalSubnetMask2.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalSubnetMask2.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalSubnetMask3_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalSubnetMask3.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalSubnetMask3.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalSubnetMask4_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalSubnetMask4.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalSubnetMask4.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalGateway1_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalGateway1.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalGateway1.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalGateway2_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalGateway2.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalGateway2.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalGateway3_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalGateway3.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalGateway3.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void labelLocalGateway4_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalGateway4.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelLocalGateway4.Text = myKeyPad.StringValue;
this.buttonTcpSave1.Enabled = true;
}
}
}
private void buttonTcpSave1_Click(object sender, EventArgs e)
{
string deviceIP = "", subNetMask = "", gateWay = "";
string beforeIP = "", beforeSub = "", beforeGate = "", afterIP = "", afterSub = "", afterGate = "";
beforeIP = this.ParentForm.smartConfigs.IPSettings.DeviceIP;
beforeSub = this.ParentForm.smartConfigs.IPSettings.SubNetMask;
beforeGate = this.ParentForm.smartConfigs.IPSettings.GateWay;
this.buttonTcpSave1.Enabled = false;
if (this.ParentForm.SystemConfig.EthernetOperationMode == 1)
this.ParentForm.EthernetServerStop();
else if (this.ParentForm.SystemConfig.EthernetOperationMode == 2)
this.ParentForm.EthernetClientDisconnect();
deviceIP = string.Format("{0}.{1}.{2}.{3}",
this.labelLocalIP1.Text, this.labelLocalIP2.Text, this.labelLocalIP3.Text, this.labelLocalIP4.Text);
subNetMask = string.Format("{0}.{1}.{2}.{3}",
this.labelLocalSubnetMask1.Text, this.labelLocalSubnetMask2.Text, this.labelLocalSubnetMask3.Text, this.labelLocalSubnetMask4.Text);
gateWay = string.Format("{0}.{1}.{2}.{3}",
this.labelLocalGateway1.Text, this.labelLocalGateway2.Text, this.labelLocalGateway3.Text, this.labelLocalGateway4.Text);
this.ParentForm.smartConfigs.IPSettings.DeviceIP = deviceIP;
this.ParentForm.smartConfigs.IPSettings.SubNetMask = subNetMask;
this.ParentForm.smartConfigs.IPSettings.GateWay = gateWay;
this.ParentForm.smartConfigs.IPSettings.Save();
this.ParentForm.smartConfigs.IPSettings.SetApply();
if (this.ParentForm.SystemConfig.EthernetOperationMode == 1)
this.ParentForm.EthernetServerStart();
else if (this.ParentForm.SystemConfig.EthernetOperationMode == 2)
this.ParentForm.EthernetClientConnect();
afterIP = this.ParentForm.smartConfigs.IPSettings.DeviceIP;
afterSub = this.ParentForm.smartConfigs.IPSettings.SubNetMask;
afterGate = this.ParentForm.smartConfigs.IPSettings.GateWay;
// Part 11
if (this.ParentForm.SystemConfig.IsPart11 == true)
{
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPLocalIPAddress, "", beforeIP, afterIP);
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPLocalSubnetMask, "", beforeSub, afterSub);
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPLocalGateway, "", beforeGate, afterGate);
}
}
private void labelLocalPort_Click(object sender, EventArgs e)
{
string before = "", after = "";
before = this.labelLocalPort.Text;
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelLocalPort.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
this.labelLocalPort.Text = myKeyPad.StringValue;
this.ParentForm.EthernetServerStop();
this.ParentForm.smartTCPMultiServer.Port = myKeyPad.IntValue;
this.ParentForm.SystemConfig.EthernetLocalPort = myKeyPad.IntValue;
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
after = this.labelLocalPort.Text;
// Part 11
if (this.ParentForm.SystemConfig.IsPart11 == true)
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPLocalPort, "", before, after);
}
}
private void labelHostIP1_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelHostIP1.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelHostIP1.Text = myKeyPad.StringValue;
this.buttonTcpSave2.Enabled = true;
}
}
}
private void labelHostIP2_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelHostIP2.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelHostIP2.Text = myKeyPad.StringValue;
this.buttonTcpSave2.Enabled = true;
}
}
}
private void labelHostIP3_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelHostIP3.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelHostIP3.Text = myKeyPad.StringValue;
this.buttonTcpSave2.Enabled = true;
}
}
}
private void labelHostIP4_Click(object sender, EventArgs e)
{
string temp = "";
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelHostIP4.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.IntValue > 255)
{
temp = "0 ~ 255";
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language, temp);
myMsg.ShowDialog();
}
else
{
this.labelHostIP4.Text = myKeyPad.StringValue;
this.buttonTcpSave2.Enabled = true;
}
}
}
private void labelHostPort_Click(object sender, EventArgs e)
{
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelHostPort.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
this.labelHostPort.Text = myKeyPad.StringValue;
this.buttonTcpSave2.Enabled = true;
}
}
private void buttonTcpSave2_Click(object sender, EventArgs e)
{
string beforeIP = "", beforePort = "", afterIP = "", afterPort = "";
beforeIP = this.ParentForm.SystemConfig.EthernetServerAddress;
beforePort = this.ParentForm.SystemConfig.EthernetServerPort.ToString();
this.ParentForm.SystemConfig.EthernetServerPort = int.Parse(this.labelHostPort.Text);
this.ParentForm.SystemConfig.EthernetServerAddress = string.Format("{0}.{1}.{2}.{3}",
this.labelHostIP1.Text, this.labelHostIP2.Text, this.labelHostIP3.Text, this.labelHostIP4.Text);
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
this.ParentForm.EthernetClientDisconnect();
this.buttonTcpSave2.Enabled = false;
afterIP = this.ParentForm.SystemConfig.EthernetServerAddress;
afterPort = this.ParentForm.SystemConfig.EthernetServerPort.ToString();
// Part11
if (this.ParentForm.SystemConfig.IsPart11 == true)
{
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPServerIPAddress, "", beforeIP, afterIP);
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.TCPServerPort, "", beforePort, afterPort);
}
}
private void labelSlaveID_Click(object sender, EventArgs e)
{
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelSlaveID.Text, 3, 0, false, this.ParentForm.SystemConfig.Language);
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue < 0 || myKeyPad.doubleValue > 255)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.labelSlaveID.Text = myKeyPad.StringValue;
this.ParentForm.SystemConfig.ModbusRtuSlaveID = myKeyPad.IntValue;
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
}
}
}
private void buttonSerialSend_Click(object sender, EventArgs e)
{
if (this.ParentForm.SystemConfig.Serial3Mode == 1)
{
#region OPT1
if (this.ParentForm.SystemConfig.EquipmentMode == 1)
this.ParentForm.UartCom3WeightDataTransfer(this.ParentForm.CollectionWeightData);
#endregion
}
else if (this.ParentForm.SystemConfig.Serial3Mode == 2)
{
#region OPT2
if (this.ParentForm.SystemConfig.EquipmentMode == 1 || this.ParentForm.SystemConfig.EquipmentMode == 3
|| this.ParentForm.SystemConfig.EquipmentMode == 7)
{
if (this.ParentForm.SystemConfig.IsIndividualTransmission == false)
this.ParentForm.SerialCH3OPT2(this.ParentForm.CollectionWeightData);
else
{
for (int i = 0; i < this.ParentForm.SystemConfig.EquipmentColumns; i++)
this.ParentForm.SerialCH3OPT2(i + 1, this.ParentForm.CollectionWeightData[i]);
}
}
else if (this.ParentForm.SystemConfig.EquipmentMode == 2)
{
if (this.ParentForm.SystemConfig.IsIntegratedTransmission == false)
this.ParentForm.SerialCH3OPT2(1, this.ParentForm.CollectionWeightData[0]);
else
this.ParentForm.SerialCH3OPT2(this.ParentForm.CollectionWeightData);
}
#endregion
}
else if (this.ParentForm.SystemConfig.Serial3Mode == 3)
{
#region OPT3
if (this.ParentForm.SystemConfig.EquipmentMode == 1 || this.ParentForm.SystemConfig.EquipmentMode == 3
|| this.ParentForm.SystemConfig.EquipmentMode == 7)
{
if (this.ParentForm.SystemConfig.IsIndividualTransmission == false)
this.ParentForm.SerialCH3OPT3(this.ParentForm.CollectionWeightData);
else
{
for (int i = 0; i < this.ParentForm.SystemConfig.EquipmentColumns; i++)
this.ParentForm.SerialCH3OPT3(i + 1, this.ParentForm.CollectionWeightData[i]);
}
}
else if (this.ParentForm.SystemConfig.EquipmentMode == 2)
{
if (this.ParentForm.SystemConfig.IsIntegratedTransmission == false)
this.ParentForm.SerialCH3OPT3(1, this.ParentForm.CollectionWeightData[0]);
else
this.ParentForm.SerialCH3OPT3(this.ParentForm.CollectionWeightData);
}
#endregion
}
else if (this.ParentForm.SystemConfig.Serial3Mode == 4)
{
#region OPT4
this.ParentForm.SerialCH3OPT4Test(1, this.ParentForm.CollectionWeightData[0]);
#endregion
}
else if (this.ParentForm.SystemConfig.Serial3Mode == 5)
{
#region Printer
if (this.ParentForm.SystemConfig.EquipmentMode == 1 || this.ParentForm.SystemConfig.EquipmentMode == 3
|| this.ParentForm.SystemConfig.EquipmentMode == 7)
{
for (int i = 0; i < this.ParentForm.SystemConfig.EquipmentColumns; i++)
this.ParentForm.SerialCH3Printer(i + 1, this.ParentForm.CollectionWeightData[i]);
}
else if (this.ParentForm.SystemConfig.EquipmentMode == 2)
this.ParentForm.SerialCH3Printer(1, this.ParentForm.CollectionWeightData[0]);
#endregion
}
else if (this.ParentForm.SystemConfig.Serial3Mode == 6)
{
if (this.ParentForm.SystemConfig.EquipmentMode == 1 || this.ParentForm.SystemConfig.EquipmentMode == 3
|| this.ParentForm.SystemConfig.EquipmentMode == 7)
{
if (this.ParentForm.SystemConfig.IsIndividualTransmission == false)
this.ParentForm.SerialCH3OPT5(this.ParentForm.CollectionWeightData);
else
{
for (int i = 0; i < this.ParentForm.SystemConfig.EquipmentColumns; i++)
this.ParentForm.SerialCH3OPT5(i + 1, this.ParentForm.CollectionWeightData[i]);
}
}
else if (this.ParentForm.SystemConfig.EquipmentMode == 2)
{
if (this.ParentForm.SystemConfig.IsIntegratedTransmission == false)
this.ParentForm.SerialCH3OPT5(1, this.ParentForm.CollectionWeightData[0]);
else
this.ParentForm.SerialCH3OPT5(this.ParentForm.CollectionWeightData);
}
}
}
private void buttonSerialSave_Click(object sender, EventArgs e)
{
string beforeBr = "", beforeMode = "", afterBr = "", afterMode = "";
// before BaudRate
if (this.ParentForm.SystemConfig.Serial3BaudRate == 0)
beforeBr = "9600";
else if (this.ParentForm.SystemConfig.Serial3BaudRate == 1)
beforeBr = "19200";
else if (this.ParentForm.SystemConfig.Serial3BaudRate == 2)
beforeBr = "38400";
else if (this.ParentForm.SystemConfig.Serial3BaudRate == 3)
beforeBr = "115200";
else
beforeBr = "9600";
// before Mode
if (this.ParentForm.SystemConfig.Serial3Mode == 0)
beforeMode = "None";
else if (this.ParentForm.SystemConfig.Serial3Mode == 1)
beforeMode = "OPT1";
else if (this.ParentForm.SystemConfig.Serial3Mode == 2)
beforeMode = "OPT2";
else if (this.ParentForm.SystemConfig.Serial3Mode == 3)
beforeMode = "OPT3";
else if (this.ParentForm.SystemConfig.Serial3Mode == 4)
beforeMode = "OPT4";
else if (this.ParentForm.SystemConfig.Serial3Mode == 5)
beforeMode = "Printer";
else if (this.ParentForm.SystemConfig.Serial3Mode == 6)
beforeMode = "OPT5";
this.ParentForm.SystemConfig.Serial3BaudRate = this.comboBoxSerial3BaudRate.SelectedIndex;
this.ParentForm.SystemConfig.Serial3Mode = this.comboBoxSerial3Mode.SelectedIndex;
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
if (this.ParentForm.smartSerialPortCom3.IsOpen == true)
this.ParentForm.smartSerialPortCom3.Close();
if (this.ParentForm.SystemConfig.Serial3Mode != 0)
{
this.buttonSerialSend.Enabled = true;
switch (this.ParentForm.SystemConfig.Serial3BaudRate)
{
case 0:
this.ParentForm.smartSerialPortCom3.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
afterBr = "9600";
break;
case 1:
this.ParentForm.smartSerialPortCom3.Baud_Rate = SmartSerialPort.BAUDRATE._19200bps;
afterBr = "19200";
break;
case 2:
this.ParentForm.smartSerialPortCom3.Baud_Rate = SmartSerialPort.BAUDRATE._38400bps;
afterBr = "38400";
break;
case 3:
this.ParentForm.smartSerialPortCom3.Baud_Rate = SmartSerialPort.BAUDRATE._115200bps;
afterBr = "115200";
break;
default:
this.ParentForm.smartSerialPortCom3.Baud_Rate = SmartSerialPort.BAUDRATE._9600bps;
afterBr = "9600";
break;
}
switch (this.ParentForm.SystemConfig.Serial3Mode)
{
case 0:
this.ParentForm.smartSerialPortCom3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;
afterMode = "None";
break;
case 1:
this.ParentForm.smartSerialPortCom3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;
afterMode = "OPT1";
break;
case 2:
this.ParentForm.smartSerialPortCom3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;
afterMode = "OPT2";
break;
case 3:
this.ParentForm.smartSerialPortCom3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;
afterMode = "OPT3";
break;
case 4:
this.ParentForm.smartSerialPortCom3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;
afterMode = "OPT4";
break;
case 5:
this.ParentForm.smartSerialPortCom3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.NONEFRAME_READTIMEOUT;
afterMode = "Printer";
break;
case 6:
this.ParentForm.smartSerialPortCom3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;
afterMode = "OPT5";
break;
default:
this.ParentForm.smartSerialPortCom3.FrameSeparationType = SmartSerialPort.FRAMESEPARATIONTYPES.STXANDETX;
break;
}
this.ParentForm.smartSerialPortCom3.Open();
}
else
this.buttonSerialSend.Enabled = false;
this.buttonSerialSave.Enabled = false;
if (this.ParentForm.SystemConfig.Serial3Mode == 1)
{
if (this.ParentForm.SystemConfig.EquipmentMode == 2)
{
this.labelTitleTimeout.Visible = true;
this.labelABFoodTimeoutInterval.Visible = true;
}
else
{
this.labelTitleTimeout.Visible = false;
this.labelABFoodTimeoutInterval.Visible = false;
}
this.ParentForm.timerOPT1.Enabled = true;
}
else
{
if (this.ParentForm.SystemConfig.EquipmentMode == 1 && this.ParentForm.SystemConfig.IsIndividualTransmission == true)
{
this.labelTitleTimeout.Text = "Interval";
this.labelTitleTimeout.Visible = true;
this.labelABFoodTimeoutInterval.Visible = true;
}
else
{
this.labelTitleTimeout.Visible = false;
this.labelABFoodTimeoutInterval.Visible = false;
}
this.ParentForm.timerOPT1.Enabled = false;
}
// Part 11
if (this.ParentForm.SystemConfig.IsPart11 == true)
{
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.Com3Baudrate, "", beforeBr, afterBr);
this.ParentForm.SetTrackingHistoryData(DataStore.TrackingParameter.Com3Mode, "", beforeMode, afterMode);
}
}
private void comboBoxSerial3_SelectedIndexChanged(object sender, EventArgs e)
{
this.UpdateProtocolDescriptionCom3Display();
this.comboBoxSerial3BaudRate.SelectedIndexChanged -= new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
if (this.comboBoxSerial3Mode.SelectedIndex == 5)
{
this.comboBoxSerial3BaudRate.SelectedIndex = 0;
this.comboBoxSerial3BaudRate.Enabled = false;
}
else
this.comboBoxSerial3BaudRate.Enabled = true;
this.comboBoxSerial3BaudRate.SelectedIndexChanged += new EventHandler(this.comboBoxSerial3_SelectedIndexChanged);
this.buttonSerialSave.Enabled = true;
}
private void labelABFoodTimeoutInterval_Click(object sender, EventArgs e)
{
int maxValue = 0;
DialogFormNumKeyPad myKeyPad = new DialogFormNumKeyPad(this.labelABFoodTimeoutInterval.Text, 4, 0, false, this.ParentForm.SystemConfig.Language);
if (this.ParentForm.SystemConfig.EquipmentMode == 1 && this.ParentForm.SystemConfig.IsIndividualTransmission == true)
maxValue = 100;
else
maxValue = 1000;
if (myKeyPad.ShowDialog() == DialogResult.OK)
{
if (myKeyPad.doubleValue < 1 || myKeyPad.doubleValue > maxValue)
{
// 입력범위를 확인하세요
DialogFormMessage myMsg = new DialogFormMessage(1, this.ParentForm.SystemConfig.Language);
myMsg.ShowDialog();
}
else
{
this.labelABFoodTimeoutInterval.Text = myKeyPad.StringValue;
this.ParentForm.SystemConfig.ABFoodTimeoutInterval = myKeyPad.IntValue;
this.ParentForm.timerTimeoutOPT1.Interval = this.ParentForm.SystemConfig.ABFoodTimeoutInterval;
this.ParentForm.SaveSystemConfigurationFile(this.ParentForm.SystemConfig);
}
}
}
private void buttonDataSend_Click(object sender, EventArgs e)
{
this.ParentForm.ModbusCommonDataSend();
}
private void button1LaneSend_Click(object sender, EventArgs e)
{
this.ParentForm.ModbusLaneTestDataSend(1);
}
private void button10LaneSend_Click(object sender, EventArgs e)
{
this.ParentForm.ModbusLaneTestDataSend(10);
}
#endregion
private void smartButton3_Click(object sender, EventArgs e)
{
this.DisplayRefresh();
}
}
}