Form1.cs 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Runtime.InteropServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. /*------------兼容ZLG的数据类型---------------------------------*/
  12. //1.ZLGCAN系列接口卡信息的数据类型。
  13. public struct VCI_BOARD_INFO
  14. {
  15. public UInt16 hw_Version;
  16. public UInt16 fw_Version;
  17. public UInt16 dr_Version;
  18. public UInt16 in_Version;
  19. public UInt16 irq_Num;
  20. public byte can_Num;
  21. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
  22. public byte[] str_Serial_Num;
  23. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)]
  24. public byte[] str_hw_Type;
  25. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
  26. public byte[] Reserved;
  27. }
  28. /////////////////////////////////////////////////////
  29. //2.定义CAN信息帧的数据类型。
  30. unsafe public struct VCI_CAN_OBJ //使用不安全代码
  31. {
  32. public uint ID;
  33. public uint TimeStamp; //时间标识
  34. public byte TimeFlag; //是否使用时间标识
  35. public byte SendType; //发送标志。保留,未用
  36. public byte RemoteFlag; //是否是远程帧
  37. public byte ExternFlag; //是否是扩展帧
  38. public byte DataLen; //数据长度
  39. public fixed byte Data[8]; //数据
  40. public fixed byte Reserved[3];//保留位
  41. }
  42. //3.定义初始化CAN的数据类型
  43. public struct VCI_INIT_CONFIG
  44. {
  45. public UInt32 AccCode;
  46. public UInt32 AccMask;
  47. public UInt32 Reserved;
  48. public byte Filter; //0或1接收所有帧。2标准帧滤波,3是扩展帧滤波。
  49. public byte Timing0; //波特率参数,具体配置,请查看二次开发库函数说明书。
  50. public byte Timing1;
  51. public byte Mode; //模式,0表示正常模式,1表示只听模式,2自测模式
  52. }
  53. /*------------其他数据结构描述---------------------------------*/
  54. //4.USB-CAN总线适配器板卡信息的数据类型1,该类型为VCI_FindUsbDevice函数的返回参数。
  55. public struct VCI_BOARD_INFO1
  56. {
  57. public UInt16 hw_Version;
  58. public UInt16 fw_Version;
  59. public UInt16 dr_Version;
  60. public UInt16 in_Version;
  61. public UInt16 irq_Num;
  62. public byte can_Num;
  63. public byte Reserved;
  64. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
  65. public byte[] str_Serial_Num;
  66. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
  67. public byte[] str_hw_Type;
  68. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 16)]
  69. public byte[] str_Usb_Serial;
  70. }
  71. public struct CHGDESIPANDPORT
  72. {
  73. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
  74. public byte[] szpwd;
  75. [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
  76. public byte[] szdesip;
  77. public Int32 desport;
  78. public void Init()
  79. {
  80. szpwd = new byte[10];
  81. szdesip = new byte[20];
  82. }
  83. }
  84. public unsafe struct UdsAppMsgInfo
  85. {
  86. public UInt32 xUdsId;
  87. public UInt32 xDataLen;
  88. public byte xUdsRequest;
  89. public fixed byte aDataBuf[150];
  90. }
  91. public unsafe struct UdsAppResponseInfo
  92. {
  93. public bool isPositiveResponse;
  94. public byte responseDataLength;
  95. public fixed byte responseData[100];
  96. }
  97. public struct UdsDID
  98. {
  99. public byte DID_High;
  100. public byte DID_Low;
  101. }
  102. public struct UdsDIDList
  103. {
  104. public UdsDID fingerPrint;
  105. public UdsDID eraseFlash;
  106. public UdsDID checkProgramIndependence;
  107. public UdsDID checkCRCofBlock;
  108. }
  109. public struct FileDownloadDataType
  110. {
  111. public bool isDownloadFlag;
  112. public UInt32 memoryStartAddr;
  113. public UInt32 memorySize;
  114. public UInt16 fileBlockCRC16;
  115. public byte[] fileDownloadDataBuff;
  116. }
  117. namespace WindowsFormsApplication1
  118. {
  119. public partial class Form1 : Form
  120. {
  121. const int DEV_USBCAN = 3;
  122. const int DEV_USBCAN2 = 4;
  123. UInt32 receCount = new UInt32();
  124. /// <summary>
  125. ///
  126. /// </summary>
  127. /// <param name="DeviceType"></param>
  128. /// <param name="DeviceInd"></param>
  129. /// <param name="Reserved"></param>
  130. /// <returns></returns>
  131. /*------------兼容ZLG的函数描述---------------------------------*/
  132. [DllImport("controlcan.dll")]
  133. static extern UInt32 VCI_OpenDevice(UInt32 DeviceType, UInt32 DeviceInd, UInt32 Reserved);
  134. [DllImport("controlcan.dll")]
  135. static extern UInt32 VCI_CloseDevice(UInt32 DeviceType, UInt32 DeviceInd);
  136. [DllImport("controlcan.dll")]
  137. static extern UInt32 VCI_InitCAN(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_INIT_CONFIG pInitConfig);
  138. [DllImport("controlcan.dll")]
  139. static extern UInt32 VCI_ReadBoardInfo(UInt32 DeviceType, UInt32 DeviceInd, ref VCI_BOARD_INFO pInfo);
  140. [DllImport("controlcan.dll")]
  141. static extern UInt32 VCI_GetReceiveNum(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd);
  142. [DllImport("controlcan.dll")]
  143. static extern UInt32 VCI_ClearBuffer(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd);
  144. [DllImport("controlcan.dll")]
  145. static extern UInt32 VCI_StartCAN(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd);
  146. [DllImport("controlcan.dll")]
  147. static extern UInt32 VCI_ResetCAN(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd);
  148. [DllImport("controlcan.dll")]
  149. static extern UInt32 VCI_Transmit(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_CAN_OBJ pSend, UInt32 Len);
  150. [DllImport("controlcan.dll")]
  151. static extern UInt32 VCI_Receive(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_CAN_OBJ pReceive, UInt32 Len, Int32 WaitTime);
  152. /*------------其他函数描述---------------------------------*/
  153. [DllImport("controlcan.dll")]
  154. static extern UInt32 VCI_ConnectDevice(UInt32 DevType, UInt32 DevIndex);
  155. [DllImport("controlcan.dll")]
  156. static extern UInt32 VCI_UsbDeviceReset(UInt32 DevType, UInt32 DevIndex, UInt32 Reserved);
  157. [DllImport("controlcan.dll")]
  158. static extern UInt32 VCI_FindUsbDevice(ref VCI_BOARD_INFO1 pInfo);
  159. private delegate void CrossThreadOperationControl();
  160. /*------------函数描述结束---------------------------------*/
  161. /*------------全局变量声明---------------------------------*/
  162. //private float X;//当前窗体的宽度
  163. //private float Y;//当前窗体的高度
  164. //private bool IsFirst = true;
  165. bool isForm1Colsed = false;
  166. byte controllerChooseFlag = 0xFF;
  167. static UInt32 m_devtype = 4;//USBCAN2
  168. UInt32 m_devind = 0;
  169. UInt32 m_canind = 0;
  170. UInt32[] m_arrdevtype = new UInt32[20];
  171. bool UpdateServiceSwitch = false;
  172. VCI_CAN_OBJ[] receobj = new VCI_CAN_OBJ[20];
  173. bool buttStartCan = false;
  174. bool buttStartDownload = false;
  175. public Form1()
  176. {
  177. InitializeComponent();
  178. }
  179. private void button1_Click(object sender, EventArgs e)
  180. {
  181. }
  182. private void Form1_Load(object sender, EventArgs e)
  183. {
  184. Int32 curindex = 0;
  185. comboBox_devtype.Items.Clear();
  186. curindex = comboBox_devtype.Items.Add("DEV_USBCAN");
  187. m_arrdevtype[curindex] = DEV_USBCAN;
  188. //comboBox_devtype.Items[2] = "VCI_USBCAN1";
  189. //m_arrdevtype[2]= VCI_USBCAN1 ;
  190. curindex = comboBox_devtype.Items.Add("DEV_USBCAN2");
  191. m_arrdevtype[curindex] = DEV_USBCAN2;
  192. //comboBox_devtype.Items[3] = "VCI_USBCAN2";
  193. //m_arrdevtype[3]= VCI_USBCAN2 ;
  194. comboBox_BoardIndex.SelectedIndex = 0;
  195. comboBox_CANIndex.SelectedIndex = 0;
  196. comboBox_DeviceIndex.SelectedIndex = 0;
  197. comboBox_CANIndex.SelectedIndex = 0;
  198. comboBox_MsgType.SelectedIndex = 0;
  199. comboBox_VCU_BMSHVOnOffReq.SelectedIndex = 0;
  200. comboBox_VCU_AllowChgCtrl.SelectedIndex = 0;
  201. comboBox_VCU_BMSCutOffLV.SelectedIndex = 0;
  202. comboBox_LockingPinStsFB.SelectedIndex = 0;
  203. comboBox_Change_BattConSts.SelectedIndex = 0;
  204. comboBox_BTMS_WorkSts.SelectedIndex = 0;
  205. comboBox_BTMS_ConnStsFb.SelectedIndex = 0;
  206. comboBox_BTMS_FltLevel.SelectedIndex = 0;
  207. comboBox_encryptionEnable.SelectedIndex = 0;
  208. //comboBox_ControllerChoose.SelectedIndex = 0x00;
  209. //comboBox_MsgType.SelectedIndex = 0x01;
  210. //canMsgType = (byte)(comboBox_MsgType.SelectedIndex);
  211. //controllerChooseFlag = (byte)(comboBox_ControllerChoose.SelectedIndex + 1);
  212. //
  213. TextBox[] test = new TextBox[10];
  214. for (int i = 0; i < 10; i++)
  215. {
  216. //test.Size = new System.Drawing.Size(400, 300);
  217. test[i] = new TextBox();
  218. test[i].Text = "标题" + i.ToString();//设置文本,i的值转成字符串与标题相加
  219. test[i].Parent = flowLayoutPanel_1;
  220. }
  221. comboBox_devtype.SelectedIndex = 1;
  222. comboBox_devtype.MaxDropDownItems = comboBox_devtype.Items.Count;
  223. setBoxAndButtonEnalbe(true);
  224. isForm1Colsed = false;
  225. }
  226. private void setBoxAndButtonEnalbe(bool trueOrfalse)
  227. {
  228. comboBox_CANIndex.Enabled = trueOrfalse;
  229. comboBox_devtype.Enabled = trueOrfalse;
  230. comboBox_BoardIndex.Enabled = trueOrfalse;
  231. comboBox_DeviceIndex.Enabled = trueOrfalse;
  232. }
  233. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  234. {
  235. if (buttStartCan == true)
  236. {
  237. //VCI_CloseDevice(m_devtype, m_devind);
  238. }
  239. //autoSaveFile();
  240. //UpdateStep = 0xFF;
  241. isForm1Colsed = true;
  242. //setBoxAndButtonEnalbe(false);
  243. }
  244. private void button_StartCAN_Click(object sender, EventArgs e)
  245. {
  246. if (buttStartCan == true)
  247. {
  248. buttStartCan = false;
  249. }
  250. else
  251. {
  252. m_devtype = m_arrdevtype[comboBox_devtype.SelectedIndex];
  253. m_devind = 0;
  254. m_canind = (UInt32)comboBox_CANIndex.SelectedIndex;
  255. m_devind = (UInt32)comboBox_DeviceIndex.SelectedIndex;
  256. if (VCI_OpenDevice(m_devtype, m_devind, 0) == 0)
  257. {
  258. MessageBox.Show("打开设备失败,请检查设备类型和设备索引号是否正确", "错误",
  259. MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  260. return;
  261. }
  262. buttStartCan = true;
  263. VCI_INIT_CONFIG config = new VCI_INIT_CONFIG();
  264. if (comboBox_MsgType.Text == "标准帧")
  265. {
  266. config.AccCode = 0;
  267. config.AccMask = 0xffffffff;
  268. //config.AccCode = Convert.ToUInt32(textBox_responseAddr.Text, 16) << 21;
  269. //config.AccMask = 0x1FFFFF;
  270. config.Filter = 0x02;//只接收符合要求的标准帧
  271. //0或1接收所有帧。2标准帧滤波,3是扩展帧滤波。
  272. }
  273. else if (comboBox_MsgType.Text == "扩展帧")
  274. {
  275. config.AccCode = 0;
  276. config.AccMask = 0xffffffff;
  277. //config.AccCode = Convert.ToUInt32(textBox_responseAddr.Text, 16) << 3;
  278. //config.AccMask = 0x07;
  279. config.Filter = 0x03;//只接收符合要求的扩展帧
  280. }
  281. //波特率设置为250K
  282. switch (comboBox_BoardIndex.Text)
  283. {
  284. case "250K":
  285. config.Timing0 = 0x01;
  286. config.Timing1 = 0x1C;
  287. break;
  288. case "500K":
  289. config.Timing0 = 0x00;
  290. config.Timing1 = 0x1C;
  291. break;
  292. default: //250K
  293. config.Timing0 = 0x01;
  294. config.Timing1 = 0x1C;
  295. break;
  296. }
  297. //config.Filter = 0x00;//接收所有报文
  298. config.Mode = (Byte)0x00; //正常工作模式
  299. VCI_InitCAN(m_devtype, m_devind, m_canind, ref config);
  300. }
  301. button_StartCAN.Text = buttStartCan == true ? "停止CAN" : "启动CAN";
  302. button_StartCAN.BackColor = buttStartCan == true ? Color.GreenYellow : SystemColors.Control;
  303. if (buttStartCan == false)
  304. {
  305. VCI_ResetCAN(m_devtype, m_devind, m_canind);
  306. comboBox_devtype.Enabled = true;
  307. comboBox_CANIndex.Enabled = true;
  308. comboBox_DeviceIndex.Enabled = true;
  309. comboBox_BoardIndex.Enabled = true;
  310. comboBox_MsgType.Enabled = true;
  311. timer_rec.Enabled = false;
  312. timer_send.Enabled = false;
  313. //comboBox_ControllerChoose.Enabled = true;
  314. return;
  315. }
  316. VCI_StartCAN(m_devtype, m_devind, m_canind);
  317. comboBox_devtype.Enabled = false;
  318. comboBox_CANIndex.Enabled = false;
  319. comboBox_DeviceIndex.Enabled = false;
  320. comboBox_BoardIndex.Enabled = false;
  321. comboBox_MsgType.Enabled = false;
  322. timer_rec.Interval = 10;
  323. timer_send.Interval = 100;
  324. timer_rec.Enabled = true;
  325. timer_send.Enabled = true;
  326. //comboBox_ControllerChoose.Enabled = false;
  327. }
  328. private void timer_rec_Tick(object sender, EventArgs e)
  329. {
  330. if (receCount == 0)
  331. {
  332. uint res = VCI_GetReceiveNum(m_devtype, m_devind, m_canind);
  333. if (res > 0)
  334. {
  335. receobj = new VCI_CAN_OBJ[20];
  336. receCount = 0;
  337. receCount = VCI_Receive(m_devtype, m_devind, m_canind, ref receobj[0], 15, 0);
  338. if (receCount == 0xFFFFFFFF)
  339. {
  340. receCount = 0;
  341. }
  342. for (int i = 0; i < receCount; i++)
  343. {
  344. //strCanMsg += CANMsgRecord(receobj[i], "rx");
  345. byte[] tmp = new byte[8];
  346. CANRec(receobj[i].ID, receobj[i]);
  347. }
  348. receCount = 0;
  349. }
  350. else
  351. {
  352. }
  353. }
  354. }
  355. private void timer_send_Tick(object sender, EventArgs e)
  356. {
  357. VCI_CAN_OBJ sendObj = new VCI_CAN_OBJ();
  358. CANTx(0x1802F3D0, sendObj);
  359. CANTx(0x18F5C13A, sendObj);
  360. CANTx(0x18FF42D8, sendObj);
  361. CANTx(0x18FFCBF3, sendObj);
  362. CANTx(0x18FFF8A7, sendObj);
  363. }
  364. void CANTx(UInt32 ID, VCI_CAN_OBJ sendObj)
  365. {
  366. sendObj.ID = ID;
  367. sendObj.ExternFlag = 0X01;
  368. sendObj.DataLen = 0x08;
  369. unsafe
  370. {
  371. for (int i = 0; i < 8; i++)
  372. {
  373. sendObj.Data[i] = 0;
  374. }
  375. switch (ID)
  376. {
  377. //vcu
  378. case 0x1802F3D0:
  379. int VCU_V2B_CMD_Checksum = 0;
  380. int VCU_BMSHVOnOffReq = 0;
  381. int VCU_VehSpd = 0;
  382. int VCU_BMSCutOffLV = 0;
  383. int VCU_AllowChgCtrl = 0;
  384. if (VCU_V2B_CMD_AliveConter++ > 15)
  385. VCU_V2B_CMD_AliveConter = 0;
  386. VCU_BMSHVOnOffReq = comboBox_VCU_BMSHVOnOffReq.SelectedIndex;
  387. sendObj.Data[1] = (byte)((((VCU_V2B_CMD_AliveConter >> 0) & 0xF) << 0) | (((VCU_BMSHVOnOffReq >> 0) & 0x3) << 4));
  388. VCU_VehSpd = Convert.ToInt32(numericUpDown_VCU_VehSpd.Value);
  389. sendObj.Data[2] = (byte)(((VCU_VehSpd >> 0) & 0xFF) << 0);
  390. VCU_AllowChgCtrl = comboBox_VCU_AllowChgCtrl.SelectedIndex;
  391. VCU_BMSCutOffLV = comboBox_VCU_BMSCutOffLV.SelectedIndex;
  392. sendObj.Data[7] = (byte)((((VCU_BMSCutOffLV >> 0) & 0x1) << 0) | ((VCU_AllowChgCtrl >> 0) & 0x3) << 1);
  393. for (int i = 1; i < 8; i++)
  394. {
  395. VCU_V2B_CMD_Checksum ^= sendObj.Data[1];
  396. }
  397. sendObj.Data[0] = (byte)(((VCU_V2B_CMD_Checksum >> 0) & 0xFF) << 0);
  398. break;
  399. //tms
  400. case 0x18F5C13A:
  401. int BTMS_WorkSts = 0;
  402. int BTMS_ConnStsFb = 0;
  403. int BTMS_BattPackInCoolTemp = 0;
  404. int BTMS_BattPackoutCoolTemp = 0;
  405. int BTMS_ActPower = 0;
  406. int BTMS_DTC = 0;
  407. int BTMS_FltLevel = 0;
  408. BTMS_WorkSts = comboBox_BTMS_WorkSts.SelectedIndex;
  409. BTMS_ConnStsFb = comboBox_BTMS_ConnStsFb.SelectedIndex;
  410. BTMS_BattPackInCoolTemp = Convert.ToByte(numericUpDown_BTMS_BattPackInCoolTemp.Value + 40);
  411. BTMS_BattPackoutCoolTemp = Convert.ToByte(numericUpDown_BTMS_BattPackoutCoolTemp.Value + 40);
  412. BTMS_ActPower = Convert.ToInt32(numericUpDown_BTMS_ActPower.Value * 10);
  413. BTMS_DTC = Convert.ToByte(numericUpDown_BTMS_DTC.Value);
  414. BTMS_FltLevel = comboBox_BTMS_FltLevel.SelectedIndex;
  415. sendObj.Data[0] = (byte)((((BTMS_WorkSts >> 0) & 0x3) << 0) | (((BTMS_ConnStsFb >> 0) & 0xF) << 2));
  416. sendObj.Data[1] = (byte)(((BTMS_BattPackInCoolTemp >> 0) & 0xFF) << 0);
  417. sendObj.Data[2] = (byte)(((BTMS_BattPackoutCoolTemp >> 0) & 0xFF) << 0);
  418. sendObj.Data[5] = (byte)(((BTMS_ActPower >> 0) & 0xFF) << 0);
  419. sendObj.Data[6] = (byte)(((BTMS_ActPower >> 8) & 0xFF) << 0);
  420. sendObj.Data[7] = (byte)((((BTMS_DTC >> 0) & 0x3F) << 0) | (((BTMS_FltLevel >> 0) & 0x3) << 6));
  421. break;
  422. case 0x18FF42D8:
  423. /*
  424. sendObj.Data[0] = (byte)(((TBOX_Second >> 0) & 0xFF) << 0);
  425. sendObj.Data[1] = (byte)(((TBOX_Minute >> 0) & 0xFF) << 0);
  426. sendObj.Data[2] = (byte)(((TBOX_Hour >> 0) & 0xFF) << 0);
  427. sendObj.Data[3] = (byte)(((TBOX_Day >> 0) & 0xFF) << 0);
  428. sendObj.Data[4] = (byte)(((TBOX_Month >> 0) & 0xFF) << 0);
  429. sendObj.Data[5] = (byte)(((TBOX_Year >> 0) & 0xFF) << 0);*/
  430. break;
  431. //rcb
  432. case 0x18FFCBF3:
  433. int RCB_encryp1 = 0;
  434. int RCB_encryp2 = 0;
  435. int RCB_encryp3 = 0;
  436. int RCB_encryp4 = 0;
  437. sendObj.Data[0] = (byte)(((RCB_encryp1 >> 0) & 0xFF) << 0);
  438. sendObj.Data[1] = (byte)(((RCB_encryp1 >> 8) & 0xFF) << 0);
  439. sendObj.Data[2] = (byte)(((RCB_encryp2 >> 0) & 0xFF) << 0);
  440. sendObj.Data[3] = (byte)(((RCB_encryp2 >> 8) & 0xFF) << 0);
  441. sendObj.Data[4] = (byte)(((RCB_encryp3 >> 0) & 0xFF) << 0);
  442. sendObj.Data[5] = (byte)(((RCB_encryp3 >> 8) & 0xFF) << 0);
  443. sendObj.Data[6] = (byte)(((RCB_encryp4 >> 0) & 0xFF) << 0);
  444. sendObj.Data[7] = (byte)(((RCB_encryp4 >> 8) & 0xFF) << 0);
  445. break;
  446. //EBC
  447. case 0x18FFF8A7:
  448. int LockingPinStsFB = 0;
  449. int Change_BattConSts = 0;
  450. int Message_Checksum = 0;
  451. if (Message_Counter++ > 15)
  452. Message_Counter = 0;
  453. Message_Checksum = Message_Counter;
  454. LockingPinStsFB = comboBox_LockingPinStsFB.SelectedIndex = 0;
  455. Change_BattConSts = comboBox_Change_BattConSts.SelectedIndex;
  456. sendObj.Data[1] = (byte)((((LockingPinStsFB >> 0) & 0x3) << 0) | (((Change_BattConSts >> 0) & 0x3) << 2));
  457. sendObj.Data[7] = (byte)((((Message_Counter >> 0) & 0xF) << 0) | (((Message_Checksum >> 0) & 0xF) << 4));
  458. break;
  459. default:
  460. break;
  461. }
  462. VCI_Transmit(m_devtype, m_devind, m_canind, ref sendObj, 1);
  463. }
  464. }
  465. void CANRec(UInt32 ID, VCI_CAN_OBJ sendObj)
  466. {
  467. unsafe
  468. {
  469. switch (ID)
  470. {
  471. case 0x1801D0F3:
  472. string[] strs_BMS_CutOffHVReq = { "0:预留 ","请求下高压","不请求下高压","无效 "};
  473. int BMS_CutOffHVReq = (byte)((((sendObj.Data[0] >> 2) & 0x3) << 0)); //是否请求下高压
  474. BMS_CutOffHVReq = BMS_CutOffHVReq > strs_BMS_CutOffHVReq.Length ? BMS_CutOffHVReq : strs_BMS_CutOffHVReq.Length - 1;
  475. textBox_BMS_CutOffHVReq.Text = strs_BMS_CutOffHVReq[BMS_CutOffHVReq];
  476. //int BMS_PmtCutoffLVFb = (byte)((((sendObj.Data[0]>>4)&0x3)<<0)); //BMS允许下低压
  477. //int BMS_EmergCutoffHVReq = (byte)((((sendObj.Data[0]>>6)&0x3)<<0)); //BMS紧急下高压请求
  478. //int BMS_HeatNegRelaySts = (byte)((((sendObj.Data[1]>>0)&0x3)<<0)); //加热负继电器状态
  479. // int BMS_HeatPosRelaySts = (byte)((((sendObj.Data[1]>>2)&0x3)<<0)); //加热正继电器状态
  480. //int BMS_SelfChkSts = (byte)((((sendObj.Data[1]>>4)&0x3)<<0)); //BMS自检状态
  481. break;
  482. case 0x1880D0F3:
  483. /*
  484. int BMS_BattSysNum = (byte)((((sendObj.Data[0]>>0)&0xF)<<0)); //可充电装置系统序号
  485. int BMS_MainPosRelayWeldedFlt = (byte)((((sendObj.Data[0]>>4)&0x1)<<0)); //主正继电器粘连故障
  486. int BMS_MainNegRelayWeldedFlt = (byte)((((sendObj.Data[0]>>5)&0x1)<<0)); //主负继电器粘连故障
  487. int BMS_ChgPosWeldedFlt1 = (byte)((((sendObj.Data[0]>>6)&0x1)<<0)); //充电正1继电器粘连故障
  488. int BMS_ChgNegWeldedFlt1 = (byte)((((sendObj.Data[0]>>7)&0x1)<<0)); //充电负1继电器粘连故障
  489. int BMS_ChgPosWeldedFlt2 = (byte)((((sendObj.Data[1]>>0)&0x1)<<0)); //充电正2继电器粘连故障
  490. int BMS_ChgNegWeldedFlt2 = (byte)((((sendObj.Data[1]>>1)&0x1)<<0)); //充电负2继电器粘连故障
  491. int BMS_HeatNegWeldedFlt = (byte)((((sendObj.Data[1]>>2)&0x1)<<0)); //加热负继电器粘连故障
  492. int BMS_HeatPosWeldedFlt1 = (byte)((((sendObj.Data[1]>>3)&0x1)<<0)); //加热正继电器粘连故障
  493. */
  494. string[] BMS_ConnSts = { "预留" , "开启" ,"闭合" , "无效" };
  495. int BMS_MainPosConnSts = (byte)((((sendObj.Data[1] >> 4) & 0x3) << 0)); //主正继电器状态反馈
  496. int BMS_MainNegConnSts = (byte)((((sendObj.Data[1] >> 6) & 0x3) << 0)); //主ds负继电器状态反馈
  497. int BMS_PreChgConnSts = (byte)((((sendObj.Data[2] >> 0) & 0x3) << 0)); //预充继电器状态反馈
  498. int BMS_ChgPosConnSts1 = (byte)((((sendObj.Data[2] >> 2) & 0x3) << 0)); //充电正1继电器状态
  499. int BMS_ChgNegConnSts1 = (byte)((((sendObj.Data[2] >> 4) & 0x3) << 0)); //充电负1继电器状态
  500. int BMS_ChgPosConnSts2 = (byte)((((sendObj.Data[2] >> 6) & 0x3) << 0)); //充电正2继电器状态
  501. int BMS_ChgNegConnSts2 = (byte)((((sendObj.Data[3] >> 0) & 0x3) << 0)); //充电负2继电器状态
  502. BMS_MainPosConnSts = BMS_MainPosConnSts > BMS_ConnSts.Length ? BMS_MainPosConnSts : BMS_ConnSts.Length - 1;
  503. BMS_MainNegConnSts = BMS_MainNegConnSts > BMS_ConnSts.Length ? BMS_MainNegConnSts : BMS_ConnSts.Length - 1;
  504. BMS_ChgPosConnSts1 = BMS_ChgPosConnSts1 > BMS_ConnSts.Length ? BMS_ChgPosConnSts1 : BMS_ConnSts.Length - 1;
  505. BMS_PreChgConnSts = BMS_PreChgConnSts > BMS_ConnSts.Length ? BMS_PreChgConnSts : BMS_ConnSts.Length - 1;
  506. BMS_ChgNegConnSts1 = BMS_ChgNegConnSts1 > BMS_ConnSts.Length ? BMS_ChgNegConnSts1 : BMS_ConnSts.Length - 1;
  507. BMS_ChgPosConnSts2 = BMS_ChgPosConnSts2 > BMS_ConnSts.Length ? BMS_ChgPosConnSts2 : BMS_ConnSts.Length - 1;
  508. BMS_ChgNegConnSts2 = BMS_ChgNegConnSts2 > BMS_ConnSts.Length ? BMS_ChgNegConnSts2 : BMS_ConnSts.Length - 1;
  509. textBox_BMS_MainPosConnSts.Text = BMS_ConnSts[BMS_MainPosConnSts];
  510. textBox_BMS_MainNegConnSts.Text = BMS_ConnSts[BMS_MainNegConnSts];
  511. textBox_BMS_PreChgConnSts.Text = BMS_ConnSts[BMS_PreChgConnSts];
  512. textBox_BMS_ChgPosConnSts1.Text = BMS_ConnSts[BMS_ChgPosConnSts1];
  513. textBox_BMS_ChgNegConnSts1.Text = BMS_ConnSts[BMS_ChgNegConnSts1];
  514. textBox_BMS_ChgPosConnSts2.Text = BMS_ConnSts[BMS_ChgPosConnSts2];
  515. textBox_BMS_ChgNegConnSts2.Text = BMS_ConnSts[BMS_ChgNegConnSts2];
  516. int BMS_ErrorCode = (byte)((((sendObj.Data[7] >> 0) & 0xFF) << 0)); //电池系统故障码
  517. textBox_BMS_ErrorCode.Text = BMS_ErrorCode.ToString();
  518. /*
  519. int BMS_BranchCircuitFlt = (byte)((((sendObj.Data[3]>>3)&0x1)<<0)); //支路断路故障
  520. int BMS_ChgCircuitOverLimtFlt = (byte)((((sendObj.Data[3]>>4)&0x3)<<0)); //回充电流超限故障
  521. int BMS_MainPosNotConnFlt = (byte)((((sendObj.Data[3]>>6)&0x1)<<0)); //主正继电器无法闭合报警
  522. int BMS_MainNegNotConnFlt = (byte)((((sendObj.Data[3]>>7)&0x1)<<0)); //主负继电器无法闭合报警
  523. int BMS_ChgPosNotConnFlt1 = (byte)((((sendObj.Data[4]>>0)&0x1)<<0)); //充电正1继电器无法闭合报警
  524. int BMS_ChgPosNotConnFlt2 = (byte)((((sendObj.Data[4]>>1)&0x1)<<0)); //充电正2继电器无法闭合报警
  525. int BMS_ChgNegNotConnFlt1 = (byte)((((sendObj.Data[4]>>2)&0x1)<<0)); //充电负1继电器无法闭合报警
  526. int BMS_ChgNegNotConnFlt2 = (byte)((((sendObj.Data[4]>>3)&0x1)<<0)); //充电负2继电器无法闭合报警
  527. int BMS_HeatBTMSConnNotOpenFlt = (byte)((((sendObj.Data[4]>>4)&0x1)<<0)); //加热膜或BTMS继电器无法断开故障
  528. int BMS_HeatBTMSNotConnFlt = (byte)((((sendObj.Data[4]>>5)&0x1)<<0)); //加热膜或 BTMS 继电器无法闭合故障
  529. int BMS_HeatMgSysFlt = (byte)((((sendObj.Data[4]>>6)&0x1)<<0)); //热管理系统故障
  530. int BMS_SupBattFlt = (byte)((((sendObj.Data[4]>>7)&0x1)<<0)); //BMS 24V供电异常报警
  531. int BMS_BattSelfProtAlm = (byte)((((sendObj.Data[5]>>0)&0x1)<<0)); //电池包自保护报警
  532. int BMS_PreChgRelayWeldedFlt = (byte)((((sendObj.Data[5]>>3)&0x1)<<0)); //预充继电器粘连故障
  533. int BMS_PreChgNotConnFlt = (byte)((((sendObj.Data[5]>>4)&0x1)<<0)); //预充继电器无法闭合报警
  534. int BMS_HeatPosNotConnFlt1 = (byte)((((sendObj.Data[5]>>5)&0x1)<<0)); //加热正继电器无法闭合故障
  535. int BMS_HeatNegNotConnFlt = (byte)((((sendObj.Data[5]>>6)&0x1)<<0)); //加热负继电器无法闭合故障
  536. int BMS_SysNum = (byte)((((sendObj.Data[6]>>0)&0xF)<<0)); //可充电储能子系统总数
  537. */
  538. break;
  539. case 0x1881D0F3:
  540. string[] strs_BMS_FaultLevel = { "无故障", "1级故障", "2级故障", "3级故障" };
  541. string[] sts_BMS_BattCurrentSts = { "高压开启", "预先充电", "高压关断", "高压上电故障" };
  542. int BMS_FaultLevel = (byte)((((sendObj.Data[2] >> 5) & 0x3) << 0)); //最高报警等级
  543. int BMS_GBT32960FltNum = (byte)((((sendObj.Data[7] >> 3) & 0x1F) << 0)); //故障数目
  544. int BMS_BattCurrentSts = (byte)((((sendObj.Data[1] >> 4) & 0x3) << 0)); //BMS当前工作状态
  545. BMS_FaultLevel = BMS_FaultLevel > strs_BMS_FaultLevel.Length ? BMS_BattCurrentSts : strs_BMS_FaultLevel.Length - 1;
  546. textBox_BMS_FaultLevel.Text = strs_BMS_FaultLevel[BMS_FaultLevel];
  547. textBox_BMS_GBT32960FltNum.Text = textBox_BMS_GBT32960FltNum.ToString();
  548. BMS_BattCurrentSts = BMS_BattCurrentSts > sts_BMS_BattCurrentSts.Length ? BMS_BattCurrentSts : sts_BMS_BattCurrentSts.Length - 1;
  549. textBox_BMS_BattCurrentSts.Text = sts_BMS_BattCurrentSts[BMS_BattCurrentSts];
  550. /*
  551. int BMS_B2V_ST1Checksum = (byte)((((sendObj.Data[0]>>0)&0xFF)<<0)); //校验
  552. int BMS_B2V_ST2AliveCounter = (byte)((((sendObj.Data[1]>>0)&0xF)<<0)); //计数
  553. int BMS_AssisConnSts = (byte)((((sendObj.Data[1]>>6)&0x1)<<0)); //附件继电器状态
  554. int BMS_BattEqualizationSts = (byte)((((sendObj.Data[1]>>7)&0x1)<<0)); //BMS当前均衡状态
  555. int BMS_CellTempDiffFault = (byte)((((sendObj.Data[3]>>0)&0x3)<<0)); //电芯温差异常报警
  556. int BMS_BattTempHighFault = (byte)((((sendObj.Data[3]>>2)&0x3)<<0)); //电芯温度过高报警
  557. int BMS_BattPackVolHighFault = (byte)((((sendObj.Data[3]>>4)&0x3)<<0)); //PACK过压报警
  558. int BMS_BattPackVolLowFault = (byte)((((sendObj.Data[3]>>6)&0x3)<<0)); //PACK欠压报警
  559. int BMS_BattSOCLowFault = (byte)((((sendObj.Data[4]>>0)&0x3)<<0)); //SOC过低报警
  560. int BMS_BattCellVolHighFault = (byte)((((sendObj.Data[4]>>2)&0x3)<<0)); //单体电压过高报警
  561. int BMS_BattCellVolLowFault = (byte)((((sendObj.Data[4]>>4)&0x3)<<0)); //单体电压欠压报警
  562. int BMS_BattIsolationFault = (byte)((((sendObj.Data[4]>>6)&0x3)<<0)); //绝缘报警
  563. int BMS_CellVolDiffFault = (byte)((((sendObj.Data[5]>>0)&0x3)<<0)); //单体压差过大
  564. int BMS_ChgCurrHighFlt = (byte)((((sendObj.Data[5]>>2)&0x3)<<0)); //充电电流过大报警
  565. int BMS_DisChgCurrHighFlt = (byte)((((sendObj.Data[5]>>4)&0x3)<<0)); //放电电流过大报警
  566. int BMS_BattTempLowFault = (byte)((((sendObj.Data[5]>>6)&0x3)<<0)); //电芯温度过低报警
  567. int BMS_BranchCircuitDiffFault = (byte)((((sendObj.Data[6]>>0)&0x3)<<0)); //支路压差过大报警
  568. int BMS_ST1_Flt_HW = (byte)((((sendObj.Data[6]>>2)&0x3)<<0)); //BMS 硬件故障
  569. int BMS_BattSOCHighFault = (byte)((((sendObj.Data[6]>>4)&0x1)<<0)); //SOC过高报警
  570. int BMS_SOCJumpFault = (byte)((((sendObj.Data[6]>>5)&0x1)<<0)); //SOC跳变报警
  571. int BMS_CANComFault = (byte)((((sendObj.Data[6]>>6)&0x1)<<0)); //BMS内部通讯故障
  572. int BMS_BattPackMatchFault = (byte)((((sendObj.Data[6]>>7)&0x1)<<0)); //BMS系统不匹配报警
  573. int BMS_ST1_Flt_HVIL = (byte)((((sendObj.Data[7]>>0)&0x1)<<0)); //高压互锁报警
  574. int BMS_SmokeAlarm = (byte)((((sendObj.Data[7]>>1)&0x1)<<0)); //烟雾报警
  575. int BMS_FireAlarm = (byte)((((sendObj.Data[7]>>2)&0x1)<<0)); //火灾报警
  576. */
  577. break;
  578. case 0x1882D0F3:
  579. int BMS_BattSOC = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //电池包SOC
  580. int BMS_BattSOH = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //电池包SOH
  581. int BMS_BattCurr = (UInt16)((((sendObj.Data[2] >> 0) & 0xFF) << 0) | (((sendObj.Data[3] >> 0) & 0xFF) << 8)); //动力电池组电流
  582. //int BMS_MaxPmtEnyRecoCurr = (UInt16)((((sendObj.Data[4]>>0)&0xFF)<<0)|(((sendObj.Data[5]>>0)&0xFF)<<8)); //电池包允许最大回充电电流值 (脉冲)
  583. int BMS_MaxPmtDischgCurr = (UInt16)((((sendObj.Data[6] >> 0) & 0xFF) << 0) | (((sendObj.Data[7] >> 0) & 0xFF) << 8)); //电池包允许最大放电电流值(脉冲)
  584. textBox_BMS_BattSOC.Text = ((BMS_BattSOC + 0.0) * 0.4).ToString("F2");
  585. textBox_BMS_BattSOH.Text = ((BMS_BattSOH + 0.0) * 0.4).ToString("F2");
  586. textBox_BMS_BattCurr.Text = ((BMS_BattCurr + 0.0) * 0.1 - 2000.0).ToString("F2");
  587. textBox_BMS_MaxPmtDischgCurr.Text = ((BMS_BattCurr + 0.0) * 0.1).ToString();
  588. break;
  589. case 0x1883D0F3:
  590. int BMS_PosIsolationRes = (UInt16)((((sendObj.Data[0] >> 0) & 0xFF) << 0) | (((sendObj.Data[1] >> 0) & 0xFF) << 8)); //电池包正极绝缘值
  591. int BMS_NegIsolationRes = (UInt16)((((sendObj.Data[2] >> 0) & 0xFF) << 0) | (((sendObj.Data[3] >> 0) & 0xFF) << 8)); //电池包负极绝缘值
  592. int BMS_BattTermVolINMainPos = (UInt16)((((sendObj.Data[4] >> 0) & 0xFF) << 0) | (((sendObj.Data[5] >> 0) & 0xFF) << 8)); //主正继电器内侧电池端电压 总压
  593. int BMS_BattBusVolOutMainPos = (UInt16)((((sendObj.Data[6] >> 0) & 0xFF) << 0) | (((sendObj.Data[7] >> 0) & 0xFF) << 8)); //主正继电器外侧母线电压
  594. textBox_BMS_PosIsolationRes.Text = ((BMS_PosIsolationRes)).ToString();
  595. textBox_BMS_NegIsolationRes.Text = ((BMS_NegIsolationRes)).ToString();
  596. textBox_BMS_BattTermVolINMainPos.Text = ((BMS_BattTermVolINMainPos + 0.0) * 0.1).ToString("F2");
  597. textBox_BMS_BattBusVolOutMainPos.Text = ((BMS_BattBusVolOutMainPos + 0.0) * 0.1).ToString("F2");
  598. break;
  599. case 0x1884D0F3:
  600. int BMS_BattMaxTemp = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //电芯温度最大值
  601. int BMS_BattMinTemp = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //电芯温度最小值
  602. textBox_BMS_BattMaxTemp.Text = BMS_BattMaxTemp.ToString();
  603. textBox_BMS_BattMinTemp.Text = BMS_BattMinTemp.ToString();
  604. /*int BMS_Cell_Avg_Temp = (byte)((((sendObj.Data[2]>>0)&0xFF)<<0)); //电芯温度平均值
  605. int BMS_MaxTemp1PackNum = (byte)((((sendObj.Data[3]>>0)&0xFF)<<0)); //电芯温度最大值所在CSC编号
  606. int BMS_MaxTemp1SnsNum = (byte)((((sendObj.Data[4]>>0)&0xFF)<<0)); //电芯温度最大值所在CSC内温度探针编号
  607. int BMS_MinTemp1PackNum = (byte)((((sendObj.Data[5]>>0)&0xFF)<<0)); //电芯温度最小值所在CSC内温度探针编号
  608. int BMS_MinTemp1SnsNum = (byte)((((sendObj.Data[6]>>0)&0xFF)<<0)); //电芯温度最小值所在CSC内温度探针编号*/
  609. break;
  610. case 0x1885D0F3:
  611. int BMS_MaxCellVolt = (UInt16)((((sendObj.Data[0] >> 0) & 0xFF) << 0) | (((sendObj.Data[1] >> 0) & 0xFF) << 8)); //电芯电压值最大值
  612. /*int BMS_MaxCellVoltPackNum = (byte)((((sendObj.Data[2]>>0)&0xFF)<<0)); //电芯电压最大值所在CSC编号
  613. int BMS_MaxCellVoltSnsNum = (byte)((((sendObj.Data[3]>>0)&0xFF)<<0)); //电芯电压最大值所在CSC内单体编号
  614. int BMS_Cell_Avg_Volt = (UInt16)((((sendObj.Data[4]>>0)&0xFF)<<0)|(((sendObj.Data[5]>>0)&0xFF)<<8)); //电芯电压值平均值*/
  615. textBox_BMS_MaxCellVolt.Text = ((BMS_MaxCellVolt + 0.0) * 0.001).ToString("F3");
  616. break;
  617. case 0x1886D0F3:
  618. int BMS_MinCellVolt = (UInt16)((((sendObj.Data[0] >> 0) & 0xFF) << 0) | (((sendObj.Data[1] >> 0) & 0xFF) << 8)); //电芯电压值最小值
  619. //int BMS_MinCellVoltSnsNum = (byte)((((sendObj.Data[2]>>0)&0xFF)<<0)); //电芯电压最小值所在CSC内单体编号
  620. //int BMS_MinCellVoltPackNum = (byte)((((sendObj.Data[3]>>0)&0xFF)<<0)); //电芯电压最小值所在CSC编号
  621. textBox_BMS_MinCellVolt.Text = ((BMS_MinCellVolt + 0.0) * 0.001).ToString("F3");
  622. break;
  623. case 0x1888D0F3:
  624. //int BMS_BattTermVolOutMainPos = (UInt16)((((sendObj.Data[0]>>0)&0xFF)<<0)|(((sendObj.Data[1]>>0)&0xFF)<<8)); //主正继电器外侧电池端电压
  625. //int BMS_BattTermVolOutMainNeg = (UInt16)((((sendObj.Data[2]>>0)&0xFF)<<0)|(((sendObj.Data[3]>>0)&0xFF)<<8)); //主负继电器外侧电池端电压
  626. string[] strs_BMS_DCChgPlugSts = { "未连接", "仅充电口A口连接", "仅充电口B口连接", "充电口A口和B充都连接"};
  627. string[] strs_BMS_ChgSts = { "可以充电", "正在充电", "充电结束", "充电故障" };
  628. string[] strs_BMS_CnctSt = { "车", "站" };
  629. string[] strs_BMS_chrgIReq = { "30s", "60s" };
  630. int BMS_DCChgPlugSts = (byte)((((sendObj.Data[4] >> 0) & 0x7) << 0)); //充电枪连接状态
  631. int BMS_ChgSts = (byte)((((sendObj.Data[4] >> 5) & 0x7) << 0)); //充电状态
  632. //int BMS_ChgMode = (byte)((((sendObj.Data[4]>>3)&0x3)<<0)); //充电模式
  633. int BMS_CnctSt = (byte)((((sendObj.Data[5] >> 4) & 0x1) << 0)); //BMS连接状态
  634. //int BMS_BattPulseTime = (byte)((((sendObj.Data[5]>>5)&0x7)<<0)); //脉冲时间
  635. int BMS_chrgIReq = (UInt16)((((sendObj.Data[6] >> 0) & 0xFF) << 0) | (((sendObj.Data[7] >> 0) & 0xFF) << 8)); //充电需求电流
  636. BMS_DCChgPlugSts = BMS_DCChgPlugSts > strs_BMS_DCChgPlugSts.Length ? BMS_DCChgPlugSts : strs_BMS_DCChgPlugSts.Length - 1;
  637. textBox_BMS_DCChgPlugSts.Text = strs_BMS_DCChgPlugSts[BMS_DCChgPlugSts];
  638. BMS_ChgSts = BMS_ChgSts > strs_BMS_ChgSts.Length ? BMS_ChgSts : strs_BMS_ChgSts.Length - 1;
  639. textBox_BMS_DCChgPlugSts.Text = strs_BMS_ChgSts[BMS_ChgSts];
  640. BMS_CnctSt = BMS_CnctSt > strs_BMS_CnctSt.Length ? BMS_CnctSt : strs_BMS_CnctSt.Length - 1;
  641. textBox_BMS_DCChgPlugSts.Text = strs_BMS_CnctSt[BMS_CnctSt];
  642. BMS_chrgIReq = BMS_chrgIReq > strs_BMS_chrgIReq.Length ? BMS_chrgIReq : strs_BMS_chrgIReq.Length - 1;
  643. textBox_BMS_chrgIReq.Text = strs_BMS_chrgIReq[BMS_chrgIReq];
  644. break;
  645. case 0x18C1D0F3:
  646. int BMS_CellVolMsgCode = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //帧序号
  647. int BMS_CellVolCSCNum = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //CSC 编号
  648. int BMS_CellVolt1 = (UInt16)((((sendObj.Data[2] >> 0) & 0xFF) << 0) | (((sendObj.Data[3] >> 0) & 0xFF) << 8)); //单体电池电压(V1)
  649. int BMS_CellVolt2 = (UInt16)((((sendObj.Data[4] >> 0) & 0xFF) << 0) | (((sendObj.Data[5] >> 0) & 0xFF) << 8)); //单体电池电压(V2)
  650. int BMS_CellVolt3 = (UInt16)((((sendObj.Data[6] >> 0) & 0xFF) << 0) | (((sendObj.Data[7] >> 0) & 0xFF) << 8)); //单体电池电压(V3)
  651. //int BCUCellU[BMS_CellVolMsgCode * 3 - 3]=BMS_CellVolt1*0.001;
  652. //int BCUCellU[BMS_CellVolMsgCode * 3 - 2]=BMS_CellVolt2*0.001;
  653. //int BCUCellU[BMS_CellVolMsgCode * 3 - 1]=BMS_CellVolt3*0.001;
  654. break;
  655. case 0x18C2D0F3:
  656. int BMS_TempMsgCode = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //帧序号
  657. int BMS_CSCNum = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //CSC 编号
  658. int BMS_BattTemp1 = (byte)((((sendObj.Data[2] >> 0) & 0xFF) << 0)); //温度探针1对应的温度值
  659. int BMS_BattTemp2 = (byte)((((sendObj.Data[3] >> 0) & 0xFF) << 0)); //温度探针2对应的温度值
  660. int BMS_BattTemp3 = (byte)((((sendObj.Data[4] >> 0) & 0xFF) << 0)); //温度探针3对应的温度值
  661. int BMS_BattTemp4 = (byte)((((sendObj.Data[5] >> 0) & 0xFF) << 0)); //温度探针4对应的温度值
  662. int BMS_BattTemp5 = (byte)((((sendObj.Data[6] >> 0) & 0xFF) << 0)); //温度探针5对应的温度值
  663. int BMS_BattTemp6 = (byte)((((sendObj.Data[7] >> 0) & 0xFF) << 0)); //温度探针6对应的温度值
  664. // int BCUModT[BMS_TempMsgCode * 6 - 6]=BMS_BattTemp1-40;
  665. // int BCUModT[BMS_TempMsgCode * 6 - 5]=BMS_BattTemp1-40;
  666. // int BCUModT[BMS_TempMsgCode * 6 - 4]=BMS_BattTemp1-40;
  667. // int BCUModT[BMS_TempMsgCode * 6 - 3]=BMS_BattTemp1-40;
  668. // int BCUModT[BMS_TempMsgCode * 6 - 2]=BMS_BattTemp1-40;
  669. // int BCUModT[BMS_TempMsgCode * 6 - 1]=BMS_BattTemp1-40;
  670. break;
  671. case 0x18F4D0F3:
  672. /*int BMS_SingleChgEnergy = (UInt16)((((sendObj.Data[0]>>0)&0xFF)<<0)|(((sendObj.Data[1]>>0)&0xFF)<<8)); //单次充电电量(充电枪插入)
  673. int BMS_SingleDisChgEny = (UInt16)((((sendObj.Data[2]>>0)&0xFF)<<0)|(((sendObj.Data[3]>>0)&0xFF)<<8)); //单次放电电量
  674. int BMS_SingleEnergy = (UInt16)((((sendObj.Data[4]>>0)&0xFF)<<0)|(((sendObj.Data[5]>>0)&0xFF)<<8)); //单次充电电量(制动能量回收)*/
  675. break;
  676. case 0x18FEF8F3:
  677. /*int BMS_ConTempDC1Pos = (byte)((((sendObj.Data[0]>>0)&0xFF)<<0)); //行车换电连接器功率端子DC1+的温度
  678. int BMS_ConTempDC1Neg = (byte)((((sendObj.Data[1]>>0)&0xFF)<<0)); //行车换电连接器功率端子DC1-的温度
  679. int BMS_ConTempDC2Pos = (byte)((((sendObj.Data[2]>>0)&0xFF)<<0)); //行车换电连接器功率端子DC2+的温度
  680. int BMS_ConTempDC2Neg = (byte)((((sendObj.Data[3]>>0)&0xFF)<<0)); //行车换电连接器功率端子DC2-的温度
  681. int BMS_ChgConTempDC1Pos = (byte)((((sendObj.Data[4]>>0)&0xFF)<<0)); //充电换电连接器功率端子DC1+的温度
  682. int BMS_ChgConTempDC1Neg = (byte)((((sendObj.Data[5]>>0)&0xFF)<<0)); //充电换电连接器功率端子DC1-的温度
  683. int BMS_ChgConTempDC2Pos = (byte)((((sendObj.Data[6]>>0)&0xFF)<<0)); //充电换电连接器功率端子DC2+的温度
  684. int BMS_ChgConTempDC2Neg = (byte)((((sendObj.Data[7]>>0)&0xFF)<<0)); //充电换电连接器功率端子DC2-的温度*/
  685. break;
  686. case 0x18FFF3CB:
  687. int BMS_encryp1 = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //BMS认证数据1
  688. int BMS_encryp2 = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //BMS认证数据2
  689. int BMS_encryp3 = (byte)((((sendObj.Data[2] >> 0) & 0xFF) << 0)); //BMS认证数据3
  690. int BMS_encryp4 = (byte)((((sendObj.Data[3] >> 0) & 0xFF) << 0)); //BMS认证数据4
  691. break;
  692. default:
  693. break;
  694. }
  695. }
  696. }
  697. int VCU_V2B_CMD_AliveConter = 0;
  698. UInt16 encryptionAlgorithm(UInt16 plainText)
  699. {
  700. UInt16 cipherText = 1;
  701. UInt32 privateKeyE = 207521;
  702. UInt16 privateKeyN = 54127;
  703. plainText = (UInt16)(plainText % privateKeyN);
  704. while (privateKeyE > 0)
  705. {
  706. if (privateKeyE % 2 == 1)
  707. {
  708. cipherText = (UInt16)((cipherText * plainText) % privateKeyN);
  709. }
  710. privateKeyE = privateKeyE / 2;
  711. plainText = (UInt16)((plainText * plainText) % privateKeyN);
  712. }
  713. return cipherText;
  714. }
  715. int Message_Counter = 0;
  716. void textChecker(object sender, KeyPressEventArgs e)
  717. { //判断输入是否符合规范
  718. if ((!char.IsDigit(e.KeyChar)) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  719. {//允许输入数字、退格符、小数点、删除键和负号
  720. MessageBox.Show("请输入正确的数字");
  721. e.Handled = true;
  722. }
  723. if (e.KeyChar == (char)('-'))
  724. {
  725. if (Form.ActiveForm.ActiveControl.Text != "")
  726. {//这里的txt1需要改成应用处的TextBox的名称,或者可以给这个函数多传递一个参数,再在此处添加一个switch来判断
  727. MessageBox.Show("负号位置错误");
  728. e.Handled = true;
  729. }
  730. }
  731. if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
  732. {
  733. MessageBox.Show("第一位不能为小数点");
  734. e.Handled = true;
  735. }
  736. if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
  737. {
  738. MessageBox.Show("小数点只能输入一次");
  739. e.Handled = true;
  740. }
  741. if (e.KeyChar != (char)('.') && ((TextBox)sender).Text == "0" && (e.KeyChar != 8))
  742. {//这里要注意退格符是可以输入的
  743. MessageBox.Show("第一位是0,第二位必须为小数点");
  744. e.Handled = true;
  745. }
  746. if (((TextBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  747. {
  748. MessageBox.Show("第一位是负号,第二位不能为小数点 ");
  749. e.Handled = true;
  750. }
  751. }
  752. }
  753. }