Parcourir la source

V1.2.4
1、新增配置项,包括连接开机、断开关机、识别通讯盒、离线使用、FTP服务器配置等;
2、开机时识别配置文件,存在配置文件时调用配置文件,并自动连接端口,不存在配置文件时按照默认值生成配置文件;
3、修改配置信息时,更新配置文件;
4、保存数据时完成所有数据的自动读取,并保存测试图片和测试数据,同时将测试图片和测试数据上传FTP服务器保存;
5、增加手动开关机控制。

Dail il y a 2 ans
Parent
commit
1465a43acd

BIN
.vs/Welling_Motor_Debug_Tool/v17/.suo


+ 9 - 1
Welling_Motor_Debug_Tool/App.config

@@ -1,6 +1,14 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <startup> 
         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
     </startup>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
 </configuration>

Fichier diff supprimé car celui-ci est trop grand
+ 446 - 77
Welling_Motor_Debug_Tool/Form1.Designer.cs


+ 609 - 105
Welling_Motor_Debug_Tool/Form1.cs

@@ -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);
+        }
     }
+
+
 }

+ 5 - 5
Welling_Motor_Debug_Tool/Params.cs

@@ -10,15 +10,15 @@ namespace Welling_Motor_Debug_Tool
     {
         public List<string> MotorParma = new List<string> { "极对数","电阻","d轴电感","q轴电感","永磁体磁链","Id最大值","Id最小值",
                                                             "额定转速","额定功率","额定电流","额定电压","惯量","最大转矩"};
-        public List<string> BikeParma = new List<string> { "轮胎周长", "电控传动比", "助力最大限速", "推行模式限速", "前牙盘T数", "后牙盘T数",
-                                                           "助力方案1", "助力方案2", "前后灯电压","轮胎周长微调","启动模式","自动关机时间" };
+        public List<string> BikeParma = new List<string> { "轮胎周长", "电控传动比", "助力模式限速", "推行模式限速", "前牙盘T数", "后牙盘T数",
+                                                           "助力方案1", "助力方案2", "前后灯参数","轮胎周长微调","启动模式","开关机参数" };
         public List<string> ControlParma = new List<string> {"位置传感器零点","位置传感器当前零点","峰值电流","电流保护阈值","最高档电压保护阈值","最高档欠压保护阈值",
-                                                             "超速保护阈值","温度保护阈值","温度保护恢复阈值","温度降额启动阈值"};
+                                                             "超速保护阈值","过热保护阈值","过热保护恢复阈值","过热降额启动阈值"};
         public List<string> AssistParam = new List<string> { "零速启动增益", "巡航启动增益", "助力转矩曲线编号", "助力踏频曲线编号",
                                                              "转矩曲线.a", "转矩曲线.b","转矩曲线.c","转矩曲线.d",
                                                              "踏频曲线.a", "踏频曲线.b","踏频曲线.c","踏频曲线.d",
-                                                             "助力启动阈值", "助力停止阈值", "启动时电流增长阶梯",
-                                                             "启动对应踏频脉冲数", "转矩滤波对应踏频脉冲数", "待速转速", "待速最大电流",
+                                                             "助力启动阈值", "助力停止阈值", "电压限幅阶梯",
+                                                             "启动对应踏频脉冲数", "转矩滤波对应踏频脉冲数", "待速转速", "启动平滑系数阶梯",
                                                              "车速限幅启动阈值", "车速限幅停止阈值" ,"踏频占比"};
         public List<string> DebugParam = new List<string> { "整体运行模式","位置获取模式","采样模式","旋转方向","定位电流","拖拽电压",
                                                             "拖拽电流","拖拽频率","加速斜率","减速斜率","转速环控制器带宽","转速环控制器m",

+ 18 - 9
Welling_Motor_Debug_Tool/Serial_Process.cs

@@ -37,7 +37,7 @@ namespace Welling_Motor_Debug_Tool
         #endregion
 
         #region 打开串口
-        public bool SerialOpen(string portNum, string baudRate)
+        public bool SerialOpen(string portNum, string baudRate, bool AutoPowerOn, bool CheckOnline)
         {
             byte[] Data = new byte[1];
 
@@ -51,13 +51,19 @@ namespace Welling_Motor_Debug_Tool
                     mySerial.Open();
 
                     //发送指令检测CDL是否在线
-                    SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x1100, null);
-                    CDL_OnlineCheck_Cnt = 0;
-                    CDL_Online_Flag = false;
+                    if (CheckOnline == true)
+                    {
+                        SendCmd((ushort)0x7FF, (byte)0x11, (ushort)0x1100, null);
+                        CDL_OnlineCheck_Cnt = 0;
+                        CDL_Online_Flag = false;
+                    }
 
                     //开机
-                    Data[0] = 0xF1;
-                    SendCmd(0x7FF, 0x16, 0x2201, Data);
+                    if (AutoPowerOn == true)
+                    {
+                        Data[0] = 0xF1;
+                        SendCmd(0x7FF, 0x16, 0x2201, Data);
+                    }                    
 
                     return true;
                 }
@@ -72,7 +78,7 @@ namespace Welling_Motor_Debug_Tool
         #endregion
 
         #region 关闭串口
-        public bool SerialClose()
+        public bool SerialClose(bool AutoPowerOff)
         {
             byte[] Data = new byte[1];
 
@@ -81,8 +87,11 @@ namespace Welling_Motor_Debug_Tool
                 if (mySerial.IsOpen)
                 {
                     //关机
-                    Data[0] = 0xF0;
-                    SendCmd(0x7FF, 0x16, 0x2201, Data);
+                    if (AutoPowerOff == true)
+                    {
+                        Data[0] = 0xF0;
+                        SendCmd(0x7FF, 0x16, 0x2201, Data);
+                    }                    
 
                     //打开时点击,则关闭串口
                     mySerial.Close();

+ 1 - 0
Welling_Motor_Debug_Tool/Welling_Motor_Debug_Tool.csproj

@@ -71,6 +71,7 @@
     <Compile Include="Form1.Designer.cs">
       <DependentUpon>Form1.cs</DependentUpon>
     </Compile>
+    <Compile Include="ftp.cs" />
     <Compile Include="Params.cs" />
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />

BIN
Welling_Motor_Debug_Tool/bin/Debug/Welling_Motor_Debug_Tool.exe


+ 9 - 1
Welling_Motor_Debug_Tool/bin/Debug/Welling_Motor_Debug_Tool.exe.config

@@ -1,6 +1,14 @@
-<?xml version="1.0" encoding="utf-8" ?>
+<?xml version="1.0" encoding="utf-8"?>
 <configuration>
     <startup> 
         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
     </startup>
+  <runtime>
+    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
+      <dependentAssembly>
+        <assemblyIdentity name="Microsoft.Bcl.AsyncInterfaces" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
+        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
+      </dependentAssembly>
+    </assemblyBinding>
+  </runtime>
 </configuration>

BIN
Welling_Motor_Debug_Tool/bin/Debug/Welling_Motor_Debug_Tool.pdb


BIN
Welling_Motor_Debug_Tool/bin/Debug/Welling_Motor_Debug_Tool_202308301600.exe


+ 461 - 0
Welling_Motor_Debug_Tool/ftp.cs

@@ -0,0 +1,461 @@
+using System;
+using System.Collections.Generic;
+using System.Net;
+using System.Text;
+using System.IO;
+using System.Windows.Forms;
+
+namespace Welling_Motor_Debug_Tool
+{
+    public class ftp
+    {
+        string serverIP;
+        string serverPort;
+        string userId;
+        string passWord;
+        public bool IsNetConnected = false;
+
+        /// <summary>
+        /// 配置网络
+        /// </summary>
+        /// <param name="serverIP"></param>
+        /// <param name="serverPort"></param>
+        /// <param name="userId"></param>
+        /// <param name="passWord"></param>
+        public void FtpOption(string serverIP, string serverPort, string userId, string passWord)
+        {
+            this.serverIP = serverIP;
+            this.serverPort = serverPort;
+            this.userId = userId;
+            this.passWord = passWord;
+        }
+
+        /// <summary>
+        /// 检查网络
+        /// </summary>
+        /// <returns>bool</returns>
+        public bool CheckFtp()
+        {
+            try
+            {
+                Uri uri = new Uri(string.Format("ftp://{0}/{1}", serverIP, "/"));
+                FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(uri);
+                ftpRequest.Credentials = new NetworkCredential(userId, passWord);
+                ftpRequest.Method = WebRequestMethods.Ftp.PrintWorkingDirectory;
+                FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();
+                ftpResponse.Close();
+                IsNetConnected = true;
+                return true;
+            }
+            catch (Exception)
+            {
+                IsNetConnected = false;
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 文件上传
+        /// </summary>
+        /// <param name="sourceFullPath">要上传文件全名</param>
+        /// <param name="targetPath">服务器端地址(temp)</param>
+        /// <returns></returns>
+        public bool UploadFile(string sourceFullPath, string targetPath)
+        {
+            FtpWebRequest reqFTP = null;
+            FileStream fs = null;
+            Stream strm = null;
+
+            FileInfo fileInf = new FileInfo(sourceFullPath);
+            string fileName = sourceFullPath.Substring(sourceFullPath.LastIndexOf("\\") + 1);
+
+            //远端存在该文件时,先删除
+            if (FileExist(targetPath, fileName))
+            {
+                DeleteFile(targetPath + "/" + fileName);
+            }
+
+            Uri uri = new Uri("ftp://" + serverIP + ":" + serverPort + "/" + targetPath + "/" + Uri.EscapeDataString(fileName));
+            reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+            reqFTP.Credentials = new NetworkCredential(userId, passWord);
+            reqFTP.KeepAlive = false;
+            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
+            reqFTP.UseBinary = true;
+            reqFTP.UsePassive = true;
+            reqFTP.ContentLength = fileInf.Length;
+            byte[] buff = new byte[2048];
+            int contentLen = 0;
+            fs = fileInf.OpenRead();
+            try
+            {
+                strm = reqFTP.GetRequestStream();
+                while ((contentLen = fs.Read(buff, 0, buff.Length)) != 0)
+                {
+                    strm.Write(buff, 0, contentLen);
+                }
+                fs.Close();
+                strm.Close();
+                return true;
+            }
+            catch (Exception ex)
+            {
+                fs.Close();
+                strm.Close();
+                //throw new Exception("上传文件失败,原因: " + ex.Message);
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 文件下载
+        /// </summary>
+        /// <param name="filePath">文件本地存放路径</param>
+        /// <param name="serverPath">远端文件路径</param>
+        /// <param name="fileName">文件名</param>
+        /// <returns>bool</returns>
+        public bool DownloadFile(string sourceFullPath, string targetFullPath)
+        {
+            FtpWebRequest ftpRequest = null;
+            FileStream outputStream = null;
+            FtpWebResponse response = null;
+            Stream ftpStream = null;
+
+            try
+            {
+                string fileName = sourceFullPath.Substring(sourceFullPath.LastIndexOf("/") + 1);
+                if (Directory.Exists(targetFullPath) == false)
+                    Directory.CreateDirectory(targetFullPath);
+                outputStream = new FileStream(targetFullPath + "\\" + fileName, FileMode.Create);
+                Uri uri = new Uri("ftp://" + serverIP + "/" + sourceFullPath);
+                ftpRequest = (FtpWebRequest)FtpWebRequest.Create(uri);
+                ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;
+                ftpRequest.UseBinary = true;
+                ftpRequest.UsePassive = true;
+                ftpRequest.Proxy = null;
+                ftpRequest.Credentials = new NetworkCredential(userId, passWord);
+                response = (FtpWebResponse)ftpRequest.GetResponse();
+                ftpStream = response.GetResponseStream();
+                int readCount = 0;
+                byte[] buffer = new byte[2048];
+
+                while ((readCount = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
+                {
+                    outputStream.Write(buffer, 0, readCount);
+                }
+                outputStream.Close();
+                ftpStream.Close();
+                response.Close();
+                return true;
+            }
+            catch (Exception ex)
+            {
+                outputStream.Close();
+                ftpStream.Close();
+                response.Close();
+                //throw new Exception("下载文件失败,原因: " + ex.Message);
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 删除文件
+        /// </summary>
+        /// <param name="fileName"></param>
+        public void DeleteFile(string fileName)
+        {
+            try
+            {
+                Uri uri = new Uri("ftp://" + serverIP + "/" + fileName);
+                FtpWebRequest reqFTP;
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+
+                reqFTP.Credentials = new NetworkCredential(userId, passWord);
+                reqFTP.KeepAlive = false;
+                reqFTP.Method = WebRequestMethods.Ftp.DeleteFile;
+                reqFTP.UsePassive = false;
+
+                string result = String.Empty;
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                long size = response.ContentLength;
+                Stream datastream = response.GetResponseStream();
+                StreamReader sr = new StreamReader(datastream);
+                result = sr.ReadToEnd();
+                sr.Close();
+                datastream.Close();
+                response.Close();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("文件删除失败!" + ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 删除文件夹
+        /// </summary>
+        /// <param name="folderName"></param>
+        public void RemoveDirectory(string folderName)
+        {
+            try
+            {
+                Uri uri = new Uri("ftp://" + serverIP + "/" + folderName);
+                FtpWebRequest reqFTP;
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+
+                reqFTP.Credentials = new NetworkCredential(userId, passWord);
+                reqFTP.KeepAlive = false;
+                reqFTP.Method = WebRequestMethods.Ftp.RemoveDirectory;
+                reqFTP.UsePassive = false;
+
+                string result = String.Empty;
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                long size = response.ContentLength;
+                Stream datastream = response.GetResponseStream();
+                StreamReader sr = new StreamReader(datastream);
+                result = sr.ReadToEnd();
+                sr.Close();
+                datastream.Close();
+                response.Close();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("文件夹删除失败!" + ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 获取当前目录下明细(包含文件和文件夹)
+        /// </summary>
+        /// <param name="ServerPath">远端的地址</param>
+        /// <param name="WRMethods">
+        /// <returns></returns>
+        /// 
+        private string[] GetFileList(string ServerPath, string WRMethods)
+        {
+            StringBuilder result = null;
+            FtpWebRequest ftp = null;
+            WebResponse response = null;
+            StreamReader reader = null;
+
+            try
+            {
+                result = new StringBuilder();
+                Uri uri = new Uri("ftp://" + serverIP + "/" + ServerPath);
+                ftp = (FtpWebRequest)FtpWebRequest.Create(uri);
+                ftp.Credentials = new NetworkCredential(userId,passWord);
+                ftp.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
+                ftp.UsePassive = true;
+                response = ftp.GetResponse();
+                reader = new StreamReader(response.GetResponseStream(), Encoding.Default);
+                string line = reader.ReadLine();
+                while (line != null)
+                {
+                    result.Append(line);
+                    result.Append("\n");
+                    line = reader.ReadLine();
+                } 
+                if (result.ToString() != "")
+                {
+                    result.Remove(result.ToString().LastIndexOf("\n"), 1);
+                }
+                reader.Close();
+                response.Close();
+                return result.ToString().Split('\n');
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("获取文件列表失败,原因: " + ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 获得文件列表
+        /// </summary>
+        /// <param name="path"></param>
+        /// <returns></returns>
+        /// 
+        public string[] GetFileNameList(string dirName)
+        {
+            string[] drectory = GetFileList(dirName, WebRequestMethods.Ftp.ListDirectoryDetails);
+            List<string> strList = new List<string>();
+            if (drectory.Length > 0)
+            {
+                foreach (string str in drectory)
+                {
+                    if (str.Trim().Length == 0)
+                        continue;
+                    //会有两种格式的详细信息返回
+                    //一种包含<DIR>
+                    //一种第一个字符串是drwxerwxx这样的权限操作符号
+                    //现在写代码包容两种格式的字符串
+                    if (!str.Trim().Contains("<DIR>"))
+                    {
+                        strList.Add(str.Substring(str.LastIndexOf(":") + 4).Trim()) ;
+                    }
+                    else
+                    {
+                        if (str.Trim().Substring(0, 1).ToUpper() != "D")
+                        {
+                            strList.Add(str.Substring(str.LastIndexOf(":") + 1).Trim()) ;
+                        }
+                    }
+                }
+            }
+            return strList.ToArray();
+        }
+
+        /// <summary>
+        /// 获取文件夹下明细
+        /// </summary>
+        /// <param name="path"></param>
+        /// <returns></returns>
+        public string[] GetFilesDetailList(string dirName)
+        {
+            return GetFileList(dirName, WebRequestMethods.Ftp.ListDirectoryDetails);
+        }
+
+        /// <summary>
+        /// 获取目录列表
+        /// </summary>
+        /// <param name="dirName">远端的地址</param>
+        /// <returns></returns>
+        /// 
+        public string[] GetDirectoryList(string dirName)
+        {
+            string[] drectory = GetFileList(dirName, WebRequestMethods.Ftp.ListDirectoryDetails);
+            List<string> strList = new List<string>();
+            if (drectory.Length > 0)
+            {
+                foreach (string str in drectory)
+                {
+                    if (str.Trim().Length == 0)
+                        continue;
+                    //会有两种格式的详细信息返回
+                    //一种包含<DIR>
+                    //一种第一个字符串是drwxerwxx这样的权限操作符号
+                    //现在写代码包容两种格式的字符串
+                    if (str.Trim().Contains("<DIR>"))
+                    {
+                        strList.Add(str.Substring(39).Trim());
+                    }
+                    else
+                    {
+                        if (str.Trim().Substring(0, 1).ToUpper() == "D")
+                        {
+                            strList.Add(str.Substring(55).Trim());
+                        }
+                    }
+                }
+            }
+            return strList.ToArray();
+        }
+
+        /// <summary>
+        /// 判断当前目录下指定的子目录是否存在
+        /// </summary>
+        /// <param name="RemoteDirectoryName">指定的目录名</param>
+        public bool DirectoryExist(string rootDir, string RemoteDirectoryName)
+        {
+            string[] dirList = GetDirectoryList(rootDir);//获取子目录
+            if (dirList.Length > 0)
+            {
+                foreach (string str in dirList)
+                {
+                    if (str.Trim() == RemoteDirectoryName.Trim())
+                    {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 判断目录下指定的文件是否存在
+        /// </summary>
+        /// <param name="rootDir">远端目录</param>
+        /// <param name="fileName">指定文件</param>
+        /// <returns></returns>
+        public bool FileExist(string rootDir, string fileName)
+        {
+            string[] fileList = GetFileNameList(rootDir);
+            if (fileList.Length > 0)
+            {
+                foreach (string file in fileList)
+                {
+                    if (file.Substring(file.LastIndexOf("/") + 1) == fileName)
+                    {
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        /// <summary>
+        /// 创建目录
+        /// </summary>
+        /// <param name="dirName"></param>
+        public void MakeDir(string dirName)
+        {
+            FtpWebRequest reqFTP;
+            try
+            {
+                Uri uri = new Uri("ftp://" + serverIP + "/" + dirName);
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+                reqFTP.Method = WebRequestMethods.Ftp.MakeDirectory;
+                reqFTP.UseBinary = true;
+                reqFTP.UsePassive = true;
+                reqFTP.Credentials = new NetworkCredential(userId,passWord);
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                Stream ftpStream = response.GetResponseStream();
+                ftpStream.Close();
+                response.Close();
+            }
+            catch (Exception ex)
+            {
+                MessageBox.Show("创建文件失败,原因: " + ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 重命名
+        /// </summary>
+        /// <param name="currentFilename"></param>
+        /// <param name="newFilename"></param>
+        public void ReName(string currentFilename, string newFilename)
+        {
+            FtpWebRequest reqFTP;
+            try
+            {
+                Uri uri = new Uri("ftp://" + serverIP + "/" + currentFilename);
+                reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
+                reqFTP.Method = WebRequestMethods.Ftp.Rename;
+                reqFTP.RenameTo = newFilename;
+                reqFTP.UseBinary = true;
+                reqFTP.UsePassive = false;
+                reqFTP.Credentials = new NetworkCredential(userId,passWord);
+                FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
+                Stream ftpStream = response.GetResponseStream();
+
+                ftpStream.Close();
+                response.Close();
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("FtpHelper ReName Error --> " + ex.Message);
+            }
+        }
+
+        /// <summary>
+        /// 移动文件
+        /// </summary>
+        /// <param name="currentFilename"></param>
+        /// <param name="newFilename"></param>
+        public void MovieFile(string currentFilename, string newDirectory)
+        {
+            ReName(currentFilename, newDirectory);
+        }
+
+    }
+}

BIN
Welling_Motor_Debug_Tool/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache


BIN
Welling_Motor_Debug_Tool/obj/Debug/Welling_Motor_Debug_Tool.csproj.AssemblyReference.cache


+ 1 - 1
Welling_Motor_Debug_Tool/obj/Debug/Welling_Motor_Debug_Tool.csproj.CoreCompileInputs.cache

@@ -1 +1 @@
-854ce549c22e80d36bc9c6e11352c03ec99afc21
+353ecbfa050d99993dc581d24aa6c56b59c7d67b

BIN
Welling_Motor_Debug_Tool/obj/Debug/Welling_Motor_Debug_Tool.csproj.GenerateResource.cache


BIN
Welling_Motor_Debug_Tool/obj/Debug/Welling_Motor_Debug_Tool.exe


BIN
Welling_Motor_Debug_Tool/obj/Debug/Welling_Motor_Debug_Tool.pdb


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff