171 lines
4.7 KiB
C#
171 lines
4.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Drawing;
|
|
using System.Data;
|
|
using System.Text;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
|
|
using System.Runtime.InteropServices;
|
|
using System.IO;
|
|
using System.IO.Ports;
|
|
|
|
using LFP_Manager.DataStructure;
|
|
using LFP_Manager.Function;
|
|
|
|
namespace LFP_Manager.Controls
|
|
{
|
|
public partial class ucCommConfig : DevExpress.XtraEditors.XtraUserControl
|
|
{
|
|
#region EVENT
|
|
|
|
public delegate void CloseEvent(object aConfig, bool saved);
|
|
|
|
#endregion
|
|
|
|
#region VARIABLES
|
|
|
|
CommConfig Config = new CommConfig();
|
|
public event CloseEvent OnClose = null;
|
|
|
|
DataTable dtComport = new DataTable();
|
|
private bool saved = false;
|
|
|
|
#endregion
|
|
|
|
#region CONSTRUCTORS
|
|
|
|
public ucCommConfig()
|
|
{
|
|
InitializeComponent();
|
|
|
|
CommPortLoad();
|
|
|
|
IniLoad();
|
|
}
|
|
|
|
private void InitComportDataTable()
|
|
{
|
|
dtComport = new DataTable();
|
|
dtComport.Columns.Add("name", typeof(string));
|
|
dtComport.Columns.Add("name2", typeof(string));
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DATA LOAD AND SAVE
|
|
|
|
private void CommPortLoad()
|
|
{
|
|
bool found = false;
|
|
int ComId = 0;
|
|
|
|
InitComportDataTable();
|
|
foreach (string comport in SerialPort.GetPortNames())
|
|
{
|
|
DataRow aRow = dtComport.NewRow();
|
|
aRow["name"] = comport;
|
|
dtComport.Rows.Add(aRow);
|
|
}
|
|
|
|
for (int i = 0; i < dtComport.Rows.Count; i++)
|
|
{
|
|
cbUartPort.Properties.Items.Add(dtComport.Rows[i]["name"].ToString());
|
|
}
|
|
|
|
if (Config.UartPort != "")
|
|
{
|
|
for (int i = 0; i < cbUartPort.Properties.Items.Count; i++)
|
|
{
|
|
if (dtComport.Rows[i]["name"].ToString() == Config.UartPort)
|
|
{
|
|
found = true;
|
|
ComId = i;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (found)
|
|
{
|
|
cbUartPort.SelectedIndex = ComId;
|
|
Config.UartPort = cbUartPort.Properties.Items[ComId].ToString();
|
|
}
|
|
else
|
|
{
|
|
if (cbUartPort.Properties.Items.Count > 0)
|
|
{
|
|
cbUartPort.SelectedIndex = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void IniLoad()
|
|
{
|
|
csIniControlFunction.IniLoad(Application.ExecutablePath, ref Config);
|
|
|
|
cbUartModel.Properties.Items.Clear();
|
|
foreach (string m_name in csConstData.UART_MODEL)
|
|
{
|
|
cbUartModel.Properties.Items.Add(m_name);
|
|
}
|
|
cbModuleQty.Properties.Items.Clear();
|
|
for (int i = 0; i < csConstData.SystemInfo.MAX_MODULE_SIZE; i++)
|
|
{
|
|
cbModuleQty.Properties.Items.Add(string.Format("{0}", i + 1));
|
|
}
|
|
cbUartProtocol.Properties.Items.Clear();
|
|
foreach (string m_name in csConstData.UART_PROTOCOL)
|
|
{
|
|
cbUartProtocol.Properties.Items.Add(m_name);
|
|
}
|
|
|
|
cbUartPort.Text = Config.UartPort;
|
|
cbUartModel.SelectedIndex = Config.UartModelIndex;
|
|
cbUartProtocol.SelectedIndex = Config.UartProtocol;
|
|
if (Config.ModuleQty <= 0) Config.ModuleQty = 1;
|
|
cbModuleQty.SelectedIndex = Config.ModuleQty - 1;
|
|
edRecvWaitTime.Text = string.Format("{0}", Config.RecvWaitTime);
|
|
|
|
cbDbLogPeriod.Text = Config.DbLogPeriod.ToString();
|
|
|
|
rbUart.Checked = true;
|
|
}
|
|
|
|
private void IniSave()
|
|
{
|
|
Config.CommType = csConstData.CommType.COMM_UART;
|
|
|
|
Config.UartPort = cbUartPort.Text;
|
|
Config.UartModelIndex = cbUartModel.SelectedIndex;
|
|
Config.ModuleQty = cbModuleQty.SelectedIndex + 1;
|
|
Config.UartProtocol = cbUartProtocol.SelectedIndex;
|
|
Config.RecvWaitTime = Convert.ToInt32(edRecvWaitTime.Text);
|
|
|
|
Config.DbLogPeriod = Convert.ToInt32(cbDbLogPeriod.Text);
|
|
|
|
csIniControlFunction.IniSave(Application.ExecutablePath, Config);
|
|
|
|
saved = true;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region COMPONENT EVENT
|
|
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
if (OnClose != null) OnClose(Config, saved);
|
|
}
|
|
|
|
private void btnSave_Click(object sender, EventArgs e)
|
|
{
|
|
IniSave();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|