Exemplo n.º 1
0
        private void buttonSend_Click(object sender, EventArgs e)
        {
            if (usbCAN.IsOpen == false)
            {
                if (usbCAN.startDevice() == false)
                {
                    return;
                }
            }

            prepareFrame();
            if (SENDCOUNT <= 0)
            {
                return;
            }
            if (SENDCOUNT > 48)
            {
                MessageBox.Show("此处发送尽量满足准确的时间间隔,为保证要求选中帧不能超过48个。\n" +
                                "如需大于48帧可构造重放文件进行发送");
                return;
            }

            buttonSend.Enabled = false;

            if (threadSend != null)
            {
                threadSend.Abort();
            }
            threadSend = null;
            threadSend = new Thread(sendThreading);
            threadSend.Start();
        }
Exemplo n.º 2
0
        public bool startDevice()
        {
            if (usbCAN == null)
            {
                return(false);
            }

            return(usbCAN.startDevice());
        }
Exemplo n.º 3
0
        /*---------------------------------------------------------------------------------------------------*/
        public bool fetchStrSupported(byte externFlag)
        {
            if (usbCAN.startDevice() == false)
            {
                return(false);
            }

            for (int i = 0; i < arrStrSupported.Length; i++)
            {
                UDSServiceFormat uds = listOBD[0x20 * i];
                uds.format = externFlag;
                if (uds.format == 0)
                {
                    uds.address = 0x7DF;
                }
                else
                {
                    uds.address = 0x18DB33F1;
                }

                uds.expectedFrame = 0; //单帧

                UDSResponseList retClass = null;

                for (int reTry = 0; reTry < 10; reTry++)
                {
                    DateTime prev = DateTime.Now;
                    while ((DateTime.Now - prev).TotalMilliseconds < DELAY)
                    {
                        Application.DoEvents();
                    }

                    retClass = udsClass.getResponseList(uds);

                    if ((retClass.errorCode != UDSResponseList.ERRORCODE.SUCCEED) ||
                        (retClass.responseList.Count < 6) || (retClass.responseList[1] != uds.parameterList[0]))
                    {
                        continue;
                    }

                    break;
                }

                if ((retClass.errorCode != UDSResponseList.ERRORCODE.SUCCEED) ||
                    (retClass.responseList.Count < 6) || (retClass.responseList[1] != uds.parameterList[0]))
                {
                    MessageBox.Show("初始化超时,请重试\n或者尝试切换帧格式");
                    return(false);
                }

                //address赋值
                for (int g = 0x20 * i + 1; g < 0x20 * i + 0x20; g++)
                {
                    if (uds.format == 0)
                    {
                        listOBD[g].address = retClass.respAddress - 0x08;
                    }
                    else
                    {
                        UInt32 TASA = retClass.respAddress & 0x0000FFFF;
                        UInt32 addr = 0x18DA0000;

                        TASA = (TASA >> 8) | ((TASA << 8) & 0x0000FF00);
                        addr = addr | TASA;
                        listOBD[g].address = addr;
                    }

                    listOBD[g].expectedFrame = 0;
                }

                arrStrSupported[i] = "";
                for (int d = 0; d < 4; d++)
                {
                    arrStrSupported[i] += Convert.ToString(retClass.responseList[d + 2], 2).PadLeft(8, '0');
                }

                if (arrStrSupported[i][0x1f] == '0')
                {
                    for (int j = i + 1; j < arrStrSupported.Length; j++)
                    {
                        arrStrSupported[j] = "00000000000000000000000000000000";
                    }
                    break;
                }
            }

            if (usbCAN.shutDevice() == false)
            {
                return(false);
            }

            return(true);
        }
        private void buttonDSstep1_Click(object sender, EventArgs e)
        {
            groupBoxDSstep1.Enabled = false;

            int delay = 0, sUpper = 0;

            try
            {
                delay = Convert.ToInt32(textBoxdsStep1.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("收集时间输入错误");
                goto errorProcessing;
            }
            //
            try
            {
                sUpper = Convert.ToInt32(textBoxSILENCEUPPER.Text);
            }
            catch (Exception)
            {
                MessageBox.Show("静默状态数量输入错误");
                goto errorProcessing;
            }
            dsClass.SlienceUpper = sUpper;
            //
            if (usbCAN.shutDevice() == false)
            {
                goto errorProcessing;
            }
            //关闭了再清除
            dataGridViewshow.Rows.Clear();

            //!!
            usbCAN.ProcessingFrame = dsClass.saveData;
            //
            dsClass.Step = 0;
            dsClass.clearCANset();
            if (usbCAN.startDevice() == false)
            {
                goto errorProcessing;
            }

            DateTime dtPrev = DateTime.Now;

            while ((DateTime.Now - dtPrev).TotalMilliseconds < delay * 1000)
            {
                buttonDSstep1.Text = ((delay * 1000 - (DateTime.Now - dtPrev).TotalMilliseconds) / 1000).ToString("f2") + "s";
                Application.DoEvents();
            }
            buttonDSstep1.Text = "开始收集";

            if (usbCAN.shutDevice() == false)
            {
                goto errorProcessing;
            }
            dsClass.toFilter();

            groupBoxDSstep2.Enabled = true;
            return;

errorProcessing:
            groupBoxDSstep1.Enabled = true;
        }
        private void buttonStart_Click(object sender, EventArgs e)
        {
            int pointCount = 0;

            try { pointCount = Convert.ToInt32(textBoxPointCount.Text); }
            catch (Exception) { MessageBox.Show("请指定收集点个数"); return; }

            int udsInterval = 0;

            try { udsInterval = Convert.ToInt32(textBoxUdsInterval.Text); }
            catch (Exception) { MessageBox.Show("请指定指令发送间隔"); return; }
            //
            richTextBoxLog.Text    = "";
            buttonEnd.Enabled      = true;
            buttonStart.Enabled    = false;
            groupBoxResult.Enabled = false;
            rawPacket.Clear();
            hasGetUds = false;
            DateTime prev;

            for (int reqIndex = 0; reqIndex < listRequests.Count; reqIndex++)
            {
                if (usbCAN.startDevice() == false)
                {
                    goto endProcess;
                }

                udsCAN.createService(listRequests[reqIndex]);
                for (int cnt = pointCount; cnt > 0;)
                {
                    for (int reTry = 0; reTry < 10 && wantTerminate == false; reTry++)
                    {
                        prev = DateTime.Now;
                        while ((DateTime.Now - prev).TotalMilliseconds < DELAY)
                        {
                            Application.DoEvents();
                        }

                        hasGetUds = false;
                        usbCAN.sendFame(1);

                        prev = DateTime.Now;
                        while (hasGetUds == false && (DateTime.Now - prev).TotalMilliseconds < 1200)
                        {
                            Application.DoEvents();
                        }
                        if (hasGetUds == false)
                        {
                            continue;
                        }

                        break;
                    }

                    if (wantTerminate)
                    {
                        goto endProcess;
                    }

                    if (hasGetUds == false)
                    {
                        richTextBoxLog.AppendText("超时,请检查设备\n");
                    }
                    else
                    {
                        cnt--;
                        richTextBoxLog.AppendText(listRequests[reqIndex].description + ":剩余点个数 " + cnt.ToString() + "\n");
                    }

                    prev = DateTime.Now;
                    while ((DateTime.Now - prev).TotalMilliseconds < udsInterval)
                    {
                        Application.DoEvents();
                    }
                }

                //保存文件
                if (usbCAN.shutDevice() == false)
                {
                    goto endProcess;
                }

                string   path = Application.StartupPath + @"\dataPacket\";
                TimeSpan ts   = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                path += listRequests[reqIndex].description + Convert.ToUInt64(ts.TotalSeconds).ToString();
                FileStream   file = new FileStream(path, FileMode.Create);
                StreamWriter sw   = new StreamWriter(file);

                string line;
                for (int i = 0; i < rawPacket.Count; i++)
                {
                    line  = rawPacket[i].ID.ToString("X2") + " ";
                    line += rawPacket[i].DataLen.ToString() + " ";
                    for (int d = 0; d < rawPacket[i].DataLen; d++)
                    {
                        line += rawPacket[i].Data[d].ToString("X2") + " ";
                    }

                    sw.WriteLine(line);
                }

                sw.Close();
                file.Close();

                ANALYSISRESULT result = new ANALYSISRESULT();
                result.udsReq = listRequests[reqIndex];
                result.path   = path;
                analysisResults.Add(result);
                listBoxResult.Items.Add(result.udsReq.description);
            }

endProcess:
            buttonEnd.Enabled      = false;
            buttonStart.Enabled    = true;
            groupBoxResult.Enabled = true;
            wantTerminate          = false;
        }