Kaynağa Gözat

增加测试代码,未编译。

Dail 1 yıl önce
ebeveyn
işleme
0a2d49ac4f

BIN
.vs/Welling_Motor_Debug_Tool/v17/.suo


BIN
Welling_Motor_Debug_Tool/bin/Debug/Welling_Motor_Debug_Tool.pdb


+ 417 - 125
Welling_Motor_Debug_Tool/mainForm.cs

@@ -45,6 +45,13 @@ namespace Welling_Motor_Debug_Tool
         public static Login EnterForm1 = new Login();
         //生产配置文件信息
         ArrayList array_CfgInfo = new ArrayList();
+        //写入参数返回标志和计数
+        public bool WriteACK = false;
+        public ushort WriteCnt = 0;
+        //写入参数返回提示标志
+        public bool ACK_DisFlag = true;
+        //Boot版本信息
+        public string BootInfo = "";
         #endregion
 
         #region 故障日志结构体定义
@@ -99,7 +106,7 @@ namespace Welling_Motor_Debug_Tool
             //预留
             public UInt16 RS1;
             public UInt16 RS2;
-            public UInt16 RS3;            
+            public UInt16 RS3;
         };
 
         #endregion
@@ -137,7 +144,7 @@ namespace Welling_Motor_Debug_Tool
                         tabPage_OtherInfo.Parent = null;
                         tabPage_OBC.Parent = null;
                         tabPage_RAMorFLASH.Parent = null;
-                        tabPage_FactoryMode.Parent = null;                        
+                        tabPage_FactoryMode.Parent = null;
                         tabPage_DebugInfo.Parent = null;
                         //显示运行信息
                         tabPage_RunInfo.Parent = tabControl2;
@@ -168,8 +175,10 @@ namespace Welling_Motor_Debug_Tool
                         {
                             tabPage_ProductMode_Write.Parent = null;
                             tabPage_ProductMode_Read.Parent = tabControl1;
-                        }                        
-                    }                 
+                        }
+                        //应答指令不提示
+                        ACK_DisFlag = false;
+                    }
                     else if (EnterForm1.comboBox_User.Text == "工程配置")
                     {
                         //隐藏工作台内容,新建窗口完成配置
@@ -242,7 +251,7 @@ namespace Welling_Motor_Debug_Tool
                     toolStripTextBox_ServerPasswd.Text = array_CfgInfo[15].ToString().Split(':')[1];
                     toolStripTextBox_ServerPath.Text = array_CfgInfo[16].ToString().Split(':')[1];
                     //MacInfo
-                    toolStripTextBox_MAC.Text= array_CfgInfo[19].ToString().Split(':')[1];
+                    toolStripTextBox_MAC.Text = array_CfgInfo[19].ToString().Split(':')[1];
                     toolStripTextBoxMACAddr.Text = array_CfgInfo[20].ToString().Split(':')[1];
                     toolStripTextBox_MACDate.Text = DateTime.Now.ToString("yyyyMMdd");
                     toolStripTextBox_MACPD.Text = array_CfgInfo[22].ToString().Split(':')[1];
@@ -256,18 +265,18 @@ namespace Welling_Motor_Debug_Tool
                 catch (System.Exception)
                 {
                     timer_1s.Enabled = false;
-                    MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);                    
+                    MessageBox.Show("参数格式错误,写入默认值!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                     timer_1s.Enabled = true;
                     ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
                 }
-                
+
             }
             else //不存在配置文件,生成文件写入默认值
             {
                 ConfigFileSave(false, localInfo.LocalPath + localInfo.ConfigFileName);
             }
             //配置网络FTP服务器
-            myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text);            
+            myFtp.FtpOption(toolStripTextBox_ServerIP.Text, toolStripTextBox_ServerPort.Text, toolStripTextBox_ServerUser.Text, toolStripTextBox_ServerPasswd.Text);
             //创建线程,定时检测网络连接状态
             Thread th = new Thread(NetworkCheck);
             th.IsBackground = true;
@@ -290,7 +299,7 @@ namespace Welling_Motor_Debug_Tool
                     myFtp.IsNetConnected = true;
                 }
                 else//服务器连接失败
-                {                                        
+                {
                     label_Server_ComStatus.Text = "网络断开";
                     label_ServerStatus.BackColor = Color.Red;
                     myFtp.IsNetConnected = false;
@@ -299,7 +308,7 @@ namespace Welling_Motor_Debug_Tool
                         timer_1s.Enabled = false;
                         MessageBox.Show("网络断开,将自动关闭!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         timer_1s.Enabled = true;
-                        this.Close();                        
+                        this.Close();
                     }
                     else //离线使用
                     {
@@ -405,7 +414,7 @@ namespace Welling_Motor_Debug_Tool
                 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;
@@ -464,7 +473,7 @@ namespace Welling_Motor_Debug_Tool
             string SaveData = "";
             //Log1
             if (Log1.Error_Index != 0xFFFF)
-            {               
+            {
                 SaveData += "故障序号:" + Convert.ToString(Log1.Error_Index) + ", ";
                 SaveData += "备注1:" + Convert.ToString(Log1.NotesInfo1) + ", ";
                 SaveData += "备注2:" + Convert.ToString(Log1.NotesInfo2) + ", ";
@@ -796,7 +805,7 @@ namespace Welling_Motor_Debug_Tool
                                     textBox_RunInfo_AvgPower.Text = Convert.ToString(DataTemp * 10) + " mAh/km";
                                     //PCB温度
                                     DataTemp = (ushort)(Data[21]);
-                                    textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40))+" ℃";
+                                    textBox_RunInfo_T_PCB.Text = Convert.ToString((int)(DataTemp - 40)) + " ℃";
                                     Class_MotorTemp.String = textBox_RunInfo_T_PCB.Text;
                                     Class_MotorTemp.Data = DataTemp - 40;
                                     //绕组温度
@@ -841,11 +850,17 @@ namespace Welling_Motor_Debug_Tool
                             {
                                 this.Invoke((EventHandler)(delegate
                                 {
-                                    timer_1s.Enabled = false;
-                                    MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
-                                    timer_1s.Enabled = true;
-                                    //关机反馈
-                                    PowerOffAckStatus = true;
+                                    if (ACK_DisFlag == true)
+                                    {
+                                        timer_1s.Enabled = false;
+                                        MessageBox.Show("OK", "反馈指令", MessageBoxButtons.OK, MessageBoxIcon.Information);
+                                        timer_1s.Enabled = true;
+                                        //关机反馈
+                                        PowerOffAckStatus = true;
+                                    }
+                                    //应答标志置位
+                                    WriteACK = true;
+                                    WriteCnt++;
                                 }));
                             }
                             break;
@@ -878,29 +893,29 @@ namespace Welling_Motor_Debug_Tool
                                     richTextBox_BikeParam.Clear();
                                     for (int i = 0; i < myParams.BikeParma.Count; i++)
                                     {
-                                        if (i == 9)                                        
-                                            richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");                                        
+                                        if (i == 9)
+                                            richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((short)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
                                         else
                                             richTextBox_BikeParam.AppendText(myParams.BikeParma[i] + "=" + Convert.ToString((ushort)(Data[2 * i + 1] * 256 + Data[2 * i])) + ", ");
                                         //更新前后灯参数
-                                        if (i == 8) 
+                                        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) 
+                                        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();//限速
+                                    textBox_FacModeSpeedLimit.Text = (Data[5] * 256 + Data[4]).ToString();//限速
                                     DataTemp = (int)(Data[13] * 256 + Data[12]);//助力方案1
                                     if (DataTemp == 0) comboBox_FacModeAssist1.SelectedIndex = 0;
                                     else if (DataTemp == 341) comboBox_FacModeAssist1.SelectedIndex = 1;
@@ -1313,7 +1328,7 @@ namespace Welling_Motor_Debug_Tool
                     case 0xAB0B:
                     case 0xAB0C:
                         {
-                            unchecked 
+                            unchecked
                             {
                                 this.Invoke((EventHandler)(delegate
                                 {
@@ -1462,7 +1477,7 @@ namespace Welling_Motor_Debug_Tool
                                 {
                                     //程序特性
                                     textBox_SP.Text = "";
-                                    textBox_OBC_ReadSP.Text = "";    
+                                    textBox_OBC_ReadSP.Text = "";
                                     textBox_FacModeSP.Text = "";
                                     for (ushort i = 0; i < 32; i++)
                                     {
@@ -1547,6 +1562,14 @@ namespace Welling_Motor_Debug_Tool
                             }
                             break;
                         }
+                    case 0xC109: //Boot版本信息
+                        {
+                            for (ushort i = 0; i < 9; i++)
+                            {
+                                BootInfo += ((char)Data[i]).ToString();
+                            }
+                            break;
+                        }
                     default:
                         {
                             break;
@@ -1644,7 +1667,7 @@ namespace Welling_Motor_Debug_Tool
                             }
                             break;
                         }
-                    
+
                     default: break;
                 }
             }
@@ -1836,7 +1859,7 @@ namespace Welling_Motor_Debug_Tool
                     }
                 }
             }
-            
+
             //OBC定时发送设置档位
             if (checkBox_OBC_StartSetGearSt.Checked == true)
             {
@@ -1881,13 +1904,13 @@ namespace Welling_Motor_Debug_Tool
                     if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
                     {
                         checkBox_ReadRanFlash_AutoSW.Checked = false;
-                        MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);                        
+                        MessageBox.Show("请输入起始和结束地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         continue;
                     }
                     else if ((textBox_Address_Begin.Text.Length != 8) || (textBox_Address_End.Text.Length != 8))
                     {
                         checkBox_ReadRanFlash_AutoSW.Checked = false;
-                        MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);                        
+                        MessageBox.Show("请检查地址长度!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                         continue;
                     }
                     else
@@ -1900,7 +1923,7 @@ namespace Welling_Motor_Debug_Tool
                         if (Addres_End < Address_Begin)
                         {
                             checkBox_ReadRanFlash_AutoSW.Checked = false;
-                            MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);                            
+                            MessageBox.Show("结束地址必须大于或等于起始地址!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                             continue;
                         }
                         else
@@ -1924,12 +1947,12 @@ namespace Welling_Motor_Debug_Tool
 
         }
 
-       /// <summary>
-       /// 字符串转成字节流
-       /// </summary>
-       /// <param name="hexStr"></param>
-       /// <param name="Flag_Space"></param>
-       /// <returns></returns>
+        /// <summary>
+        /// 字符串转成字节流
+        /// </summary>
+        /// <param name="hexStr"></param>
+        /// <param name="Flag_Space"></param>
+        /// <returns></returns>
         public static byte[] HexStringToBytes(string hexStr, bool Flag_Space)
         {
             if (string.IsNullOrEmpty(hexStr))
@@ -1995,10 +2018,10 @@ namespace Welling_Motor_Debug_Tool
             {
                 if ((c is TextBox))
                 {
-                    if(c.Name != textBox_ErrorCode.ToString())
+                    if (c.Name != textBox_ErrorCode.ToString())
                         c.Text = "---";
                 }
-            }          
+            }
         }
 
         /// <summary>
@@ -2040,7 +2063,7 @@ namespace Welling_Motor_Debug_Tool
             ConfigParam[0] = (byte)((写入存储ToolStripMenuItem.Checked) ? 0x01 : 0x00);
             short wDataTemp = 0;
             ushort DataTemp = 0;
-            string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", "},StringSplitOptions.None);
+            string[] strDataTemp = richTextBox_MotorParam.Text.Split(new string[] { ", " }, StringSplitOptions.None);
             try
             {
                 for (int i = 0; i < strDataTemp.Length; i++)
@@ -2056,7 +2079,7 @@ namespace Welling_Motor_Debug_Tool
                         DataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
                         ConfigParam[2 * i + 2] = (byte)DataTemp;
                         ConfigParam[2 * i + 3] = (byte)(DataTemp >> 8);
-                    }                    
+                    }
                 }
                 mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x3B28, ConfigParam);
             }
@@ -2114,7 +2137,7 @@ namespace Welling_Motor_Debug_Tool
                     else
                     {
                         wDataTemp = Convert.ToInt16(strDataTemp[i].Split('=')[1]);
-                    }                    
+                    }
                     ConfigParam[2 * i + 2] = (byte)wDataTemp;
                     ConfigParam[2 * i + 3] = (byte)(wDataTemp >> 8);
                 }
@@ -2193,10 +2216,10 @@ namespace Welling_Motor_Debug_Tool
             catch (Exception)
             {
                 timer_1s.Enabled = false;
-                MessageBox.Show("请选择助力参数编号!","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
+                MessageBox.Show("请选择助力参数编号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 timer_1s.Enabled = true;
             }
-            
+
         }
 
         /// <summary>
@@ -2221,7 +2244,7 @@ namespace Welling_Motor_Debug_Tool
                     {
                         index_1 = i;
                         break;
-                    }                       
+                    }
                 }
                 for (int i = 0; i < strDataTemp.Length; i++)
                 {
@@ -2229,7 +2252,7 @@ namespace Welling_Motor_Debug_Tool
                     {
                         index_2 = i;
                         break;
-                    }                    
+                    }
                 }
                 for (int i = 0; i < strDataTemp.Length; i++)
                 {
@@ -2250,7 +2273,7 @@ namespace Welling_Motor_Debug_Tool
                     {
                         ConfigParam[2 * i + 20] = (byte)lDataTemp;
                         ConfigParam[2 * i + 21] = (byte)(lDataTemp >> 8);
-                    }  
+                    }
                 }
                 mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4450, ConfigParam);
             }
@@ -2602,7 +2625,7 @@ namespace Welling_Motor_Debug_Tool
             textBox_PP.Text = "---";
             mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x1F00, null);
         }
-        
+
         /// <summary>
         /// 写入生产信息
         /// </summary>
@@ -3070,7 +3093,7 @@ namespace Welling_Motor_Debug_Tool
             UserInfoCode[3] = (byte)(uint)numericUpDown_OBC_OffTime.Value;
             mySerialProcess.SendCmd((ushort)0x731, (byte)0x16, (ushort)0x3408, UserInfoCode);
         }
-        
+
         /// <summary>
         /// OBC查询电机版本信息
         /// </summary>
@@ -3244,7 +3267,7 @@ namespace Welling_Motor_Debug_Tool
             {
                 mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x4906, SaveFlag);
             }
-            timer_1s.Enabled = true;    
+            timer_1s.Enabled = true;
         }
 
         /// <summary>
@@ -3258,7 +3281,7 @@ namespace Welling_Motor_Debug_Tool
             UInt32 Address_Begin;
             UInt32 Addres_End;
 
-            if(checkBox_ReadRanFlash_AutoClear.Checked == true)
+            if (checkBox_ReadRanFlash_AutoClear.Checked == true)
                 richTextBox_RamFlasgData.Clear();
 
             if ((textBox_Address_Begin.Text == string.Empty) || (textBox_Address_End.Text == string.Empty))
@@ -3625,11 +3648,11 @@ namespace Welling_Motor_Debug_Tool
                 button_FacModeLightSW.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
             }
             else
-            { 
+            {
                 CtrlCode[1] = 0xF1;
                 button_FacModeLightSW.BackColor = Color.Yellow;
-            }             
-            if(mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
+            }
+            if (mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2802, CtrlCode))
             {
                 LightSwitchStatus = !LightSwitchStatus;
                 comboBox_LightSwitch.SelectedIndex = LightSwitchStatus ? 0 : 1;
@@ -3669,7 +3692,8 @@ namespace Welling_Motor_Debug_Tool
                 timer_1s.Enabled = true;
                 return;
             }
-            
+
+            //设置参数
             var ConfigParam = new byte[60];
             for (int i = 0; i < 60; i++)
                 ConfigParam[i] = 0;
@@ -3677,7 +3701,7 @@ namespace Welling_Motor_Debug_Tool
             ushort uwDataTemp = 0;
 
             if (!MotorRunStatus) //停止状态
-            { 
+            {
                 //设置速度环
                 if (radioButton_FacModeDriverCity.Checked | radioButton_FacModeDriverMtb.Checked | radioButton_FacModeDriverLG.Checked == true)
                 {
@@ -3741,7 +3765,7 @@ namespace Welling_Motor_Debug_Tool
                         ConfigParam[2 * i + 2] = (byte)uwDataTemp;
                         ConfigParam[2 * i + 3] = (byte)(uwDataTemp >> 8);
                     }
-                    if(!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
+                    if (!mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, ConfigParam))
                         return;
                 }
                 catch (Exception)
@@ -3765,33 +3789,8 @@ namespace Welling_Motor_Debug_Tool
             }
             else //运转状态
             {
-                //还原为原始值
-                if (radioButton_FacModeDriverCity.Checked == true)
-                {
-                    strDataTemp[0] = "整体运行模式=4";
-                    strDataTemp[1] = "位置获取模式=1";
-                    strDataTemp[10] = "转速环控制器带宽=5";
-                }
-                else if (radioButton_FacModeDriverMtb.Checked == true)
-                {
-                    strDataTemp[0] = "整体运行模式=5";
-                    strDataTemp[1] = "位置获取模式=1";
-                    strDataTemp[10] = "转速环控制器带宽=5";
-                }
-                else if (radioButton_FacModeDriverLG.Checked == true)
-                {
-                    strDataTemp[0] = "整体运行模式=6";
-                    strDataTemp[1] = "位置获取模式=2";
-                    strDataTemp[10] = "转速环控制器带宽=5";
-                }
-                else
-                {
-                    timer_1s.Enabled = false;
-                    MessageBox.Show("请选择电机类型!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
-                    timer_1s.Enabled = true;
-                    return;
-                }
-
+                //还原为原始值                
+                strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
                 try
                 {
                     for (int i = 0; i < strDataTemp.Length; i++)
@@ -3896,7 +3895,7 @@ namespace Welling_Motor_Debug_Tool
                 ConfigParam[14] = (byte)uwDataTemp;
                 ConfigParam[15] = (byte)(uwDataTemp >> 8);
                 //助力方案2
-                if(comboBox_FacModeAssist2.SelectedIndex == 0) uwDataTemp = 0;
+                if (comboBox_FacModeAssist2.SelectedIndex == 0) uwDataTemp = 0;
                 else if (comboBox_FacModeAssist2.SelectedIndex == 1) uwDataTemp = 341;
                 else if (comboBox_FacModeAssist2.SelectedIndex == 2) uwDataTemp = 682;
                 else
@@ -3909,7 +3908,7 @@ namespace Welling_Motor_Debug_Tool
                 ConfigParam[16] = (byte)uwDataTemp;
                 ConfigParam[17] = (byte)(uwDataTemp >> 8);
                 //灯压
-                if(comboBox_FacModeLightVol.SelectedIndex == 0) uwDataTemp = 6;
+                if (comboBox_FacModeLightVol.SelectedIndex == 0) uwDataTemp = 6;
                 else if (comboBox_FacModeLightVol.SelectedIndex == 1) uwDataTemp = 12;
                 else
                 {
@@ -3948,7 +3947,7 @@ namespace Welling_Motor_Debug_Tool
             textBox_FacModeStartGain.Text = "";
             textBox_FacModeCircuitK.Text = "";
             textBox_FacModeFltCounter.Text = "";
-            textBox_FacModeSpeedLimitTh.Text ="";
+            textBox_FacModeSpeedLimitTh.Text = "";
             textBox_FacModeSpeedLimitEnd.Text = "";
             textBox_FacModeCadencePer.Text = "";
             ConfigParam[0] = (byte)(1 & 0xFF);
@@ -4222,7 +4221,7 @@ namespace Welling_Motor_Debug_Tool
                     }
                 }
                 mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2420, MACArray);
-                
+
                 return;
             } while (false);
 
@@ -4386,7 +4385,7 @@ namespace Welling_Motor_Debug_Tool
                 }
 
                 //设置文件存储路径
-                string Save_Path = localInfo.LocalPath  + DateTime.Now.ToString("yyyy-MM-dd") + "\\"; ;
+                string Save_Path = localInfo.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))
@@ -4412,6 +4411,7 @@ namespace Welling_Motor_Debug_Tool
                 FileInfo += "硬件版本: " + textBox_HW.Text + "\r\n";
                 FileInfo += "软件版本: " + textBox_FW.Text + "\r\n";
                 FileInfo += "软件标识: " + textBox_SP.Text + "\r\n";
+                FileInfo += "Git信息: " + textBox_FacModeGit.Text + "\r\n";
                 FileInfo += "\r\n";
                 FileInfo += "[马达参数]\r\n";
                 FileInfo += richTextBox_MotorParam.Text + "\r\n";
@@ -4461,7 +4461,7 @@ namespace Welling_Motor_Debug_Tool
                 //数据上传
                 if (myFtp.IsNetConnected == true)
                 {
-                    string DataNow= DateTime.Now.ToString("yyyy-MM-dd");
+                    string DataNow = DateTime.Now.ToString("yyyy-MM-dd");
                     //检查路径
                     if (myFtp.DirectoryExist("\\", toolStripTextBox_ServerPath.Text) == false)
                     {
@@ -4868,7 +4868,7 @@ namespace Welling_Motor_Debug_Tool
         /// <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))
@@ -4884,7 +4884,7 @@ namespace Welling_Motor_Debug_Tool
         /// <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))
@@ -4925,7 +4925,7 @@ namespace Welling_Motor_Debug_Tool
             catch (Exception)
             {
                 MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
-            }            
+            }
         }
 
         /// <summary>
@@ -4959,7 +4959,7 @@ namespace Welling_Motor_Debug_Tool
             catch (Exception)
             {
                 MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
-            }            
+            }
         }
 
         /// <summary>
@@ -5100,7 +5100,7 @@ namespace Welling_Motor_Debug_Tool
                 MessageBox.Show("用户不存在或密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 允许ToolStripMenuItem.Checked = false;
                 不允许ToolStripMenuItem.Checked = true;
-            }           
+            }
         }
 
         /// <summary>
@@ -5143,8 +5143,12 @@ namespace Welling_Motor_Debug_Tool
                 }
                 else if (轮毂电机ToolStripMenuItem.Checked == true)
                 {
-                    regexInfo = @"\s{2}";
-                    InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
+                    InfoList = ScanInfo.Split(new string[] { "  " }, StringSplitOptions.None);
+                    string Model = InfoList[0];
+                    string Spec = InfoList[1];
+                    string Sn = InfoList[2];
+                    InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
+                    InfoList[1] = Sn;
                 }
                 if (InfoList.Length >= 2)
                 {
@@ -5182,7 +5186,7 @@ namespace Welling_Motor_Debug_Tool
                             SNArray[SN.Length + 1 + i] = 0x20;
                         }
                     }
-                    mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);                   
+                    mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
                 }
                 else
                 {
@@ -5337,7 +5341,7 @@ namespace Welling_Motor_Debug_Tool
                 {
                     comboBox_FacModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
                     comboBox_CheckModeCfgDate.Items.Add(file.Substring(file.LastIndexOf("\\") + 1));
-                } 
+                }
             }
             else
             {
@@ -5352,7 +5356,7 @@ namespace Welling_Motor_Debug_Tool
                 {
                     comboBox_FacModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
                     comboBox_CheckModeCfgDate.Items.Add(DateList[i].Substring(DateList[i].LastIndexOf("\\") + 1));
-                } 
+                }
             }
         }
 
@@ -5449,12 +5453,20 @@ namespace Welling_Motor_Debug_Tool
         {
             //初始化标签
             FacModelLabelInit();
+            richTextBox_FacModeLog.Clear();
+
             //检查打标信息格式
-            //...
-            //检查配置文件是否与打标信息一致
-            //...
+            label_FacModeSatus.Text = "检查扫码信息";
+            richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "检查扫码信息" + "\r\n");
+            if (textBox_FacModeScan.Text == string.Empty)
+            {
+                MessageBox.Show("请扫码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                return;
+            }
+
             //流水号计数
             //...
+
             //创建线程,执行测试任务
             Thread th = new Thread(FacModeTest_Task);
             th.Start();
@@ -5494,14 +5506,63 @@ namespace Welling_Motor_Debug_Tool
             //系统清除
             if (checkBox_FacModeSysClear.Checked)
             {
-                //发送系统清除指令
-                //...
-                //等待系统清除完成指令
-                //...
-                //系统重新开机
-                //...
-                //等待开机,根据Boot版本信息判断
-                //...
+                do
+                {
+                    //发送系统清除指令    
+                    label_FacModeSatus.Text = "系统清除!";
+                    richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除" + "\r\n");
+                    Code[0] = (byte)'C';
+                    Code[1] = (byte)'L';
+                    Code[2] = (byte)'E';
+                    Code[3] = (byte)'A';
+                    Code[4] = (byte)'R';
+
+                    WriteACK = false;
+                    WriteCnt = 0;
+                    mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2605, Code);
+                    Delay_ms(1000);
+
+                    //等待系统清除完成指令
+                    if (WriteACK == true)
+                    {
+                        richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "系统清除成功" + "\r\n");
+                    }
+                    else
+                    {
+                        label_FacModeSatus.Text = "存在故障!";
+                        label_FacModeResult.BackColor = Color.Red;
+                        label_FacModeResult.Text = "测试异常";
+                        Delay_ms(500);
+                        //存储异常并上传
+                        //...
+                        return;
+                    }
+
+                    //系统重新开机
+                    BootInfo = "";
+                    Code[0] = 0xF0;
+                    mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
+                    Delay_ms(1000);
+                    Code[0] = 0xF1;
+                    mySerialProcess.SendCmd(0x7FF, 0x16, 0x2201, Code);
+                    Delay_ms(2000);
+
+                    //获取Boot版本信息
+                    if (BootInfo != string.Empty)
+                    {
+                        richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "Boot版本:" + BootInfo + "\r\n");
+                    }
+                    else
+                    {
+                        label_FacModeSatus.Text = "存在故障!";
+                        label_FacModeResult.BackColor = Color.Red;
+                        label_FacModeResult.Text = "测试异常";
+                        Delay_ms(500);
+                        //存储异常并上传
+                        //...
+                        return;
+                    }
+                } while (false);
             }
             else
             {
@@ -5514,12 +5575,115 @@ namespace Welling_Motor_Debug_Tool
             //参数写入
             if (checkBox_FacModeCfgWrite.Checked)
             {
-                //写入产品型号
-                //...
-                //写入产品SN
-                //..
+                //写入产品型号和SN
+                do
+                {
+                    string ScanInfo = textBox_FacModeScan.Text;
+                    string regexInfo = "";
+                    string[] InfoList = { "" };
+                    if (中置电机ToolStripMenuItem.Checked == true)
+                    {
+                        regexInfo = @"[0-9][0-9][V][0-9][0-9][0-9][W]";
+                        InfoList = Regex.Split(ScanInfo, regexInfo, RegexOptions.IgnoreCase);
+                    }
+                    else if (轮毂电机ToolStripMenuItem.Checked == true)
+                    {
+                        InfoList = ScanInfo.Split(new string[] { "  " }, StringSplitOptions.None);
+                        string Model = InfoList[0];
+                        string Spec = InfoList[1];
+                        string Sn = InfoList[2];
+                        InfoList[0] = Model.Replace("-", "").Substring(2, 12) + Spec.Substring(Spec.Length - 4);
+                        InfoList[1] = Sn;
+                    }
+                    if (InfoList.Length >= 2)
+                    {
+                        //检查配置文件是否与打标信息一致
+                        //...
+
+                        //写入型号
+                        label_FacModeSatus.Text = "写入型号";
+                        richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入型号" + "\r\n");
+                        textBox_FacModeName.Text = InfoList[0];
+                        string Mode = textBox_FacModeName.Text;
+                        var ModeArray = new byte[16];
+                        for (ushort i = 0; i < Mode.Length; i++)
+                        {
+                            ModeArray[i] = (byte)Mode[i];
+                        }
+                        if (Mode.Length < 16)
+                        {
+                            ModeArray[Mode.Length] = (byte)'.';
+                            for (ushort i = 0; i < 16 - Mode.Length - 1; i++)
+                            {
+                                ModeArray[Mode.Length + 1 + i] = 0x20;
+                            }
+                        }
+                        WriteACK = false;
+                        WriteCnt = 0;
+                        mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2210, ModeArray);
+                        Delay_ms(500);
+                        if (WriteACK == true)
+                        {
+                            richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "型号写入成功" + "\r\n");
+                        }
+                        else
+                        {
+                            label_FacModeSatus.Text = "存在故障!";
+                            label_FacModeResult.BackColor = Color.Red;
+                            label_FacModeResult.Text = "测试异常";
+                            Delay_ms(500);
+                            //存储异常并上传
+                            //...
+                            return;
+                        }
+
+                        //写入SN                    
+                        label_FacModeSatus.Text = "写入SN";
+                        richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "写入SN" + "\r\n");
+                        textBox_FacModeNum.Text = InfoList[1];
+                        string SN = textBox_FacModeNum.Text;
+                        var SNArray = new byte[16];
+                        for (ushort i = 0; i < SN.Length; i++)
+                        {
+                            SNArray[i] = (byte)SN[i];
+                        }
+                        if (SN.Length < 16)
+                        {
+                            SNArray[SN.Length] = (byte)'.';
+                            for (ushort i = 0; i < 16 - SN.Length - 1; i++)
+                            {
+                                SNArray[SN.Length + 1 + i] = 0x20;
+                            }
+                        }
+                        WriteACK = false;
+                        WriteCnt = 0;
+                        mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x2310, SNArray);
+                        Delay_ms(500);
+                        if (WriteACK == true)
+                        {
+                            richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "SN写入成功" + "\r\n");
+                        }
+                        else
+                        {
+                            label_FacModeSatus.Text = "存在故障!";
+                            label_FacModeResult.BackColor = Color.Red;
+                            label_FacModeResult.Text = "测试异常";
+                            Delay_ms(500);
+                            //存储异常并上传
+                            //...
+                            return;
+                        }
+                    }
+                    else
+                    {
+                        MessageBox.Show("格式错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
+                        return;
+                    }
+                } while (false);
+
                 //写入配置文件
                 //...
+
                 //判断反馈是否完整
                 //...
             }
@@ -5557,21 +5721,147 @@ namespace Welling_Motor_Debug_Tool
             if (checkBox_FacBaseFucTest.Checked)
             {
                 //发送指令进入配置模式
-                //...
+                do
+                {
+                    Code[0] = 0x01;
+                    mySerialProcess.SendCmdWithoutNotice((ushort)0x751, (byte)0x16, (ushort)0x1901, Code);
+                    Delay_ms(500);
+                    if (textBox_RunInfo_Vol.Text != "---")
+                    {
+                        richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "进入配置模式" + "\r\n");
+                    }
+                    else
+                    {
+                        label_FacModeSatus.Text = "存在故障!";
+                        label_FacModeResult.BackColor = Color.Red;
+                        label_FacModeResult.Text = "测试异常";
+                        Delay_ms(500);
+                        //存储异常并上传
+                        //...
+                        return;
+                    }
+                } while (false);
+
                 //发送指令启动电机
-                //...
+                do
+                {
+                    //发送指令读取调试信息
+                    richTextBox_DebugParam.Clear();
+                    mySerialProcess.SendCmd((ushort)0x751, (byte)0x11, (ushort)0x4500, null);
+                    Delay_ms(500);
+                    //获取调试信息
+                    string DebugDefaultInfo = "";
+                    if (richTextBox_DebugParam.Text == string.Empty)
+                    {
+                        label_FacModeSatus.Text = "存在故障!";
+                        label_FacModeResult.BackColor = Color.Red;
+                        label_FacModeResult.Text = "测试异常";
+                        Delay_ms(500);
+                        //存储异常并上传
+                        //...
+                        return;
+                    }
+                    else
+                    {
+                        DebugDefaultInfo = richTextBox_DebugParam.Text;
+                    }
+                    //设置模式
+                    string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
+                    strDataTemp[0] = "整体运行模式=3";
+                    //发送数据
+                    Code[0] = 0;
+                    Code[1] = 0;
+                    for (int i = 0; i < strDataTemp.Length; i++)
+                    {
+                        ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
+                        Code[2 * i + 2] = (byte)uwDataTemp;
+                        Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
+                    }
+                    mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
+                    label_FacModeSatus.Text = "启动电机";
+                    richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "启动电机" + "\r\n");
+                    Delay_ms(1000);
+                } while (false);
+
                 //判断车速
-                //...
+                if (Convert.ToDouble(textBox_RunInfo_BikeSpeed.Text.Split(' ')[0]) != 0)
+                {
+                    label_FacModeSpeed.BackColor = Color.Green;
+                    richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "车速传感器正常" + "\r\n");
+                }
+                else
+                {
+                    label_FacModeSatus.Text = "存在故障!";
+                    label_FacModeResult.BackColor = Color.Red;
+                    label_FacModeResult.Text = "测试异常";
+                    Delay_ms(500);
+                    //存储异常并上传
+                    //...
+                    return;
+                }
+
                 //判断电压
-                //...
+                if (((Convert.ToInt32(textBox_RunInfo_Vol.Text.Split(' ')[0]) > 35000) || (Convert.ToInt32(textBox_RunInfo_Vol.Text.Split(' ')[0]) < 37000)) ||
+                    ((Convert.ToInt32(textBox_RunInfo_Vol.Text.Split(' ')[0]) > 47000) || (Convert.ToInt32(textBox_RunInfo_Vol.Text.Split(' ')[0]) < 49000)))
+                {
+                    label_FacModeVolTest.BackColor = Color.Green;
+                    richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "电压正常" + "\r\n");
+                }
+                else
+                {
+                    label_FacModeSatus.Text = "存在故障!";
+                    label_FacModeResult.BackColor = Color.Red;
+                    label_FacModeResult.Text = "测试异常";
+                    Delay_ms(500);
+                    //存储异常并上传
+                    //...
+                    return;
+                }
+
                 //判断电流
                 //...
+
                 //判断转速
                 //...
+
                 //判断温度
                 //...
+
                 //发送指令停止电机
-                //...
+                do
+                {
+                    //获取调试信息
+                    string DebugDefaultInfo = "";
+                    if (richTextBox_DebugParam.Text == string.Empty)
+                    {
+                        label_FacModeSatus.Text = "存在故障!";
+                        label_FacModeResult.BackColor = Color.Red;
+                        label_FacModeResult.Text = "测试异常";
+                        Delay_ms(500);
+                        //存储异常并上传
+                        //...
+                        return;
+                    }
+                    else
+                    {
+                        DebugDefaultInfo = richTextBox_DebugParam.Text;
+                    }
+                    //设置模式
+                    string[] strDataTemp = DebugDefaultInfo.Split(new string[] { ", " }, StringSplitOptions.None);
+                    //发送数据
+                    Code[0] = 0;
+                    Code[1] = 0;
+                    for (int i = 0; i < strDataTemp.Length; i++)
+                    {
+                        ushort uwDataTemp = Convert.ToUInt16(strDataTemp[i].Split('=')[1]);
+                        Code[2 * i + 2] = (byte)uwDataTemp;
+                        Code[2 * i + 3] = (byte)(uwDataTemp >> 8);
+                    }
+                    mySerialProcess.SendCmd((ushort)0x751, (byte)0x16, (ushort)0x463C, Code);
+                    label_FacModeSatus.Text = "停止电机";
+                    richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "停止电机" + "\r\n");
+                    Delay_ms(1000);
+                } while (false);
             }
             else
             {
@@ -5618,7 +5908,7 @@ namespace Welling_Motor_Debug_Tool
             }
             else
             {
-                label_FacModeGas.BackColor = Color.Yellow;                
+                label_FacModeGas.BackColor = Color.Yellow;
                 label_FacModeSatus.Text = "跳过转把检测!";
                 richTextBox_FacModeLog.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "->" + "跳过转把检测" + "\r\n");
                 Delay_ms(500);
@@ -5695,13 +5985,15 @@ namespace Welling_Motor_Debug_Tool
             //测试结果标签
             foreach (Control c in groupBox28.Controls)
             {
-                if ((c is Label))
+                if (c is Label)
                 {
-                    c.BackColor = Color.Red;
+                    if (c.Text != string.Empty)
+                        c.BackColor = Color.Red;
                 }
             }
         }
 
 
 
-    }
+    }
+}

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