示例#1
0
 private void btSaveData_Click(object sender, EventArgs e)
 {
     DLLWork.IREn(1);
     Thread.Sleep(200);
     DLLWork.IRWork(1);
     DLLWork.IREn(0);
 }
示例#2
0
 private void ConnectForm_Shown(object sender, EventArgs e)
 {
     MainForm.serialPort          = new SerialPort();
     MainForm.serialPort.PortName = Properties.Settings.Default.SerialPortName;
     MainForm.serialPort.BaudRate = 115200;
     if (WFGlobal.OpenSerialPort(ref MainForm.serialPort, ""))
     {
         if (DLLWork.CheckDevice())
         {
             MainForm.bConnectedDevice = true;
             label1.Text        = "成功连接到硬件设备";
             progressBar1.Value = progressBar1.Maximum;
             WFGlobal.WaitMS(2000);
             this.Close();
             return;
         }
         else
         {
             MainForm.serialPort.Close();
         }
     }
     string[] ports = SerialPort.GetPortNames();
     Array.Sort(ports);
     progressBar1.Maximum = ports.Length - 1;
     progressBar1.Value   = 0;
     foreach (string port in ports)
     {
         Debug.WriteLine(port);
         progressBar1.PerformStep();
         WFGlobal.WaitMS(1);
         MainForm.serialPort.PortName = port;
         MainForm.serialPort.BaudRate = 115200;
         if (WFGlobal.OpenSerialPort(ref MainForm.serialPort, ""))
         {
             if (DLLWork.CheckDevice())
             {
                 Properties.Settings.Default.SerialPortName = port;
                 Properties.Settings.Default.Save();
                 MainForm.bConnectedDevice = true;
                 label1.Text        = "成功连接到硬件设备";
                 progressBar1.Value = progressBar1.Maximum;
                 WFGlobal.WaitMS(2000);
                 this.Close();
                 return;
             }
             else
             {
                 MainForm.serialPort.Close();
             }
         }
     }
     label1.Text = "未找到设备,请重新连接硬件设备";
     WFGlobal.WaitMS(2000);
     this.Close();
 }
示例#3
0
        public bool serialProc(ushort command, IntPtr pBuf, int offset, int count, int rxTimeout, int retry)
        {
            //comm.WriteLine("123213");
            try
            {
                serialPort.DiscardInBuffer();
            }
            catch
            {
                if (!bConnectedDevice)
                {
                    ConnectForm f = new ConnectForm();
                    f.ShowDialog();
                }
                if (!bConnectedDevice)
                {
                    return(false);
                }
            }
            serialPort.DiscardInBuffer();
            serialPort.DiscardOutBuffer();
            int nRetry = retry;

            byte[] data = new byte[count];
            Marshal.Copy(pBuf, data, offset, count);
            while (nRetry != 0)
            {
                Debug.WriteLine("发送:" + WFNetLib.StringFunc.StringsFunction.byteToHexStr(data, " "));
                serialPort.Write(data, 0, data.Length);
                serialPort.ReadTimeout = rxTimeout;
                while (true)
                {
                    try
                    {
                        if (DLLWork.ProcRxByte((byte)serialPort.ReadByte()))
                        {
                            byte[] rx  = new byte[1024];
                            int    len = 0;
                            DLLWork.GetRxData(rx, ref len);
                            Debug.WriteLine("接收:" + WFNetLib.StringFunc.StringsFunction.byteToHexStr(rx, 0, len, " "));
                            //serialPort.Close();
                            return(true);
                        }
                    }
                    catch// (Exception ex)
                    {
                        //serialPort.Close();
                        break;
                    }
                }
                nRetry--;
            }
            return(false);
        }
示例#4
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            WFGlobal.WaitMS(200);
            DLLWork.MakeDLL();

            serialProcCallback  = new DLLWork.SerialProcCallback(serialProc);
            setProgressCallback = new DLLWork.SetProgressCallback(SetProgressCallBackProc);
            //serialTxCallback = new DLLWork.SerialTxCallback(serialTxProc);
            DLLWork.InitDllWork(serialProcCallback, setProgressCallback);
            bConnectedDevice = false;
            ConnectForm f = new ConnectForm();

            f.ShowDialog();
        }
示例#5
0
        private void btReadEIS_Click(object sender, EventArgs e)
        {
            clearData();
            mainForm.SetWorkStatus("开始读取EIS");
            if (ModelType == 1 || ModelType == 4)
            {
                DLLWork.SetCANBaudRate(0);
            }
            else
            {
                DLLWork.SetCANBaudRate(1);
            }
            if (!DLLWork.CANReadEEPROMProc(ModelType))
            {
                int errCode = DLLWork.GetErrorCode();
                mainForm.SetWorkStatus(ErrorCodeTranslate.GetLastError(1, errCode));
                WinAPI.MessageBeep(WinAPI.MB_ICONHAND);
                return;
            }
            byte[] rx  = new byte[1024 * 10];
            int    len = 0;

            DLLWork.GetEEPROMData(rx, ref len);

            eisData.SetAllData(rx, len);

            string   fileName = System.Windows.Forms.Application.StartupPath + "\\" + ModelType.ToString("X2") + ".bin";
            FileInfo f        = new FileInfo(fileName);
            Stream   stream   = File.OpenWrite(f.FullName);

            stream.Write(rx, 0, len);
            stream.Flush();
            stream.Close();
            ShowData();
            WinAPI.MessageBeep(WinAPI.MB_OK);
            mainForm.SetWorkStatus("读取点火开关完成");
        }