|
@@ -1,7 +1,9 @@
|
|
|
using System;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Drawing;
|
|
|
-using System.IO.Ports;
|
|
|
+using System.IO;
|
|
|
+using System.Reflection;
|
|
|
using System.Runtime.InteropServices;
|
|
|
using System.Threading;
|
|
|
using System.Windows.Forms;
|
|
@@ -13,6 +15,13 @@ namespace Welling_Motor_Debug_Tool
|
|
|
#region 变量定义
|
|
|
//串口实例
|
|
|
Serial_Process mySerialProcess = new Serial_Process();
|
|
|
+ string PortNumSave = "";
|
|
|
+ string PortBaudrateSave = "";
|
|
|
+ //FTP实例
|
|
|
+ ftp myFtp = new ftp();
|
|
|
+ //本地存储数据路径
|
|
|
+ string LocalPath = "";
|
|
|
+ string ConfigFileName = "";
|
|
|
//MC运行信息超时计数
|
|
|
bool MC_RunInfo_Refresh = false;
|
|
|
ushort MC_RunInfo_Refresh_Cnt = 0;
|
|
@@ -87,11 +96,124 @@ namespace Welling_Motor_Debug_Tool
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
-
|
|
|
public Form1()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
+ //检查配置文件
|
|
|
+ ConfigFileName = Directory.GetCurrentDirectory() + "\\" + "Config.ttcfg";
|
|
|
+ if (File.Exists(ConfigFileName)) //存在配置文件,导入配置信息
|
|
|
+ {
|
|
|
+ //打开文件
|
|
|
+ StreamReader objReader = new StreamReader(ConfigFileName);
|
|
|
+ string sLine = "";
|
|
|
+ ArrayList array_CfgInfo = new ArrayList();
|
|
|
+ array_CfgInfo.Clear();
|
|
|
+ while (sLine != null)
|
|
|
+ {
|
|
|
+ sLine = objReader.ReadLine();
|
|
|
+ array_CfgInfo.Add(sLine);
|
|
|
+ }
|
|
|
+ objReader.Close();
|
|
|
+ //解析配置文件
|
|
|
+ try
|
|
|
+ {
|
|
|
+ PortNumSave = array_CfgInfo[1].ToString().Split(':')[1];
|
|
|
+ PortBaudrateSave = array_CfgInfo[2].ToString().Split(':')[1];
|
|
|
+ 连接开机ToolStripMenuItem.Checked = (array_CfgInfo[3].ToString().Split(':')[1] == "True");
|
|
|
+ 断开关机ToolStripMenuItem.Checked = (array_CfgInfo[4].ToString().Split(':')[1] == "True");
|
|
|
+ 识别通讯盒ToolStripMenuItem.Checked = (array_CfgInfo[5].ToString().Split(':')[1] == "True");
|
|
|
+ 写入存储ToolStripMenuItem.Checked = (array_CfgInfo[8].ToString().Split(':')[1] == "True");
|
|
|
+ 允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "True");
|
|
|
+ 不允许ToolStripMenuItem.Checked = (array_CfgInfo[9].ToString().Split(':')[1] == "False");
|
|
|
+ toolStripTextBox_ServerIP.Text = array_CfgInfo[12].ToString().Split(':')[1];
|
|
|
+ toolStripTextBox_ServerPort.Text = array_CfgInfo[13].ToString().Split(':')[1];
|
|
|
+ toolStripTextBox_ServerUser.Text = array_CfgInfo[14].ToString().Split(':')[1];
|
|
|
+ toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
|
|
|
+ toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
|
|
|
+ }
|
|
|
+ catch (System.Exception)
|
|
|
+ {
|
|
|
+ timer_1s.Enabled = false;
|
|
|
+ MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ timer_1s.Enabled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else //不存在配置文件,生成文件写入默认值
|
|
|
+ {
|
|
|
+ ConfigFileSave(false, ConfigFileName);
|
|
|
+ }
|
|
|
+ //配置网络FTP服务器
|
|
|
+ myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text);
|
|
|
+ //配置本地数据存储路径
|
|
|
+ LocalPath = Directory.GetCurrentDirectory() + "\\" + toolStripTextBox_ServerPath.Text;
|
|
|
+ //检查本地文件夹
|
|
|
+ if (!Directory.Exists(LocalPath))
|
|
|
+ Directory.CreateDirectory(LocalPath);
|
|
|
+ //创建线程,定时检测网络连接状态
|
|
|
+ Thread th = new Thread(NetworkCheck);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start();
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 检查网络状态线程
|
|
|
+ /// </summary>
|
|
|
+ private void NetworkCheck()
|
|
|
+ {
|
|
|
+ //初始化第一次连接FTP服务器
|
|
|
+ bool Result = myFtp.CheckFtp();
|
|
|
+ this.Invoke((EventHandler)(delegate
|
|
|
+ {
|
|
|
+ if (Result == true)//服务器连接成功
|
|
|
+ {
|
|
|
+ label_Server_ComStatus.Text = "网络已连接";
|
|
|
+ label_ServerStatus.BackColor = Color.Green;
|
|
|
+ myFtp.IsNetConnected = true;
|
|
|
+ }
|
|
|
+ else//服务器连接失败
|
|
|
+ {
|
|
|
+ label_Server_ComStatus.Text = "网络断开";
|
|
|
+ label_ServerStatus.BackColor = Color.Red;
|
|
|
+ myFtp.IsNetConnected = false;
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ //创建定时器,定时10s检查网络
|
|
|
+ System.Timers.Timer timer_CheckNet = new System.Timers.Timer();
|
|
|
+ timer_CheckNet.Enabled = true;
|
|
|
+ timer_CheckNet.Interval = 10000;
|
|
|
+ timer_CheckNet.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_CheckNet_Tick);
|
|
|
+ timer_CheckNet.Start();
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ Thread.Sleep(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 线程中定时任务,检查网络状态
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void timer_CheckNet_Tick(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ //连接FTP服务器
|
|
|
+ bool Result = myFtp.CheckFtp();
|
|
|
+ this.Invoke((EventHandler)(delegate
|
|
|
+ {
|
|
|
+ if (Result == true)//服务器连接成功
|
|
|
+ {
|
|
|
+ label_Server_ComStatus.Text = "网络已连接";
|
|
|
+ label_ServerStatus.BackColor = Color.Green;
|
|
|
+ myFtp.IsNetConnected = true;
|
|
|
+ }
|
|
|
+ else//服务器连接失败
|
|
|
+ {
|
|
|
+ label_Server_ComStatus.Text = "网络断开";
|
|
|
+ label_ServerStatus.BackColor = Color.Red;
|
|
|
+ myFtp.IsNetConnected = false;
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
#region 非独占性延时函数
|
|
@@ -109,6 +231,7 @@ namespace Welling_Motor_Debug_Tool
|
|
|
{
|
|
|
//页面初始化
|
|
|
label_BuildTime.Text= "编译时间:"+ System.IO.File.GetLastWriteTime(this.GetType().Assembly.Location).ToString();
|
|
|
+
|
|
|
//下拉控件初始值设定
|
|
|
comboBox_WorkMode.SelectedIndex = 0;
|
|
|
comboBox_GearSt.SelectedIndex = 0;
|
|
@@ -117,6 +240,7 @@ namespace Welling_Motor_Debug_Tool
|
|
|
comboBox_OBC_LightSw.SelectedIndex = 1;
|
|
|
comboBox_AssistTorque.SelectedIndex = 0;
|
|
|
comboBox_AssistCadence.SelectedIndex = 0;
|
|
|
+
|
|
|
//combobox事件定义
|
|
|
this.comboBox_WorkMode.SelectedIndexChanged += new System.EventHandler(this.comboBox_WorkMode_SelectedIndexChanged);
|
|
|
this.comboBox_GearSt.SelectedIndexChanged += new System.EventHandler(this.comboBox_GearSt_SelectedIndexChanged);
|
|
@@ -127,8 +251,29 @@ namespace Welling_Motor_Debug_Tool
|
|
|
//端口设置
|
|
|
mySerialProcess.Init();
|
|
|
toolStripComboBox_ComNum.Items.AddRange(mySerialProcess.refreshPort());
|
|
|
- toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
|
|
|
- toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
|
|
|
+ if ((PortNumSave != string.Empty) && (PortBaudrateSave != string.Empty)) //有数值时采用上次使用的值
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.IndexOf(PortNumSave);
|
|
|
+ toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf(PortBaudrateSave);
|
|
|
+ PortConnect();
|
|
|
+ }
|
|
|
+ catch (System.Exception)
|
|
|
+ {
|
|
|
+ toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
|
|
|
+ toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
|
|
|
+ timer_1s.Enabled = false;
|
|
|
+ MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ timer_1s.Enabled = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //否则采用默认值
|
|
|
+ {
|
|
|
+ toolStripComboBox_ComNum.SelectedIndex = toolStripComboBox_ComNum.Items.Count > 0 ? 0 : -1;
|
|
|
+ toolStripComboBox_Baudrate.SelectedIndex = toolStripComboBox_Baudrate.Items.IndexOf("115200");
|
|
|
+ }
|
|
|
+
|
|
|
//创建线程,定时解析数据
|
|
|
Thread th = new Thread(Task_SerialProcess);
|
|
|
th.IsBackground = true;
|
|
@@ -595,8 +740,20 @@ namespace Welling_Motor_Debug_Tool
|
|
|
for (int i = 0; i < myParams.BikeParma.Count; i++)
|
|
|
{
|
|
|
richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
|
|
|
+ if (i == 8) //更新前后灯参数
|
|
|
+ {
|
|
|
+ comboBox_TailLightMode.SelectedIndex = ((Data[2 * i + 1] >> 4) & 0x0F) - 1;
|
|
|
+ comboBox_TailLightVol.SelectedIndex = ((Data[2 * i + 1] & 0x0F) == 6) ? 0 : 1;
|
|
|
+ comboBox_FrontLightVol.SelectedIndex = ((Data[2 * i] & 0x0F) == 6) ? 0 : 1;
|
|
|
+ }
|
|
|
+ else if (i == 11) //更新开关机参数
|
|
|
+ {
|
|
|
+ textBox_PowerOnDelay.Text = Convert.ToString((Data[2 * i + 1] >> 4) & 0x0F);
|
|
|
+ textBox_PowerOffDelay.Text = Convert.ToString(Data[2 * i + 1] & 0x0F);
|
|
|
+ textBox_AutoPowerOff.Text = Convert.ToString(Data[2 * i]);
|
|
|
+ }
|
|
|
}
|
|
|
- richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
|
|
|
+ richTextBox_BikeParam.Text = richTextBox_BikeParam.Text.Substring(0, richTextBox_BikeParam.Text.Length - 2);
|
|
|
//更新生产模式中整车参数
|
|
|
textBox_FacModeWheelSize.Text = (Data[1] * 256 + Data[0]).ToString();//周长
|
|
|
textBox_FacModeSpeedLimit.Text= (Data[5] * 256 + Data[4]).ToString();//限速
|
|
@@ -1189,6 +1346,8 @@ namespace Welling_Motor_Debug_Tool
|
|
|
richTextBox_OBC_BMS_RunInfo.AppendText("电池状态:" + Convert.ToString(Data[10], 16).PadLeft(2, '0').ToUpper() + " H" + "\r\n");
|
|
|
//SOH
|
|
|
richTextBox_OBC_BMS_RunInfo.AppendText("电池寿命:" + Convert.ToString(Data[11]) + " %");
|
|
|
+ //循环次数
|
|
|
+ richTextBox_OBC_BMS_RunInfo.AppendText("循环次数:" + Convert.ToString((ushort)(Data[13] * 256 + Data[12])) + " 次");
|
|
|
}));
|
|
|
}
|
|
|
break;
|
|
@@ -1250,19 +1409,17 @@ namespace Welling_Motor_Debug_Tool
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
- #endregion
|
|
|
+ #endregion
|
|
|
|
|
|
/// <summary>
|
|
|
- /// 端口连接事件
|
|
|
+ /// 端口连接或断开
|
|
|
/// </summary>
|
|
|
- /// <param name="sender"></param>
|
|
|
- /// <param name="e"></param>
|
|
|
- private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
|
|
|
+ private void PortConnect()
|
|
|
{
|
|
|
bool result = false;
|
|
|
if (连接ToolStripMenuItem.Text == "连接")
|
|
|
{
|
|
|
- result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text);
|
|
|
+ result = mySerialProcess.SerialOpen(toolStripComboBox_ComNum.Text, toolStripComboBox_Baudrate.Text, 连接开机ToolStripMenuItem.Checked, 识别通讯盒ToolStripMenuItem.Checked);
|
|
|
if (result)
|
|
|
{
|
|
|
toolStripComboBox_ComNum.Enabled = false;
|
|
@@ -1271,6 +1428,7 @@ namespace Welling_Motor_Debug_Tool
|
|
|
连接ToolStripMenuItem.Text = "断开";
|
|
|
连接ToolStripMenuItem.Checked = true;
|
|
|
label_COM_Sta.Text = toolStripComboBox_ComNum.Text + "已连接," + toolStripComboBox_Baudrate.Text;
|
|
|
+ label_PortStatus.BackColor = Color.Green;
|
|
|
}
|
|
|
}
|
|
|
else if (连接ToolStripMenuItem.Text == "断开")
|
|
@@ -1278,18 +1436,28 @@ namespace Welling_Motor_Debug_Tool
|
|
|
checkBox_OBC_StartSetGearSt.Checked = false;
|
|
|
checkBox_OBC_StartReadBMS.Checked = false;
|
|
|
checkBox_ReadRanFlash_AutoSW.Checked = false;
|
|
|
- mySerialProcess.SerialClose();
|
|
|
-
|
|
|
+ mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
|
|
|
+
|
|
|
toolStripComboBox_ComNum.Enabled = true;
|
|
|
toolStripComboBox_Baudrate.Enabled = true;
|
|
|
刷新ToolStripMenuItem.Enabled = true;
|
|
|
连接ToolStripMenuItem.Text = "连接";
|
|
|
连接ToolStripMenuItem.Checked = false;
|
|
|
label_COM_Sta.Text = "连接状态:未连接";
|
|
|
-
|
|
|
+ label_PortStatus.BackColor = Color.Red;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 端口连接事件
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void 连接ToolStripMenuItem_Click(object sender, System.EventArgs e)
|
|
|
+ {
|
|
|
+ PortConnect();
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 端口号刷新事件
|
|
|
/// </summary>
|
|
@@ -1326,6 +1494,7 @@ namespace Welling_Motor_Debug_Tool
|
|
|
private void 写入存储ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
写入存储ToolStripMenuItem.Checked = !写入存储ToolStripMenuItem.Checked;
|
|
|
+ ConfigFileSave(true, ConfigFileName);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -1387,26 +1556,29 @@ namespace Welling_Motor_Debug_Tool
|
|
|
MC_ErrorCode_Refresh = false;
|
|
|
|
|
|
//CDL连接超时
|
|
|
-#if false
|
|
|
- if (mySerialProcess.CDL_Online_Flag == false)
|
|
|
+ if (识别通讯盒ToolStripMenuItem.Checked)
|
|
|
{
|
|
|
- mySerialProcess.CDL_OnlineCheck_Cnt++;
|
|
|
- if (mySerialProcess.CDL_OnlineCheck_Cnt > 3)//3s
|
|
|
+ if (mySerialProcess.CDL_Online_Flag == false)
|
|
|
{
|
|
|
- timer_1s.Enabled = false;
|
|
|
- MessageBox.Show("连接失败!", "提示");
|
|
|
- timer_1s.Enabled = true;
|
|
|
- //关闭串口
|
|
|
- mySerialProcess.SerialClose();
|
|
|
- toolStripComboBox_ComNum.Enabled = true;
|
|
|
- toolStripComboBox_Baudrate.Enabled = true;
|
|
|
- 刷新ToolStripMenuItem.Enabled = true;
|
|
|
- 连接ToolStripMenuItem.Text = "连接";
|
|
|
- 连接ToolStripMenuItem.Checked = false;
|
|
|
- label_COM_Sta.Text = "连接状态:未连接";
|
|
|
+ mySerialProcess.CDL_OnlineCheck_Cnt++;
|
|
|
+ if (mySerialProcess.CDL_OnlineCheck_Cnt > 1)//1s
|
|
|
+ {
|
|
|
+ timer_1s.Enabled = false;
|
|
|
+ MessageBox.Show("连接失败!", "提示");
|
|
|
+ timer_1s.Enabled = true;
|
|
|
+ //关闭串口
|
|
|
+ mySerialProcess.SerialClose(断开关机ToolStripMenuItem.Checked);
|
|
|
+ toolStripComboBox_ComNum.Enabled = true;
|
|
|
+ toolStripComboBox_Baudrate.Enabled = true;
|
|
|
+ 刷新ToolStripMenuItem.Enabled = true;
|
|
|
+ 连接ToolStripMenuItem.Text = "连接";
|
|
|
+ 连接ToolStripMenuItem.Checked = false;
|
|
|
+ label_COM_Sta.Text = "连接状态:未连接";
|
|
|
+ label_PortStatus.BackColor = Color.Red;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-#endif
|
|
|
+
|
|
|
//OBC定时发送设置档位
|
|
|
if (checkBox_OBC_StartSetGearSt.Checked == true)
|
|
|
{
|
|
@@ -1635,13 +1807,31 @@ namespace Welling_Motor_Debug_Tool
|
|
|
for (int i = 0; i < 28; i++)
|
|
|
ConfigParam[i] = 0;
|
|
|
ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
|
|
|
- short wDataTemp = 0;
|
|
|
+
|
|
|
string[] strDataTemp = richTextBox_BikeParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
|
|
|
try
|
|
|
{
|
|
|
for (int i = 0; i < strDataTemp.Length; i++)
|
|
|
{
|
|
|
- wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
|
|
|
+ short wDataTemp = 0;
|
|
|
+ //前后灯参数修改
|
|
|
+ if (i == 8)
|
|
|
+ {
|
|
|
+ wDataTemp |= (short)((comboBox_TailLightMode.SelectedIndex + 1) << 12); //Bit15~Bit12:尾灯模式
|
|
|
+ wDataTemp |= (short)((comboBox_TailLightVol.SelectedIndex == 0 ? 6 : 12) << 8); //Bit11~Bit8:尾灯电压
|
|
|
+ wDataTemp |= (short)(comboBox_FrontLightVol.SelectedIndex == 0 ? 6 : 12); //Bit7~Bit0:前灯电压
|
|
|
+ }
|
|
|
+ //开关机参数
|
|
|
+ else if (i == 11)
|
|
|
+ {
|
|
|
+ wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOnDelay.Text) << 12);
|
|
|
+ wDataTemp |= (short)(Convert.ToInt16(textBox_PowerOffDelay.Text) << 8);
|
|
|
+ wDataTemp |= (short)(Convert.ToInt16(textBox_AutoPowerOff.Text));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
|
|
|
+ }
|
|
|
ConfigParam[2 * i + 2] = (byte)wDataTemp;
|
|
|
ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
|
|
|
}
|
|
@@ -3699,66 +3889,129 @@ namespace Welling_Motor_Debug_Tool
|
|
|
/// <param name="e"></param>
|
|
|
private void Button_FacModeSaveResult_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- //查询传感器
|
|
|
- richTextBox_SensorParam.Clear();
|
|
|
- textBox_FacModeSensorADC0.Text = "";
|
|
|
- textBox_FacModeSensorADC1.Text = "";
|
|
|
- textBox_FacModeSensorADC2.Text = "";
|
|
|
- textBox_FacModeSensorADC3.Text = "";
|
|
|
- textBox_FacModeSensorADC4.Text = "";
|
|
|
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) return;
|
|
|
- Delay_ms(100);
|
|
|
- //读取一次电机信息
|
|
|
- var CtrlCode = new byte[2];
|
|
|
- CtrlCode[0] = 0x00;
|
|
|
- CtrlCode[1] = 0xF0;
|
|
|
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) return;
|
|
|
- Delay_ms(100);
|
|
|
- //读取一次整车参数
|
|
|
- textBox_FacModeWheelSize.Text = "";
|
|
|
- textBox_FacModeSpeedLimit.Text = "";
|
|
|
- comboBox_FacModeAssist1.SelectedIndex = -1;
|
|
|
- comboBox_FacModeAssist2.SelectedIndex = -1;
|
|
|
- comboBox_FacModeLightVol.SelectedIndex = -1;
|
|
|
- comboBox_FacModeStartMode.SelectedIndex = -1;
|
|
|
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) return;
|
|
|
- Delay_ms(100);
|
|
|
- //读取一次助力参数
|
|
|
- var ConfigParam = new byte[4];
|
|
|
- textBox_FacModeStartGain.Text = "";
|
|
|
- textBox_FacModeCircuitK.Text = "";
|
|
|
- textBox_FacModeFltCounter.Text = "";
|
|
|
- textBox_FacModeSpeedLimitTh.Text = "";
|
|
|
- textBox_FacModeSpeedLimitEnd.Text = "";
|
|
|
- textBox_FacModeCadencePer.Text = "";
|
|
|
- ConfigParam[0] = (byte)(1 & 0xFF);
|
|
|
- ConfigParam[1] = (byte)(1 >> 8);
|
|
|
- ConfigParam[2] = (byte)(1 & 0xFF);
|
|
|
- ConfigParam[3] = (byte)(1 >> 8);
|
|
|
- if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) return;
|
|
|
- Delay_ms(100);
|
|
|
- //读取一次版本信息
|
|
|
- textBox_Model.Text = "---";
|
|
|
- textBox_SN.Text = "---";
|
|
|
- textBox_HW.Text = "---";
|
|
|
- textBox_FW.Text = "---";
|
|
|
- textBox_OBC_ReadModel.Text = "---";
|
|
|
- textBox_OBC_ReadSN.Text = "---";
|
|
|
- textBox_OBC_ReadHW.Text = "---";
|
|
|
- textBox_OBC_ReadFW.Text = "---";
|
|
|
- textBox_FacModeName.Text = "---";
|
|
|
- textBox_FacModeNum.Text = "---";
|
|
|
- textBox_FacModeHW.Text = "---";
|
|
|
- textBox_FacModeFW.Text = "---";
|
|
|
- Class_Motor_Ver.Mode = "---";
|
|
|
- Class_Motor_Ver.SN = "---";
|
|
|
- Class_Motor_Ver.HW = "---";
|
|
|
- Class_Motor_Ver.FW = "---";
|
|
|
- Class_Motor_Ver.Special = "---";
|
|
|
- if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) return;
|
|
|
- Delay_ms(100);
|
|
|
+ Button_FacModeSaveResult.Text = "存储中…";
|
|
|
|
|
|
- //提示检查
|
|
|
+ do
|
|
|
+ {
|
|
|
+ //读取一次马达参数
|
|
|
+ richTextBox_MotorParam.Clear();
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3A00, null)) break; ;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次整车参数
|
|
|
+ richTextBox_BikeParam.Clear();
|
|
|
+ textBox_FacModeWheelSize.Text = "";
|
|
|
+ textBox_FacModeSpeedLimit.Text = "";
|
|
|
+ comboBox_FacModeAssist1.SelectedIndex = -1;
|
|
|
+ comboBox_FacModeAssist2.SelectedIndex = -1;
|
|
|
+ comboBox_FacModeLightVol.SelectedIndex = -1;
|
|
|
+ comboBox_FacModeStartMode.SelectedIndex = -1;
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3C00, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次控制参数
|
|
|
+ richTextBox_ControlParam.Clear();
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x3E00, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //查询传感器
|
|
|
+ richTextBox_SensorParam.Clear();
|
|
|
+ textBox_FacModeSensorADC0.Text = "";
|
|
|
+ textBox_FacModeSensorADC1.Text = "";
|
|
|
+ textBox_FacModeSensorADC2.Text = "";
|
|
|
+ textBox_FacModeSensorADC3.Text = "";
|
|
|
+ textBox_FacModeSensorADC4.Text = "";
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4000, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次助力参数
|
|
|
+ var ConfigParam = new byte[4];
|
|
|
+ textBox_FacModeStartGain.Text = "";
|
|
|
+ textBox_FacModeCircuitK.Text = "";
|
|
|
+ textBox_FacModeFltCounter.Text = "";
|
|
|
+ textBox_FacModeSpeedLimitTh.Text = "";
|
|
|
+ textBox_FacModeSpeedLimitEnd.Text = "";
|
|
|
+ textBox_FacModeCadencePer.Text = "";
|
|
|
+ richTextBox_AssistParam.Clear();
|
|
|
+ ConfigParam[0] = (byte)(1 & 0xFF);
|
|
|
+ ConfigParam[1] = (byte)(1 >> 8);
|
|
|
+ ConfigParam[2] = (byte)(1 & 0xFF);
|
|
|
+ ConfigParam[3] = (byte)(1 >> 8);
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4304, ConfigParam)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次调试信息
|
|
|
+ richTextBox_DebugParam.Clear();
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次历史信息
|
|
|
+ richTextBox_Record.Clear();
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1E00, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次电机运行信息
|
|
|
+ var CtrlCode = new byte[2];
|
|
|
+ CtrlCode[0] = 0x00;
|
|
|
+ CtrlCode[1] = 0xF0;
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次版本信息
|
|
|
+ textBox_Model.Text = "---";
|
|
|
+ textBox_SN.Text = "---";
|
|
|
+ textBox_HW.Text = "---";
|
|
|
+ textBox_FW.Text = "---";
|
|
|
+ textBox_OBC_ReadModel.Text = "---";
|
|
|
+ textBox_OBC_ReadSN.Text = "---";
|
|
|
+ textBox_OBC_ReadHW.Text = "---";
|
|
|
+ textBox_OBC_ReadFW.Text = "---";
|
|
|
+ textBox_FacModeName.Text = "---";
|
|
|
+ textBox_FacModeNum.Text = "---";
|
|
|
+ textBox_FacModeHW.Text = "---";
|
|
|
+ textBox_FacModeFW.Text = "---";
|
|
|
+ Class_Motor_Ver.Mode = "---";
|
|
|
+ Class_Motor_Ver.SN = "---";
|
|
|
+ Class_Motor_Ver.HW = "---";
|
|
|
+ Class_Motor_Ver.FW = "---";
|
|
|
+ Class_Motor_Ver.Special = "---";
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x731, (byte)0x11, (ushort)0x3900, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次生产信息
|
|
|
+ textBox_MAC.Text = "";
|
|
|
+ textBox_MACAdd.Text = "";
|
|
|
+ textBox_MACDate.Text = "";
|
|
|
+ textBox_PP.Text = "";
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次自定义信息
|
|
|
+ textBox_User1.Text = "---";
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1300, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+ textBox_User2.Text = "---";
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1500, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+ textBox_User3.Text = "---";
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1700, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次密钥
|
|
|
+ textBox_Key.Text = "---";
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1000, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //读取一次存储标志
|
|
|
+ radioButton_EE_SaveYes.Checked = false;
|
|
|
+ radioButton_EE_SaveNo.Checked = false;
|
|
|
+ radioButton_SIP_SaveYes.Checked = false;
|
|
|
+ radioButton_SIP_SaveNo.Checked = false;
|
|
|
+ if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4800, null)) break;
|
|
|
+ Delay_ms(100);
|
|
|
+
|
|
|
+ //提示检查
|
|
|
+#if false
|
|
|
timer_1s.Enabled = false;
|
|
|
if (MessageBox.Show("请检查信息是否完整!", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
|
|
{
|
|
@@ -3769,22 +4022,130 @@ namespace Welling_Motor_Debug_Tool
|
|
|
timer_1s.Enabled = true;
|
|
|
|
|
|
Delay_ms(200);
|
|
|
+#endif
|
|
|
+
|
|
|
+ //设置文件存储路径
|
|
|
+ string Save_Path = LocalPath + "\\" + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; ;
|
|
|
+ string PD_PathName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_"); ;
|
|
|
+ Save_Path += PD_PathName;
|
|
|
+ if (!Directory.Exists(Save_Path))
|
|
|
+ Directory.CreateDirectory(Save_Path);
|
|
|
+
|
|
|
+ //保存页面
|
|
|
+ string PIC_SaveFileName = "";
|
|
|
+ Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
|
|
|
+ Graphics g = Graphics.FromImage(bit);
|
|
|
+ g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
|
|
|
+ PIC_SaveFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_测试页面" + ".png";
|
|
|
+ bit.Save(PIC_SaveFileName);
|
|
|
+
|
|
|
+ //保存数据
|
|
|
+ string DataFileName = "";
|
|
|
+ string FileInfo = "";
|
|
|
+ DataFileName = Save_Path + "\\" + textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_记录数据" + ".txt";
|
|
|
+ FileInfo += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[电机信息]\r\n";
|
|
|
+ FileInfo += "电机型号: " + textBox_FacModeName.Text + "\r\n";
|
|
|
+ FileInfo += "电机编号: " + textBox_FacModeNum.Text + "\r\n";
|
|
|
+ FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
|
|
|
+ FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
|
|
|
+ FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[马达参数]\r\n";
|
|
|
+ FileInfo += richTextBox_MotorParam.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[整车参数]\r\n";
|
|
|
+ FileInfo += richTextBox_BikeParam.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[控制参数]\r\n";
|
|
|
+ FileInfo += richTextBox_ControlParam.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[传感器参数]\r\n";
|
|
|
+ FileInfo += richTextBox_SensorParam.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[助力参数]\r\n";
|
|
|
+ FileInfo += richTextBox_AssistParam.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[调试参数]\r\n";
|
|
|
+ FileInfo += richTextBox_DebugParam.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[历史信息]\r\n";
|
|
|
+ FileInfo += richTextBox_Record.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[生产信息]\r\n";
|
|
|
+ FileInfo += "生产商: " + textBox_MAC.Text + "\r\n";
|
|
|
+ FileInfo += "生产地: " + textBox_MACAdd.Text + "\r\n";
|
|
|
+ FileInfo += "生产日期: " + textBox_MACDate.Text + "\r\n";
|
|
|
+ FileInfo += "产品标识: " + textBox_PP.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[自定义信息]\r\n";
|
|
|
+ FileInfo += "自定义1: " + textBox_User1.Text + "\r\n";
|
|
|
+ FileInfo += "自定义2: " + textBox_User2.Text + "\r\n";
|
|
|
+ FileInfo += "自定义3: " + textBox_User3.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[校验密钥]\r\n";
|
|
|
+ FileInfo += textBox_Key.Text + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ FileInfo += "[存储标志]\r\n";
|
|
|
+ FileInfo += "EEPROM: " + ((radioButton_EE_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
|
|
|
+ FileInfo += "SIP: " + ((radioButton_SIP_SaveYes.Checked == true) ? "已存储" : "未存储") + "\r\n";
|
|
|
+ FileInfo += "\r\n";
|
|
|
+ System.IO.File.WriteAllText(DataFileName, FileInfo);
|
|
|
+
|
|
|
+ timer_1s.Enabled = false;
|
|
|
+ MessageBox.Show("存储完成!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
+ timer_1s.Enabled = true;
|
|
|
+
|
|
|
+ //数据上传
|
|
|
+ if (myFtp.IsNetConnected == true)
|
|
|
+ {
|
|
|
+ string DataNow= DateTime.Now.ToString("yyyy-MM-dd");
|
|
|
+ //检查路径
|
|
|
+ if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
|
|
|
+ {
|
|
|
+ myFtp.MakeDir(toolStripTextBox_ServerPath.Text);
|
|
|
+ }
|
|
|
+ if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text, DataNow) == false)
|
|
|
+ {
|
|
|
+ myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\" + DataNow);
|
|
|
+ }
|
|
|
+ if (myFtp.DirectoryExist(toolStripTextBox_ServerPath.Text + "\\" + DataNow, PD_PathName) == false)
|
|
|
+ {
|
|
|
+ myFtp.MakeDir(toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
|
|
|
+ }
|
|
|
+ //上传文件
|
|
|
+ bool result1 = myFtp.UploadFile(PIC_SaveFileName, toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
|
|
|
+ bool result2 = myFtp.UploadFile(DataFileName, toolStripTextBox_ServerPath.Text + "\\" + DataNow + "\\" + PD_PathName);
|
|
|
+ if ((result1 & result2) == true)
|
|
|
+ {
|
|
|
+ timer_1s.Enabled = false;
|
|
|
+ MessageBox.Show("数据已上传!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
|
+ timer_1s.Enabled = true;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ timer_1s.Enabled = false;
|
|
|
+ MessageBox.Show("数据上传失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ timer_1s.Enabled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ timer_1s.Enabled = false;
|
|
|
+ MessageBox.Show("服务器断开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
+ timer_1s.Enabled = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ Button_FacModeSaveResult.Text = "保存数据";
|
|
|
+ return;
|
|
|
+
|
|
|
+ } while (false);
|
|
|
|
|
|
- //保存页面
|
|
|
- Bitmap bit = new Bitmap(this.Width, this.Height);//实例化一个和窗体一样大的bitmap
|
|
|
- Graphics g = Graphics.FromImage(bit);
|
|
|
- g.CopyFromScreen(this.Left, this.Top, 0, 0, new Size(this.Width, this.Height));//保存整个窗体为图片
|
|
|
- SaveFileDialog sf = new SaveFileDialog();
|
|
|
- sf.Title = "页面保存";
|
|
|
- sf.FileName = textBox_FacModeName.Text + "_" + textBox_FacModeNum.Text + "_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss").Replace("/", "-").Replace(":", string.Empty).Replace(" ", "_") + "_页面存储" + ".png";
|
|
|
- sf.Filter = "图片|*.png";
|
|
|
timer_1s.Enabled = false;
|
|
|
- if (sf.ShowDialog() == DialogResult.OK)
|
|
|
- {
|
|
|
- bit.Save(sf.FileName);//默认保存格式为PNG,保存成jpg格式质量不是很好
|
|
|
- }
|
|
|
+ MessageBox.Show("无效数据,读取失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
timer_1s.Enabled = true;
|
|
|
-
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -4138,5 +4499,148 @@ namespace Welling_Motor_Debug_Tool
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 系统开机按钮
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void 开机ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ byte[] Data = new byte[1];
|
|
|
+ Data[0] = 0xF1;
|
|
|
+ if (mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data))
|
|
|
+ {
|
|
|
+ 开机ToolStripMenuItem.Checked = true;
|
|
|
+ 关机ToolStripMenuItem.Checked = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 系统关机按钮
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void 关机ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ byte[] Data = new byte[1];
|
|
|
+ Data[0] = 0xF0;
|
|
|
+ if (mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Data))
|
|
|
+ {
|
|
|
+ 开机ToolStripMenuItem.Checked = false;
|
|
|
+ 关机ToolStripMenuItem.Checked = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 连接开机选择
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void 连接开机ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ 连接开机ToolStripMenuItem.Checked = !连接开机ToolStripMenuItem.Checked;
|
|
|
+ ConfigFileSave(true, ConfigFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 断开关机选择
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void 断开关机ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ 断开关机ToolStripMenuItem.Checked = !断开关机ToolStripMenuItem.Checked;
|
|
|
+ ConfigFileSave(true, ConfigFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 识别通讯盒选择
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void 识别通讯盒ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ 识别通讯盒ToolStripMenuItem.Checked = !识别通讯盒ToolStripMenuItem.Checked;
|
|
|
+ ConfigFileSave(true, ConfigFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 将配置信息导出为cfg文件
|
|
|
+ /// </summary>
|
|
|
+ private void ConfigFileSave(bool DeleteFlag, string FileName)
|
|
|
+ {
|
|
|
+ if (DeleteFlag)
|
|
|
+ {
|
|
|
+ if (File.Exists(FileName))
|
|
|
+ File.Delete(FileName);
|
|
|
+ }
|
|
|
+ string CfgFileInfo = "";
|
|
|
+ CfgFileInfo += "[PortSet]" + "\r\n";
|
|
|
+ CfgFileInfo += "PortNum:" + toolStripComboBox_ComNum.Text + "\r\n";
|
|
|
+ CfgFileInfo += "PortBaudrate:" + toolStripComboBox_Baudrate.Text + "\r\n";
|
|
|
+ CfgFileInfo += "AutoOn:" + 连接开机ToolStripMenuItem.Checked.ToString() + "\r\n";
|
|
|
+ CfgFileInfo += "AutoOff:" + 断开关机ToolStripMenuItem.Checked.ToString() + "\r\n";
|
|
|
+ CfgFileInfo += "CheckCDL:" + 识别通讯盒ToolStripMenuItem.Checked.ToString() + "\r\n";
|
|
|
+ CfgFileInfo += "\r\n";
|
|
|
+ CfgFileInfo += "[Option]" + "\r\n";
|
|
|
+ CfgFileInfo += "SaveWhenWrite:" + 写入存储ToolStripMenuItem.Checked.ToString() + "\r\n";
|
|
|
+ CfgFileInfo += "OfflineEnable:" + 允许ToolStripMenuItem.Checked + "\r\n";
|
|
|
+ CfgFileInfo += "\r\n";
|
|
|
+ CfgFileInfo += "[ServerSet]" + "\r\n";
|
|
|
+ CfgFileInfo += "IPAddress:" + toolStripTextBox_ServerIP.Text + "\r\n";
|
|
|
+ CfgFileInfo += "Port:" + toolStripTextBox_ServerPort.Text + "\r\n";
|
|
|
+ CfgFileInfo += "User:" + toolStripTextBox_ServerUser.Text + "\r\n";
|
|
|
+ CfgFileInfo += "Password:" + toolStripTextBox_ServerPasswd.Text + "\r\n";
|
|
|
+ CfgFileInfo += "PathName:" + toolStripTextBox_ServerPath.Text + "\r\n";
|
|
|
+ System.IO.File.WriteAllText(FileName, CfgFileInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 配置状态更新,点击时保存
|
|
|
+ /// </summary>
|
|
|
+ private void ConfigFileSave_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ ConfigFileSave(true, ConfigFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 文本框修改结束,回车保存
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void ConfigFileSave_KeyDown(object sender, KeyEventArgs e)
|
|
|
+ {
|
|
|
+ if (e.KeyCode == Keys.Enter)
|
|
|
+ {
|
|
|
+ ConfigFileSave(true, ConfigFileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 允许离线使用
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void 允许ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ 允许ToolStripMenuItem.Checked = true;
|
|
|
+ 不允许ToolStripMenuItem.Checked = false;
|
|
|
+ ConfigFileSave(true, ConfigFileName);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 不允许离线使用
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="sender"></param>
|
|
|
+ /// <param name="e"></param>
|
|
|
+ private void 不允许ToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ 允许ToolStripMenuItem.Checked = false;
|
|
|
+ 不允许ToolStripMenuItem.Checked = true;
|
|
|
+ ConfigFileSave(true, ConfigFileName);
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|