Form1.cs 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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. static int SubBoardsNUM = 6;
  183. static int P_ALL_U_NUM = 34;
  184. static int P_ALL_T_NUM = 10;
  185. TextBox[] textboxs_U = new TextBox[SubBoardsNUM * P_ALL_U_NUM];
  186. Label[] lables_U = new Label[SubBoardsNUM * P_ALL_U_NUM];
  187. TextBox[] textboxs_T = new TextBox[SubBoardsNUM * P_ALL_T_NUM];
  188. Label[] lables_T = new Label[SubBoardsNUM * P_ALL_T_NUM];
  189. private void Form1_Load(object sender, EventArgs e)
  190. {
  191. Int32 curindex = 0;
  192. comboBox_devtype.Items.Clear();
  193. curindex = comboBox_devtype.Items.Add("DEV_USBCAN");
  194. m_arrdevtype[curindex] = DEV_USBCAN;
  195. //comboBox_devtype.Items[2] = "VCI_USBCAN1";
  196. //m_arrdevtype[2]= VCI_USBCAN1 ;
  197. curindex = comboBox_devtype.Items.Add("DEV_USBCAN2");
  198. m_arrdevtype[curindex] = DEV_USBCAN2;
  199. //comboBox_devtype.Items[3] = "VCI_USBCAN2";
  200. //m_arrdevtype[3]= VCI_USBCAN2 ;
  201. comboBox_BoardIndex.SelectedIndex = 0;
  202. comboBox_CANIndex.SelectedIndex = 0;
  203. comboBox_DeviceIndex.SelectedIndex = 0;
  204. comboBox_CANIndex.SelectedIndex = 0;
  205. comboBox_MsgType.SelectedIndex = 0;
  206. comboBox_VCU_BMSHVOnOffReq.SelectedIndex = 0;
  207. comboBox_VCU_AllowChgCtrl.SelectedIndex = 0;
  208. comboBox_VCU_BMSCutOffLV.SelectedIndex = 0;
  209. comboBox_LockingPinStsFB.SelectedIndex = 0;
  210. comboBox_Change_BattConSts.SelectedIndex = 0;
  211. comboBox_BTMS_WorkSts.SelectedIndex = 0;
  212. comboBox_BTMS_ConnStsFb.SelectedIndex = 0;
  213. comboBox_BTMS_FltLevel.SelectedIndex = 0;
  214. comboBox_encryptionEnable.SelectedIndex = 0;
  215. //comboBox_ControllerChoose.SelectedIndex = 0x00;
  216. //comboBox_MsgType.SelectedIndex = 0x01;
  217. //canMsgType = (byte)(comboBox_MsgType.SelectedIndex);
  218. //controllerChooseFlag = (byte)(comboBox_ControllerChoose.SelectedIndex + 1);
  219. //
  220. FlowLayoutPanel[] flowLayoutPanelS = { flowLayoutPanel_1, flowLayoutPanel_2, flowLayoutPanel_3, flowLayoutPanel_4, flowLayoutPanel_5, flowLayoutPanel_6 };
  221. flowLayoutPanel_1.Dock = DockStyle.Fill;
  222. //flowLayoutPanel_1.FlowDirection = FlowDirection.TopDown;
  223. // 循环生成50个lable控件和50个textbox控件
  224. for (int i = 0; i < SubBoardsNUM; i++)
  225. {
  226. flowLayoutPanelS[i].WrapContents = true;
  227. for (int j = 0; j < P_ALL_U_NUM; j++)
  228. {
  229. // 创建lable控件和textbox控件
  230. Label label = new Label();
  231. TextBox textbox = new TextBox();
  232. // 设置lable控件的文本和位置
  233. label.Text = "U" + (j + 1).ToString();
  234. label.Location = new Point(0, 0);
  235. label.Size = new Size(25, 15);
  236. // 设置textbox控件的位置和大小
  237. textbox.Location = new Point(label.Width, 0);
  238. textbox.Size = new Size(50, 25);
  239. // 创建一个容器控件,用于存放每对lable控件和textbox控件
  240. Panel container = new Panel();
  241. container.Size = new Size(textbox.Width + label.Width + 20, textbox.Height);
  242. container.Controls.Add(label);
  243. container.Controls.Add(textbox);
  244. //container.Margin = new Padding(2,2,2,2);
  245. // 将容器控件添加到FlowLayoutPanel中
  246. flowLayoutPanelS[i].Controls.Add(container);
  247. // 每行有五个控件,如果已经添加了五个控件,就换行
  248. if ((j+1) % 7 == 0 || j == 33)
  249. {
  250. flowLayoutPanelS[i].SetFlowBreak(container, true);
  251. }
  252. lables_U[i * 34 + j] = label;
  253. textboxs_U[i * 34 + j] = textbox;
  254. }
  255. for (int j = 0; j < P_ALL_T_NUM; j++)
  256. {
  257. // 创建lable控件和textbox控件
  258. Label label = new Label();
  259. TextBox textbox = new TextBox();
  260. // 设置lable控件的文本和位置
  261. label.Text = "T" + (j + 1).ToString();
  262. label.Location = new Point(0, 0);
  263. label.Size = new Size(25, 15);
  264. // 设置textbox控件的位置和大小
  265. textbox.Location = new Point(label.Width, 0);
  266. textbox.Size = new Size(50, 25);
  267. // 创建一个容器控件,用于存放每对lable控件和textbox控件
  268. Panel container = new Panel();
  269. container.Size = new Size(textbox.Width + label.Width + 20, textbox.Height);
  270. container.Controls.Add(label);
  271. container.Controls.Add(textbox);
  272. //container.Margin = new Padding(2,2,2,2);
  273. // 将容器控件添加到FlowLayoutPanel中
  274. flowLayoutPanelS[i].Controls.Add(container);
  275. // 每行有五个控件,如果已经添加了五个控件,就换行
  276. if ((j + 1) % 7 == 0)
  277. {
  278. flowLayoutPanelS[i].SetFlowBreak(container, true);
  279. }
  280. lables_T[i * 10 + j] = label;
  281. textboxs_T[i * 10 + j] = textbox;
  282. }
  283. }
  284. comboBox_devtype.SelectedIndex = 1;
  285. comboBox_devtype.MaxDropDownItems = comboBox_devtype.Items.Count;
  286. setBoxAndButtonEnalbe(true);
  287. isForm1Colsed = false;
  288. }
  289. private void setBoxAndButtonEnalbe(bool trueOrfalse)
  290. {
  291. comboBox_CANIndex.Enabled = trueOrfalse;
  292. comboBox_devtype.Enabled = trueOrfalse;
  293. comboBox_BoardIndex.Enabled = trueOrfalse;
  294. comboBox_DeviceIndex.Enabled = trueOrfalse;
  295. }
  296. private void Form1_FormClosed(object sender, FormClosedEventArgs e)
  297. {
  298. if (buttStartCan == true)
  299. {
  300. VCI_CloseDevice(m_devtype, m_devind);
  301. }
  302. //autoSaveFile();
  303. //UpdateStep = 0xFF;
  304. isForm1Colsed = true;
  305. //setBoxAndButtonEnalbe(false);
  306. }
  307. private void button_StartCAN_Click(object sender, EventArgs e)
  308. {
  309. if (buttStartCan == true)
  310. {
  311. buttStartCan = false;
  312. VCI_CloseDevice(m_devtype, m_devind);
  313. }
  314. else
  315. {
  316. m_devtype = m_arrdevtype[comboBox_devtype.SelectedIndex];
  317. m_devind = 0;
  318. m_canind = (UInt32)comboBox_CANIndex.SelectedIndex;
  319. m_devind = (UInt32)comboBox_DeviceIndex.SelectedIndex;
  320. if (VCI_OpenDevice(m_devtype, m_devind, 0) == 0)
  321. {
  322. MessageBox.Show("打开设备失败,请检查设备类型和设备索引号是否正确", "错误",
  323. MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  324. return;
  325. }
  326. buttStartCan = true;
  327. VCI_INIT_CONFIG config = new VCI_INIT_CONFIG();
  328. if (comboBox_MsgType.Text == "标准帧")
  329. {
  330. config.AccCode = 0;
  331. config.AccMask = 0xffffffff;
  332. //config.AccCode = Convert.ToUInt32(textBox_responseAddr.Text, 16) << 21;
  333. //config.AccMask = 0x1FFFFF;
  334. config.Filter = 0x02;//只接收符合要求的标准帧
  335. //0或1接收所有帧。2标准帧滤波,3是扩展帧滤波。
  336. }
  337. else if (comboBox_MsgType.Text == "扩展帧")
  338. {
  339. config.AccCode = 0;
  340. config.AccMask = 0xffffffff;
  341. //config.AccCode = Convert.ToUInt32(textBox_responseAddr.Text, 16) << 3;
  342. //config.AccMask = 0x07;
  343. config.Filter = 0x03;//只接收符合要求的扩展帧
  344. }
  345. //波特率设置为250K
  346. switch (comboBox_BoardIndex.Text)
  347. {
  348. case "250K":
  349. config.Timing0 = 0x01;
  350. config.Timing1 = 0x1C;
  351. break;
  352. case "500K":
  353. config.Timing0 = 0x00;
  354. config.Timing1 = 0x1C;
  355. break;
  356. default: //250K
  357. config.Timing0 = 0x01;
  358. config.Timing1 = 0x1C;
  359. break;
  360. }
  361. //config.Filter = 0x00;//接收所有报文
  362. config.Mode = (Byte)0x00; //正常工作模式
  363. VCI_InitCAN(m_devtype, m_devind, m_canind, ref config);
  364. }
  365. button_StartCAN.Text = buttStartCan == true ? "停止CAN" : "启动CAN";
  366. button_StartCAN.BackColor = buttStartCan == true ? Color.GreenYellow : SystemColors.Control;
  367. if (buttStartCan == false)
  368. {
  369. VCI_ResetCAN(m_devtype, m_devind, m_canind);
  370. comboBox_devtype.Enabled = true;
  371. comboBox_CANIndex.Enabled = true;
  372. comboBox_DeviceIndex.Enabled = true;
  373. comboBox_BoardIndex.Enabled = true;
  374. comboBox_MsgType.Enabled = true;
  375. timer_rec.Enabled = false;
  376. timer_send.Enabled = false;
  377. //comboBox_ControllerChoose.Enabled = true;
  378. return;
  379. }
  380. VCI_StartCAN(m_devtype, m_devind, m_canind);
  381. comboBox_devtype.Enabled = false;
  382. comboBox_CANIndex.Enabled = false;
  383. comboBox_DeviceIndex.Enabled = false;
  384. comboBox_BoardIndex.Enabled = false;
  385. comboBox_MsgType.Enabled = false;
  386. timer_rec.Interval = 10;
  387. timer_send.Interval = 100;
  388. timer_rec.Enabled = true;
  389. timer_send.Enabled = true;
  390. //comboBox_ControllerChoose.Enabled = false;
  391. }
  392. private void timer_rec_Tick(object sender, EventArgs e)
  393. {
  394. if (receCount == 0)
  395. {
  396. uint res = VCI_GetReceiveNum(m_devtype, m_devind, m_canind);
  397. if (res > 0)
  398. {
  399. receobj = new VCI_CAN_OBJ[20];
  400. receCount = 0;
  401. receCount = VCI_Receive(m_devtype, m_devind, m_canind, ref receobj[0], 15, 0);
  402. if (receCount == 0xFFFFFFFF)
  403. {
  404. receCount = 0;
  405. }
  406. for (int i = 0; i < receCount; i++)
  407. {
  408. //strCanMsg += CANMsgRecord(receobj[i], "rx");
  409. byte[] tmp = new byte[8];
  410. CANRec(receobj[i].ID, receobj[i]);
  411. }
  412. receCount = 0;
  413. }
  414. else
  415. {
  416. }
  417. }
  418. }
  419. private void timer_send_Tick(object sender, EventArgs e)
  420. {
  421. VCI_CAN_OBJ sendObj = new VCI_CAN_OBJ();
  422. CANTx(0x1802F3D0, sendObj);
  423. CANTx(0x18F5C13A, sendObj);
  424. CANTx(0x18FF42D8, sendObj);
  425. CANTx(0x18FFCBF3, sendObj);
  426. CANTx(0x18FFF8A7, sendObj);
  427. }
  428. void CANTx(UInt32 ID, VCI_CAN_OBJ sendObj)
  429. {
  430. sendObj.ID = ID;
  431. sendObj.ExternFlag = 0X01;
  432. sendObj.DataLen = 0x08;
  433. unsafe
  434. {
  435. for (int i = 0; i < 8; i++)
  436. {
  437. sendObj.Data[i] = 0;
  438. }
  439. switch (ID)
  440. {
  441. //vcu
  442. case 0x1802F3D0:
  443. int VCU_V2B_CMD_Checksum = 0;
  444. int VCU_BMSHVOnOffReq = 0;
  445. int VCU_VehSpd = 0;
  446. int VCU_BMSCutOffLV = 0;
  447. int VCU_AllowChgCtrl = 0;
  448. VCU_BMSHVOnOffReq = comboBox_VCU_BMSHVOnOffReq.SelectedIndex;
  449. sendObj.Data[1] = (byte)((((VCU_V2B_CMD_AliveConter >> 0) & 0xF) << 0) | (((VCU_BMSHVOnOffReq >> 0) & 0x3) << 4));
  450. VCU_VehSpd = Convert.ToInt32(numericUpDown_VCU_VehSpd.Value);
  451. sendObj.Data[2] = (byte)(((VCU_VehSpd >> 0) & 0xFF) << 0);
  452. VCU_AllowChgCtrl = comboBox_VCU_AllowChgCtrl.SelectedIndex;
  453. VCU_BMSCutOffLV = comboBox_VCU_BMSCutOffLV.SelectedIndex;
  454. sendObj.Data[7] = (byte)((((VCU_BMSCutOffLV >> 0) & 0x1) << 0) | ((VCU_AllowChgCtrl >> 0) & 0x3) << 1);
  455. for (int i = 1; i < 8; i++)
  456. {
  457. VCU_V2B_CMD_Checksum ^= sendObj.Data[i];
  458. }
  459. sendObj.Data[0] = (byte)(((VCU_V2B_CMD_Checksum >> 0) & 0xFF) << 0);
  460. if (++VCU_V2B_CMD_AliveConter >= 15)
  461. VCU_V2B_CMD_AliveConter = 0;
  462. break;
  463. //tms
  464. case 0x18F5C13A:
  465. int BTMS_WorkSts = 0;
  466. int BTMS_ConnStsFb = 0;
  467. int BTMS_BattPackInCoolTemp = 0;
  468. int BTMS_BattPackoutCoolTemp = 0;
  469. int BTMS_ActPower = 0;
  470. int BTMS_DTC = 0;
  471. int BTMS_FltLevel = 0;
  472. BTMS_WorkSts = comboBox_BTMS_WorkSts.SelectedIndex;
  473. BTMS_ConnStsFb = comboBox_BTMS_ConnStsFb.SelectedIndex;
  474. BTMS_BattPackInCoolTemp = Convert.ToByte(numericUpDown_BTMS_BattPackInCoolTemp.Value + 40);
  475. BTMS_BattPackoutCoolTemp = Convert.ToByte(numericUpDown_BTMS_BattPackoutCoolTemp.Value + 40);
  476. BTMS_ActPower = Convert.ToInt32(numericUpDown_BTMS_ActPower.Value * 10);
  477. BTMS_DTC = Convert.ToByte(numericUpDown_BTMS_DTC.Value);
  478. BTMS_FltLevel = comboBox_BTMS_FltLevel.SelectedIndex;
  479. sendObj.Data[0] = (byte)((((BTMS_WorkSts >> 0) & 0x3) << 0) | (((BTMS_ConnStsFb >> 0) & 0xF) << 2));
  480. sendObj.Data[1] = (byte)(((BTMS_BattPackInCoolTemp >> 0) & 0xFF) << 0);
  481. sendObj.Data[2] = (byte)(((BTMS_BattPackoutCoolTemp >> 0) & 0xFF) << 0);
  482. sendObj.Data[5] = (byte)(((BTMS_ActPower >> 0) & 0xFF) << 0);
  483. sendObj.Data[6] = (byte)(((BTMS_ActPower >> 8) & 0xFF) << 0);
  484. sendObj.Data[7] = (byte)((((BTMS_DTC >> 0) & 0x3F) << 0) | (((BTMS_FltLevel >> 0) & 0x3) << 6));
  485. break;
  486. case 0x18FF42D8:
  487. /*
  488. sendObj.Data[0] = (byte)(((TBOX_Second >> 0) & 0xFF) << 0);
  489. sendObj.Data[1] = (byte)(((TBOX_Minute >> 0) & 0xFF) << 0);
  490. sendObj.Data[2] = (byte)(((TBOX_Hour >> 0) & 0xFF) << 0);
  491. sendObj.Data[3] = (byte)(((TBOX_Day >> 0) & 0xFF) << 0);
  492. sendObj.Data[4] = (byte)(((TBOX_Month >> 0) & 0xFF) << 0);
  493. sendObj.Data[5] = (byte)(((TBOX_Year >> 0) & 0xFF) << 0);*/
  494. break;
  495. //rcb
  496. case 0x18FFCBF3:
  497. UInt16 RCB_encryp1 = (UInt16)BMS_encryp1;
  498. UInt16 RCB_encryp2 = (UInt16)BMS_encryp2;
  499. UInt16 RCB_encryp3 = (UInt16)BMS_encryp3;
  500. UInt16 RCB_encryp4 = (UInt16)BMS_encryp4;
  501. if(comboBox_encryptionEnable.SelectedIndex == 0)
  502. {
  503. RCB_encryp1 = encryptionAlgorithm(RCB_encryp1);
  504. RCB_encryp2 = encryptionAlgorithm(RCB_encryp2);
  505. RCB_encryp3 = encryptionAlgorithm(RCB_encryp3);
  506. RCB_encryp4 = encryptionAlgorithm(RCB_encryp4);
  507. }
  508. sendObj.Data[0] = (byte)(((RCB_encryp1 >> 0) & 0xFF) << 0);
  509. sendObj.Data[1] = (byte)(((RCB_encryp1 >> 8) & 0xFF) << 0);
  510. sendObj.Data[2] = (byte)(((RCB_encryp2 >> 0) & 0xFF) << 0);
  511. sendObj.Data[3] = (byte)(((RCB_encryp2 >> 8) & 0xFF) << 0);
  512. sendObj.Data[4] = (byte)(((RCB_encryp3 >> 0) & 0xFF) << 0);
  513. sendObj.Data[5] = (byte)(((RCB_encryp3 >> 8) & 0xFF) << 0);
  514. sendObj.Data[6] = (byte)(((RCB_encryp4 >> 0) & 0xFF) << 0);
  515. sendObj.Data[7] = (byte)(((RCB_encryp4 >> 8) & 0xFF) << 0);
  516. break;
  517. //EBC
  518. case 0x18FFF8A7:
  519. int LockingPinStsFB = 0;
  520. int Change_BattConSts = 0;
  521. int Message_Checksum = 0;
  522. Message_Checksum = Message_Counter;
  523. LockingPinStsFB = comboBox_LockingPinStsFB.SelectedIndex;
  524. Change_BattConSts = comboBox_Change_BattConSts.SelectedIndex;
  525. sendObj.Data[1] = (byte)((((LockingPinStsFB >> 0) & 0x3) << 0) | (((Change_BattConSts >> 0) & 0x3) << 2));
  526. sendObj.Data[7] = (byte)((((Message_Counter >> 0) & 0xF) << 0) | (((Message_Checksum >> 0) & 0xF) << 4));
  527. if (++Message_Counter >= 15)
  528. Message_Counter = 0;
  529. break;
  530. default:
  531. break;
  532. }
  533. VCI_Transmit(m_devtype, m_devind, m_canind, ref sendObj, 1);
  534. }
  535. }
  536. int BMS_encryp1 = 0;
  537. int BMS_encryp2 = 0;
  538. int BMS_encryp3 = 0;
  539. int BMS_encryp4 = 0;
  540. void CANRec(UInt32 ID, VCI_CAN_OBJ sendObj)
  541. {
  542. unsafe
  543. {
  544. switch (ID)
  545. {
  546. case 0x1801D0F3:
  547. string[] strs_BMS_CutOffHVReq = { "预留 ","请求下高压","不请求下高压","无效 "};
  548. int BMS_CutOffHVReq = (byte)((((sendObj.Data[0] >> 2) & 0x3) << 0)); //是否请求下高压
  549. BMS_CutOffHVReq = BMS_CutOffHVReq < strs_BMS_CutOffHVReq.Length ? BMS_CutOffHVReq : strs_BMS_CutOffHVReq.Length - 1;
  550. textBox_BMS_CutOffHVReq.Text = strs_BMS_CutOffHVReq[BMS_CutOffHVReq];
  551. //int BMS_PmtCutoffLVFb = (byte)((((sendObj.Data[0]>>4)&0x3)<<0)); //BMS允许下低压
  552. //int BMS_EmergCutoffHVReq = (byte)((((sendObj.Data[0]>>6)&0x3)<<0)); //BMS紧急下高压请求
  553. //int BMS_HeatNegRelaySts = (byte)((((sendObj.Data[1]>>0)&0x3)<<0)); //加热负继电器状态
  554. // int BMS_HeatPosRelaySts = (byte)((((sendObj.Data[1]>>2)&0x3)<<0)); //加热正继电器状态
  555. //int BMS_SelfChkSts = (byte)((((sendObj.Data[1]>>4)&0x3)<<0)); //BMS自检状态
  556. break;
  557. case 0x1880D0F3:
  558. /*
  559. int BMS_BattSysNum = (byte)((((sendObj.Data[0]>>0)&0xF)<<0)); //可充电装置系统序号
  560. int BMS_MainPosRelayWeldedFlt = (byte)((((sendObj.Data[0]>>4)&0x1)<<0)); //主正继电器粘连故障
  561. int BMS_MainNegRelayWeldedFlt = (byte)((((sendObj.Data[0]>>5)&0x1)<<0)); //主负继电器粘连故障
  562. int BMS_ChgPosWeldedFlt1 = (byte)((((sendObj.Data[0]>>6)&0x1)<<0)); //充电正1继电器粘连故障
  563. int BMS_ChgNegWeldedFlt1 = (byte)((((sendObj.Data[0]>>7)&0x1)<<0)); //充电负1继电器粘连故障
  564. int BMS_ChgPosWeldedFlt2 = (byte)((((sendObj.Data[1]>>0)&0x1)<<0)); //充电正2继电器粘连故障
  565. int BMS_ChgNegWeldedFlt2 = (byte)((((sendObj.Data[1]>>1)&0x1)<<0)); //充电负2继电器粘连故障
  566. int BMS_HeatNegWeldedFlt = (byte)((((sendObj.Data[1]>>2)&0x1)<<0)); //加热负继电器粘连故障
  567. int BMS_HeatPosWeldedFlt1 = (byte)((((sendObj.Data[1]>>3)&0x1)<<0)); //加热正继电器粘连故障
  568. */
  569. string[] BMS_ConnSts = { "预留" , "开启" ,"闭合" , "无效" };
  570. int BMS_MainPosConnSts = (byte)((((sendObj.Data[1] >> 4) & 0x3) << 0)); //主正继电器状态反馈
  571. int BMS_MainNegConnSts = (byte)((((sendObj.Data[1] >> 6) & 0x3) << 0)); //主ds负继电器状态反馈
  572. int BMS_PreChgConnSts = (byte)((((sendObj.Data[2] >> 0) & 0x3) << 0)); //预充继电器状态反馈
  573. int BMS_ChgPosConnSts1 = (byte)((((sendObj.Data[2] >> 2) & 0x3) << 0)); //充电正1继电器状态
  574. int BMS_ChgNegConnSts1 = (byte)((((sendObj.Data[2] >> 4) & 0x3) << 0)); //充电负1继电器状态
  575. int BMS_ChgPosConnSts2 = (byte)((((sendObj.Data[2] >> 6) & 0x3) << 0)); //充电正2继电器状态
  576. int BMS_ChgNegConnSts2 = (byte)((((sendObj.Data[3] >> 0) & 0x3) << 0)); //充电负2继电器状态
  577. BMS_MainPosConnSts = BMS_MainPosConnSts < BMS_ConnSts.Length ? BMS_MainPosConnSts : BMS_ConnSts.Length - 1;
  578. BMS_MainNegConnSts = BMS_MainNegConnSts < BMS_ConnSts.Length ? BMS_MainNegConnSts : BMS_ConnSts.Length - 1;
  579. BMS_ChgPosConnSts1 = BMS_ChgPosConnSts1 < BMS_ConnSts.Length ? BMS_ChgPosConnSts1 : BMS_ConnSts.Length - 1;
  580. BMS_PreChgConnSts = BMS_PreChgConnSts < BMS_ConnSts.Length ? BMS_PreChgConnSts : BMS_ConnSts.Length - 1;
  581. BMS_ChgNegConnSts1 = BMS_ChgNegConnSts1 < BMS_ConnSts.Length ? BMS_ChgNegConnSts1 : BMS_ConnSts.Length - 1;
  582. BMS_ChgPosConnSts2 = BMS_ChgPosConnSts2 < BMS_ConnSts.Length ? BMS_ChgPosConnSts2 : BMS_ConnSts.Length - 1;
  583. BMS_ChgNegConnSts2 = BMS_ChgNegConnSts2 < BMS_ConnSts.Length ? BMS_ChgNegConnSts2 : BMS_ConnSts.Length - 1;
  584. textBox_BMS_MainPosConnSts.Text = BMS_ConnSts[BMS_MainPosConnSts];
  585. textBox_BMS_MainNegConnSts.Text = BMS_ConnSts[BMS_MainNegConnSts];
  586. textBox_BMS_PreChgConnSts.Text = BMS_ConnSts[BMS_PreChgConnSts];
  587. textBox_BMS_ChgPosConnSts1.Text = BMS_ConnSts[BMS_ChgPosConnSts1];
  588. textBox_BMS_ChgNegConnSts1.Text = BMS_ConnSts[BMS_ChgNegConnSts1];
  589. textBox_BMS_ChgPosConnSts2.Text = BMS_ConnSts[BMS_ChgPosConnSts2];
  590. textBox_BMS_ChgNegConnSts2.Text = BMS_ConnSts[BMS_ChgNegConnSts2];
  591. int BMS_ErrorCode = (byte)((((sendObj.Data[7] >> 0) & 0xFF) << 0)); //电池系统故障码
  592. textBox_BMS_ErrorCode.Text = BMS_ErrorCode.ToString();
  593. /*
  594. int BMS_BranchCircuitFlt = (byte)((((sendObj.Data[3]>>3)&0x1)<<0)); //支路断路故障
  595. int BMS_ChgCircuitOverLimtFlt = (byte)((((sendObj.Data[3]>>4)&0x3)<<0)); //回充电流超限故障
  596. int BMS_MainPosNotConnFlt = (byte)((((sendObj.Data[3]>>6)&0x1)<<0)); //主正继电器无法闭合报警
  597. int BMS_MainNegNotConnFlt = (byte)((((sendObj.Data[3]>>7)&0x1)<<0)); //主负继电器无法闭合报警
  598. int BMS_ChgPosNotConnFlt1 = (byte)((((sendObj.Data[4]>>0)&0x1)<<0)); //充电正1继电器无法闭合报警
  599. int BMS_ChgPosNotConnFlt2 = (byte)((((sendObj.Data[4]>>1)&0x1)<<0)); //充电正2继电器无法闭合报警
  600. int BMS_ChgNegNotConnFlt1 = (byte)((((sendObj.Data[4]>>2)&0x1)<<0)); //充电负1继电器无法闭合报警
  601. int BMS_ChgNegNotConnFlt2 = (byte)((((sendObj.Data[4]>>3)&0x1)<<0)); //充电负2继电器无法闭合报警
  602. int BMS_HeatBTMSConnNotOpenFlt = (byte)((((sendObj.Data[4]>>4)&0x1)<<0)); //加热膜或BTMS继电器无法断开故障
  603. int BMS_HeatBTMSNotConnFlt = (byte)((((sendObj.Data[4]>>5)&0x1)<<0)); //加热膜或 BTMS 继电器无法闭合故障
  604. int BMS_HeatMgSysFlt = (byte)((((sendObj.Data[4]>>6)&0x1)<<0)); //热管理系统故障
  605. int BMS_SupBattFlt = (byte)((((sendObj.Data[4]>>7)&0x1)<<0)); //BMS 24V供电异常报警
  606. int BMS_BattSelfProtAlm = (byte)((((sendObj.Data[5]>>0)&0x1)<<0)); //电池包自保护报警
  607. int BMS_PreChgRelayWeldedFlt = (byte)((((sendObj.Data[5]>>3)&0x1)<<0)); //预充继电器粘连故障
  608. int BMS_PreChgNotConnFlt = (byte)((((sendObj.Data[5]>>4)&0x1)<<0)); //预充继电器无法闭合报警
  609. int BMS_HeatPosNotConnFlt1 = (byte)((((sendObj.Data[5]>>5)&0x1)<<0)); //加热正继电器无法闭合故障
  610. int BMS_HeatNegNotConnFlt = (byte)((((sendObj.Data[5]>>6)&0x1)<<0)); //加热负继电器无法闭合故障
  611. int BMS_SysNum = (byte)((((sendObj.Data[6]>>0)&0xF)<<0)); //可充电储能子系统总数
  612. */
  613. break;
  614. case 0x1881D0F3:
  615. string[] strs_BMS_FaultLevel = { "无故障", "1级故障", "2级故障", "3级故障" };
  616. string[] sts_BMS_BattCurrentSts = { "高压开启", "预先充电", "高压关断", "高压上电故障" };
  617. int BMS_FaultLevel = (byte)((((sendObj.Data[2] >> 5) & 0x3) << 0)); //最高报警等级
  618. int BMS_GBT32960FltNum = (byte)((((sendObj.Data[7] >> 3) & 0x1F) << 0)); //故障数目
  619. int BMS_BattCurrentSts = (byte)((((sendObj.Data[1] >> 4) & 0x3) << 0)); //BMS当前工作状态
  620. BMS_FaultLevel = BMS_FaultLevel < strs_BMS_FaultLevel.Length ? BMS_FaultLevel : strs_BMS_FaultLevel.Length - 1;
  621. textBox_BMS_FaultLevel.Text = strs_BMS_FaultLevel[BMS_FaultLevel];
  622. textBox_BMS_GBT32960FltNum.Text = BMS_GBT32960FltNum.ToString();
  623. BMS_BattCurrentSts = BMS_BattCurrentSts < sts_BMS_BattCurrentSts.Length ? BMS_BattCurrentSts : sts_BMS_BattCurrentSts.Length - 1;
  624. textBox_BMS_BattCurrentSts.Text = sts_BMS_BattCurrentSts[BMS_BattCurrentSts];
  625. /*
  626. int BMS_B2V_ST1Checksum = (byte)((((sendObj.Data[0]>>0)&0xFF)<<0)); //校验
  627. int BMS_B2V_ST2AliveCounter = (byte)((((sendObj.Data[1]>>0)&0xF)<<0)); //计数
  628. int BMS_AssisConnSts = (byte)((((sendObj.Data[1]>>6)&0x1)<<0)); //附件继电器状态
  629. int BMS_BattEqualizationSts = (byte)((((sendObj.Data[1]>>7)&0x1)<<0)); //BMS当前均衡状态
  630. int BMS_CellTempDiffFault = (byte)((((sendObj.Data[3]>>0)&0x3)<<0)); //电芯温差异常报警
  631. int BMS_BattTempHighFault = (byte)((((sendObj.Data[3]>>2)&0x3)<<0)); //电芯温度过高报警
  632. int BMS_BattPackVolHighFault = (byte)((((sendObj.Data[3]>>4)&0x3)<<0)); //PACK过压报警
  633. int BMS_BattPackVolLowFault = (byte)((((sendObj.Data[3]>>6)&0x3)<<0)); //PACK欠压报警
  634. int BMS_BattSOCLowFault = (byte)((((sendObj.Data[4]>>0)&0x3)<<0)); //SOC过低报警
  635. int BMS_BattCellVolHighFault = (byte)((((sendObj.Data[4]>>2)&0x3)<<0)); //单体电压过高报警
  636. int BMS_BattCellVolLowFault = (byte)((((sendObj.Data[4]>>4)&0x3)<<0)); //单体电压欠压报警
  637. int BMS_BattIsolationFault = (byte)((((sendObj.Data[4]>>6)&0x3)<<0)); //绝缘报警
  638. int BMS_CellVolDiffFault = (byte)((((sendObj.Data[5]>>0)&0x3)<<0)); //单体压差过大
  639. int BMS_ChgCurrHighFlt = (byte)((((sendObj.Data[5]>>2)&0x3)<<0)); //充电电流过大报警
  640. int BMS_DisChgCurrHighFlt = (byte)((((sendObj.Data[5]>>4)&0x3)<<0)); //放电电流过大报警
  641. int BMS_BattTempLowFault = (byte)((((sendObj.Data[5]>>6)&0x3)<<0)); //电芯温度过低报警
  642. int BMS_BranchCircuitDiffFault = (byte)((((sendObj.Data[6]>>0)&0x3)<<0)); //支路压差过大报警
  643. int BMS_ST1_Flt_HW = (byte)((((sendObj.Data[6]>>2)&0x3)<<0)); //BMS 硬件故障
  644. int BMS_BattSOCHighFault = (byte)((((sendObj.Data[6]>>4)&0x1)<<0)); //SOC过高报警
  645. int BMS_SOCJumpFault = (byte)((((sendObj.Data[6]>>5)&0x1)<<0)); //SOC跳变报警
  646. int BMS_CANComFault = (byte)((((sendObj.Data[6]>>6)&0x1)<<0)); //BMS内部通讯故障
  647. int BMS_BattPackMatchFault = (byte)((((sendObj.Data[6]>>7)&0x1)<<0)); //BMS系统不匹配报警
  648. int BMS_ST1_Flt_HVIL = (byte)((((sendObj.Data[7]>>0)&0x1)<<0)); //高压互锁报警
  649. int BMS_SmokeAlarm = (byte)((((sendObj.Data[7]>>1)&0x1)<<0)); //烟雾报警
  650. int BMS_FireAlarm = (byte)((((sendObj.Data[7]>>2)&0x1)<<0)); //火灾报警
  651. */
  652. break;
  653. case 0x1882D0F3:
  654. int BMS_BattSOC = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //电池包SOC
  655. int BMS_BattSOH = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //电池包SOH
  656. int BMS_BattCurr = (UInt16)((((sendObj.Data[2] >> 0) & 0xFF) << 0) | (((sendObj.Data[3] >> 0) & 0xFF) << 8)); //动力电池组电流
  657. //int BMS_MaxPmtEnyRecoCurr = (UInt16)((((sendObj.Data[4]>>0)&0xFF)<<0)|(((sendObj.Data[5]>>0)&0xFF)<<8)); //电池包允许最大回充电电流值 (脉冲)
  658. int BMS_MaxPmtDischgCurr = (UInt16)((((sendObj.Data[6] >> 0) & 0xFF) << 0) | (((sendObj.Data[7] >> 0) & 0xFF) << 8)); //电池包允许最大放电电流值(脉冲)
  659. textBox_BMS_BattSOC.Text = ((BMS_BattSOC + 0.0) * 0.4).ToString("F2");
  660. textBox_BMS_BattSOH.Text = ((BMS_BattSOH + 0.0) * 0.4).ToString("F2");
  661. textBox_BMS_BattCurr.Text = ((BMS_BattCurr + 0.0) * 0.1 - 2000.0).ToString("F2");
  662. textBox_BMS_MaxPmtDischgCurr.Text = ((BMS_MaxPmtDischgCurr + 0.0) * 0.1).ToString();
  663. break;
  664. case 0x1883D0F3:
  665. int BMS_PosIsolationRes = (UInt16)((((sendObj.Data[0] >> 0) & 0xFF) << 0) | (((sendObj.Data[1] >> 0) & 0xFF) << 8)); //电池包正极绝缘值
  666. int BMS_NegIsolationRes = (UInt16)((((sendObj.Data[2] >> 0) & 0xFF) << 0) | (((sendObj.Data[3] >> 0) & 0xFF) << 8)); //电池包负极绝缘值
  667. int BMS_BattTermVolINMainPos = (UInt16)((((sendObj.Data[4] >> 0) & 0xFF) << 0) | (((sendObj.Data[5] >> 0) & 0xFF) << 8)); //主正继电器内侧电池端电压 总压
  668. int BMS_BattBusVolOutMainPos = (UInt16)((((sendObj.Data[6] >> 0) & 0xFF) << 0) | (((sendObj.Data[7] >> 0) & 0xFF) << 8)); //主正继电器外侧母线电压
  669. textBox_BMS_PosIsolationRes.Text = ((BMS_PosIsolationRes)).ToString();
  670. textBox_BMS_NegIsolationRes.Text = ((BMS_NegIsolationRes)).ToString();
  671. textBox_BMS_BattTermVolINMainPos.Text = ((BMS_BattTermVolINMainPos + 0.0) * 0.1).ToString("F2");
  672. textBox_BMS_BattBusVolOutMainPos.Text = ((BMS_BattBusVolOutMainPos + 0.0) * 0.1).ToString("F2");
  673. break;
  674. case 0x1884D0F3:
  675. int BMS_BattMaxTemp = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //电芯温度最大值
  676. int BMS_BattMinTemp = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //电芯温度最小值
  677. textBox_BMS_BattMaxTemp.Text = (BMS_BattMaxTemp - 40).ToString();
  678. textBox_BMS_BattMinTemp.Text = (BMS_BattMinTemp - 40).ToString();
  679. /*int BMS_Cell_Avg_Temp = (byte)((((sendObj.Data[2]>>0)&0xFF)<<0)); //电芯温度平均值
  680. int BMS_MaxTemp1PackNum = (byte)((((sendObj.Data[3]>>0)&0xFF)<<0)); //电芯温度最大值所在CSC编号
  681. int BMS_MaxTemp1SnsNum = (byte)((((sendObj.Data[4]>>0)&0xFF)<<0)); //电芯温度最大值所在CSC内温度探针编号
  682. int BMS_MinTemp1PackNum = (byte)((((sendObj.Data[5]>>0)&0xFF)<<0)); //电芯温度最小值所在CSC内温度探针编号
  683. int BMS_MinTemp1SnsNum = (byte)((((sendObj.Data[6]>>0)&0xFF)<<0)); //电芯温度最小值所在CSC内温度探针编号*/
  684. break;
  685. case 0x1885D0F3:
  686. int BMS_MaxCellVolt = (UInt16)((((sendObj.Data[0] >> 0) & 0xFF) << 0) | (((sendObj.Data[1] >> 0) & 0xFF) << 8)); //电芯电压值最大值
  687. /*int BMS_MaxCellVoltPackNum = (byte)((((sendObj.Data[2]>>0)&0xFF)<<0)); //电芯电压最大值所在CSC编号
  688. int BMS_MaxCellVoltSnsNum = (byte)((((sendObj.Data[3]>>0)&0xFF)<<0)); //电芯电压最大值所在CSC内单体编号
  689. int BMS_Cell_Avg_Volt = (UInt16)((((sendObj.Data[4]>>0)&0xFF)<<0)|(((sendObj.Data[5]>>0)&0xFF)<<8)); //电芯电压值平均值*/
  690. textBox_BMS_MaxCellVolt.Text = ((BMS_MaxCellVolt + 0.0) * 0.001).ToString("F3");
  691. break;
  692. case 0x1886D0F3:
  693. int BMS_MinCellVolt = (UInt16)((((sendObj.Data[0] >> 0) & 0xFF) << 0) | (((sendObj.Data[1] >> 0) & 0xFF) << 8)); //电芯电压值最小值
  694. //int BMS_MinCellVoltSnsNum = (byte)((((sendObj.Data[2]>>0)&0xFF)<<0)); //电芯电压最小值所在CSC内单体编号
  695. //int BMS_MinCellVoltPackNum = (byte)((((sendObj.Data[3]>>0)&0xFF)<<0)); //电芯电压最小值所在CSC编号
  696. textBox_BMS_MinCellVolt.Text = ((BMS_MinCellVolt + 0.0) * 0.001).ToString("F3");
  697. break;
  698. case 0x1888D0F3:
  699. //int BMS_BattTermVolOutMainPos = (UInt16)((((sendObj.Data[0]>>0)&0xFF)<<0)|(((sendObj.Data[1]>>0)&0xFF)<<8)); //主正继电器外侧电池端电压
  700. //int BMS_BattTermVolOutMainNeg = (UInt16)((((sendObj.Data[2]>>0)&0xFF)<<0)|(((sendObj.Data[3]>>0)&0xFF)<<8)); //主负继电器外侧电池端电压
  701. string[] strs_BMS_DCChgPlugSts = { "未连接", "仅充电口A连接", "仅充电口B连接", "充电口A和B充都连接", "ERROR"};
  702. string[] strs_BMS_ChgSts = { "可以充电", "正在充电", "充电结束", "充电故障" , "ERROR"};
  703. string[] strs_BMS_CnctSt = { "车", "站" , "ERROR"};
  704. string[] strs_BMS_chrgIReq = { "30s", "60s" , "ERROR"};
  705. int BMS_DCChgPlugSts = (byte)((((sendObj.Data[4] >> 0) & 0x7) << 0)); //充电枪连接状态
  706. int BMS_ChgSts = (byte)((((sendObj.Data[4] >> 5) & 0x7) << 0)); //充电状态
  707. //int BMS_ChgMode = (byte)((((sendObj.Data[4]>>3)&0x3)<<0)); //充电模式
  708. int BMS_CnctSt = (byte)((((sendObj.Data[5] >> 4) & 0x1) << 0)); //BMS连接状态
  709. //int BMS_BattPulseTime = (byte)((((sendObj.Data[5]>>5)&0x7)<<0)); //脉冲时间
  710. int BMS_chrgIReq = (UInt16)((((sendObj.Data[6] >> 0) & 0xFF) << 0) | (((sendObj.Data[7] >> 0) & 0xFF) << 8)); //充电需求电流
  711. BMS_DCChgPlugSts = BMS_DCChgPlugSts < strs_BMS_DCChgPlugSts.Length ? BMS_DCChgPlugSts : strs_BMS_DCChgPlugSts.Length - 1;
  712. textBox_BMS_DCChgPlugSts.Text = strs_BMS_DCChgPlugSts[BMS_DCChgPlugSts];
  713. BMS_ChgSts = BMS_ChgSts < strs_BMS_ChgSts.Length ? BMS_ChgSts : strs_BMS_ChgSts.Length - 1;
  714. textBox_BMS_ChgSts.Text = strs_BMS_ChgSts[BMS_ChgSts];
  715. BMS_CnctSt = BMS_CnctSt < strs_BMS_CnctSt.Length ? BMS_CnctSt : strs_BMS_CnctSt.Length - 1;
  716. textBox_BMS_CnctSt.Text = strs_BMS_CnctSt[BMS_CnctSt];
  717. textBox_BMS_chrgIReq.Text = ((BMS_chrgIReq + 0.0) * 0.1 - 2000).ToString("F2"); ;
  718. break;
  719. case 0x18C1D0F3:
  720. int BMS_CellVolMsgCode = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //帧序号
  721. int BMS_CellVolCSCNum = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //CSC 编号
  722. int BMS_CellVolt1 = (UInt16)((((sendObj.Data[2] >> 0) & 0xFF) << 0) | (((sendObj.Data[3] >> 0) & 0xFF) << 8)); //单体电池电压(V1)
  723. int BMS_CellVolt2 = (UInt16)((((sendObj.Data[4] >> 0) & 0xFF) << 0) | (((sendObj.Data[5] >> 0) & 0xFF) << 8)); //单体电池电压(V2)
  724. int BMS_CellVolt3 = (UInt16)((((sendObj.Data[6] >> 0) & 0xFF) << 0) | (((sendObj.Data[7] >> 0) & 0xFF) << 8)); //单体电池电压(V3)
  725. int[] bmsValue = { BMS_CellVolt1, BMS_CellVolt2, BMS_CellVolt3 };
  726. if (BMS_CellVolMsgCode < ((SubBoardsNUM * P_ALL_U_NUM) / 3))
  727. {
  728. for (int i = 0; i < 3; i++)
  729. {
  730. textboxs_U[BMS_CellVolMsgCode * 3 + i].Text = (((bmsValue[i] + 0.0) * 0.001)).ToString("F3");
  731. }
  732. }
  733. else if(BMS_CellVolMsgCode < (SubBoardsNUM * P_ALL_U_NUM) / 3 + (((SubBoardsNUM * P_ALL_U_NUM)) % 3 > 0 ? 1 : 0))
  734. {
  735. for(int i = 0; i < (((SubBoardsNUM * P_ALL_U_NUM)) % 3); i++)
  736. {
  737. textboxs_U[((SubBoardsNUM * P_ALL_U_NUM) / 3 * 3) + i].Text = (((bmsValue[i] + 0.0) * 0.001)).ToString("F3");
  738. }
  739. }
  740. //int BCUCellU[BMS_CellVolMsgCode * 3 - 3]=BMS_CellVolt1*0.001;
  741. //int BCUCellU[BMS_CellVolMsgCode * 3 - 2]=BMS_CellVolt2*0.001;
  742. //int BCUCellU[BMS_CellVolMsgCode * 3 - 1]=BMS_CellVolt3*0.001;
  743. break;
  744. case 0x18C2D0F3:
  745. int BMS_TempMsgCode = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //帧序号
  746. int BMS_CSCNum = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //CSC 编号
  747. int BMS_BattTemp1 = (byte)((((sendObj.Data[2] >> 0) & 0xFF) << 0)); //温度探针1对应的温度值
  748. int BMS_BattTemp2 = (byte)((((sendObj.Data[3] >> 0) & 0xFF) << 0)); //温度探针2对应的温度值
  749. int BMS_BattTemp3 = (byte)((((sendObj.Data[4] >> 0) & 0xFF) << 0)); //温度探针3对应的温度值
  750. int BMS_BattTemp4 = (byte)((((sendObj.Data[5] >> 0) & 0xFF) << 0)); //温度探针4对应的温度值
  751. int BMS_BattTemp5 = (byte)((((sendObj.Data[6] >> 0) & 0xFF) << 0)); //温度探针5对应的温度值
  752. int BMS_BattTemp6 = (byte)((((sendObj.Data[7] >> 0) & 0xFF) << 0)); //温度探针6对应的温度值
  753. int[] tempValue = { BMS_BattTemp1, BMS_BattTemp2, BMS_BattTemp3, BMS_BattTemp4, BMS_BattTemp5, BMS_BattTemp6 };
  754. if (BMS_TempMsgCode < ((SubBoardsNUM * P_ALL_T_NUM) / 6))
  755. {
  756. for (int i = 0; i < 6; i++)
  757. {
  758. textboxs_T[BMS_TempMsgCode * 6 + i].Text = (tempValue[i] - 40).ToString();
  759. }
  760. }
  761. else if (BMS_TempMsgCode < (SubBoardsNUM * P_ALL_T_NUM) / 6 + (((SubBoardsNUM * P_ALL_T_NUM)) % 6 > 0 ? 1 : 0))
  762. {
  763. for (int i = 0; i < (((SubBoardsNUM * P_ALL_T_NUM)) % 6); i++)
  764. {
  765. textboxs_T[((SubBoardsNUM * P_ALL_T_NUM) / 6 * 6) + i].Text = (tempValue[i] - 40).ToString();
  766. }
  767. }
  768. // int BCUModT[BMS_TempMsgCode * 6 - 6]=BMS_BattTemp1-40;
  769. // int BCUModT[BMS_TempMsgCode * 6 - 5]=BMS_BattTemp1-40;
  770. // int BCUModT[BMS_TempMsgCode * 6 - 4]=BMS_BattTemp1-40;
  771. // int BCUModT[BMS_TempMsgCode * 6 - 3]=BMS_BattTemp1-40;
  772. // int BCUModT[BMS_TempMsgCode * 6 - 2]=BMS_BattTemp1-40;
  773. // int BCUModT[BMS_TempMsgCode * 6 - 1]=BMS_BattTemp1-40;
  774. break;
  775. case 0x18F4D0F3:
  776. /*int BMS_SingleChgEnergy = (UInt16)((((sendObj.Data[0]>>0)&0xFF)<<0)|(((sendObj.Data[1]>>0)&0xFF)<<8)); //单次充电电量(充电枪插入)
  777. int BMS_SingleDisChgEny = (UInt16)((((sendObj.Data[2]>>0)&0xFF)<<0)|(((sendObj.Data[3]>>0)&0xFF)<<8)); //单次放电电量
  778. int BMS_SingleEnergy = (UInt16)((((sendObj.Data[4]>>0)&0xFF)<<0)|(((sendObj.Data[5]>>0)&0xFF)<<8)); //单次充电电量(制动能量回收)*/
  779. break;
  780. case 0x18FEF8F3:
  781. /*int BMS_ConTempDC1Pos = (byte)((((sendObj.Data[0]>>0)&0xFF)<<0)); //行车换电连接器功率端子DC1+的温度
  782. int BMS_ConTempDC1Neg = (byte)((((sendObj.Data[1]>>0)&0xFF)<<0)); //行车换电连接器功率端子DC1-的温度
  783. int BMS_ConTempDC2Pos = (byte)((((sendObj.Data[2]>>0)&0xFF)<<0)); //行车换电连接器功率端子DC2+的温度
  784. int BMS_ConTempDC2Neg = (byte)((((sendObj.Data[3]>>0)&0xFF)<<0)); //行车换电连接器功率端子DC2-的温度
  785. int BMS_ChgConTempDC1Pos = (byte)((((sendObj.Data[4]>>0)&0xFF)<<0)); //充电换电连接器功率端子DC1+的温度
  786. int BMS_ChgConTempDC1Neg = (byte)((((sendObj.Data[5]>>0)&0xFF)<<0)); //充电换电连接器功率端子DC1-的温度
  787. int BMS_ChgConTempDC2Pos = (byte)((((sendObj.Data[6]>>0)&0xFF)<<0)); //充电换电连接器功率端子DC2+的温度
  788. int BMS_ChgConTempDC2Neg = (byte)((((sendObj.Data[7]>>0)&0xFF)<<0)); //充电换电连接器功率端子DC2-的温度*/
  789. break;
  790. case 0x18FFF3CB:
  791. BMS_encryp1 = (byte)((((sendObj.Data[0] >> 0) & 0xFF) << 0)); //BMS认证数据1
  792. BMS_encryp2 = (byte)((((sendObj.Data[1] >> 0) & 0xFF) << 0)); //BMS认证数据2
  793. BMS_encryp3 = (byte)((((sendObj.Data[2] >> 0) & 0xFF) << 0)); //BMS认证数据3
  794. BMS_encryp4 = (byte)((((sendObj.Data[3] >> 0) & 0xFF) << 0)); //BMS认证数据4
  795. break;
  796. default:
  797. break;
  798. }
  799. }
  800. }
  801. int VCU_V2B_CMD_AliveConter = 0;
  802. UInt16 encryptionAlgorithm(UInt16 plainText)
  803. {
  804. UInt16 cipherText = 1;
  805. UInt32 privateKeyE = 207521;
  806. UInt16 privateKeyN = 54127;
  807. byte c = 1;
  808. plainText = (UInt16)(plainText % privateKeyN);
  809. while (privateKeyE > 0)
  810. {
  811. if (privateKeyE % 2 == 1)
  812. {
  813. cipherText = (UInt16)((cipherText * plainText) % privateKeyN);
  814. }
  815. privateKeyE = privateKeyE / 2;
  816. plainText = (UInt16)((plainText * plainText) % privateKeyN);
  817. c++;
  818. }
  819. return cipherText;
  820. }
  821. int Message_Counter = 0;
  822. void textChecker(object sender, KeyPressEventArgs e)
  823. { //判断输入是否符合规范
  824. if ((!char.IsDigit(e.KeyChar)) && e.KeyChar != 8 && e.KeyChar != (char)('.') && e.KeyChar != (char)('-'))
  825. {//允许输入数字、退格符、小数点、删除键和负号
  826. MessageBox.Show("请输入正确的数字");
  827. e.Handled = true;
  828. }
  829. if (e.KeyChar == (char)('-'))
  830. {
  831. if (Form.ActiveForm.ActiveControl.Text != "")
  832. {//这里的txt1需要改成应用处的TextBox的名称,或者可以给这个函数多传递一个参数,再在此处添加一个switch来判断
  833. MessageBox.Show("负号位置错误");
  834. e.Handled = true;
  835. }
  836. }
  837. if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
  838. {
  839. MessageBox.Show("第一位不能为小数点");
  840. e.Handled = true;
  841. }
  842. if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
  843. {
  844. MessageBox.Show("小数点只能输入一次");
  845. e.Handled = true;
  846. }
  847. if (e.KeyChar != (char)('.') && ((TextBox)sender).Text == "0" && (e.KeyChar != 8))
  848. {//这里要注意退格符是可以输入的
  849. MessageBox.Show("第一位是0,第二位必须为小数点");
  850. e.Handled = true;
  851. }
  852. if (((TextBox)sender).Text == "-" && e.KeyChar == (char)('.'))
  853. {
  854. MessageBox.Show("第一位是负号,第二位不能为小数点 ");
  855. e.Handled = true;
  856. }
  857. }
  858. }
  859. }