void saveThreading(object saveParam) { SAVEPARAM param = (SAVEPARAM)saveParam; StreamWriter sw = param.sw; Form_ProgressBar form = param.bar; param.mrEvent.WaitOne(); string line = ""; for (int i = 0; i < dataGridViewshow.Rows.Count; i++) { line = ""; for (int l = 0; l <= 12; l++) { if (dataGridViewshow.Rows[i].Cells[l].Value != null) { line += dataGridViewshow.Rows[i].Cells[l].Value.ToString() + " "; } } sw.WriteLine(line); form.addValue(); } form.returnResult = DialogResult.OK; form.Invoke(new Action(() => { form.Close(); })); }
unsafe void fuzzingThread(object objParm) { FUZZINGPARM parm = (FUZZINGPARM)objParm; Form_ProgressBar form = parm.form; CAN_OBJ obj = parm.obj; int delay = parm.delay; byte index = parm.index; byte min = parm.min; byte max = parm.max; int rep = parm.rep; parm.mrEvent.WaitOne(); usbCAN.arrSendBuf[0].ID = obj.ID; usbCAN.arrSendBuf[0].DataLen = obj.DataLen; usbCAN.arrSendBuf[0].ExternFlag = obj.ExternFlag; usbCAN.arrSendBuf[0].RemoteFlag = obj.RemoteFlag; for (int d = 0; d < 8; d++) { usbCAN.arrSendBuf[0].Data[d] = obj.Data[d]; } for (int i = min; i <= max; i++) { for (int t = 0; t < rep; t++) { usbCAN.arrSendBuf[0].Data[index] = (byte)i; usbCAN.sendFame(1); Thread.Sleep(delay); } form.addValue(); } form.returnResult = DialogResult.OK; form.Invoke(new Action(() => { form.Close(); })); }
unsafe void replayThreading(object replayParm) { REPLAYPARAM parm = (REPLAYPARAM)replayParm; StreamReader sr = parm.sr; Form_ProgressBar form = parm.bar; parm.mrEvent.WaitOne(); string line = null; line = sr.ReadLine(); if (line == null) { goto endProcess; } Int64 timePrev, timeNow; string[] arr = line.Split(' '); try { usbCAN.arrSendBuf[0].ID = Convert.ToUInt32(arr[1], 16); } catch (Exception) { goto wrongFormat; } try { usbCAN.arrSendBuf[0].DataLen = Convert.ToByte(arr[2]); } catch (Exception) { goto wrongFormat; } try { for (int d = 0; d < 8; d++) { usbCAN.arrSendBuf[0].Data[d] = Convert.ToByte(arr[d + 3], 16); } } catch (Exception) { goto wrongFormat; } if (arr[11].Equals("扩展帧")) { usbCAN.arrSendBuf[0].ExternFlag = 1; } else if (arr[11].Equals("标准帧")) { usbCAN.arrSendBuf[0].ExternFlag = 0; } else { goto wrongFormat; } if (arr[12].Equals("远程帧")) { usbCAN.arrSendBuf[0].RemoteFlag = 1; } else if (arr[12].Equals("数据帧")) { usbCAN.arrSendBuf[0].RemoteFlag = 0; } else { goto wrongFormat; } try { timePrev = Convert.ToInt64(arr[0]); } catch (Exception) { goto wrongFormat; } usbCAN.sendFame(1); form.addValue(); while ((line = sr.ReadLine()) != null) { arr = line.Split(' '); try { timeNow = Convert.ToInt64(arr[0]); } catch (Exception) { goto wrongFormat; } try { usbCAN.arrSendBuf[0].ID = Convert.ToUInt32(arr[1], 16); } catch (Exception) { goto wrongFormat; } try { usbCAN.arrSendBuf[0].DataLen = Convert.ToByte(arr[2]); } catch (Exception) { goto wrongFormat; } try { for (int d = 0; d < 8; d++) { usbCAN.arrSendBuf[0].Data[d] = Convert.ToByte(arr[d + 3], 16); } } catch (Exception) { goto wrongFormat; } if (arr[11].Equals("扩展帧")) { usbCAN.arrSendBuf[0].ExternFlag = 1; } else if (arr[11].Equals("标准帧")) { usbCAN.arrSendBuf[0].ExternFlag = 0; } else { goto wrongFormat; } if (arr[12].Equals("远程帧")) { usbCAN.arrSendBuf[0].RemoteFlag = 1; } else if (arr[12].Equals("数据帧")) { usbCAN.arrSendBuf[0].RemoteFlag = 0; } else { goto wrongFormat; } Int64 delay = timeNow - timePrev; if (delay > 10) { Thread.Sleep(Convert.ToInt32(delay * 0.1)); } timePrev = timeNow; usbCAN.sendFame(1); form.addValue(); } endProcess: form.returnResult = DialogResult.OK; form.Invoke(new Action(() => { form.Close(); })); return; wrongFormat: form.returnResult = DialogResult.No; form.Invoke(new Action(() => { form.Close(); })); }