Exemple #1
0
 public override bool Connect()
 {
     if (!IsOpen)
     {
         this.IsOpen = VCI_OpenDevice(DevType, DevIndex, CanIndex) != 0;
         if (this.IsOpen)
         {
             VCI_INIT_CONFIG config = new VCI_INIT_CONFIG();
             config.AccCode = 0x00;
             config.AccMask = System.Convert.ToUInt32("0xFFFFFFFF", 16);
             //波特率 250kbps Timing0 = 0x01  Timing1 = 0x1c
             //波特率 500kbps Timing0 = 0x00  Timing1 = 0x1c
             //波特率 800kbps Timing0 = 0x00  Timing1 = 0x16
             //波特率 1000kbps Timing0 = 0x00  Timing1 = 0x14
             config.Timing0 = 0x00;
             config.Timing1 = 0x1c;
             config.Filter  = 0x01;
             config.Mode    = 0x00;
             VCI_InitCAN(DevType, DevIndex, CanIndex, ref config);
             VCI_StartCAN(DevType, DevIndex, CanIndex);
             VCI_BOARD_INFO br = new VCI_BOARD_INFO();
             VCI_ReadBoardInfo(DevType, DevIndex, ref br);
             Console.WriteLine(System.Text.Encoding.Default.GetString(br.str_Serial_Num));
             ErrorMessage = System.Text.Encoding.Default.GetString(br.str_Serial_Num);
             if (rec_work_thread == null)
             {
                 rec_work_thread = new Thread(RecWorkThread);
                 rec_work_thread.Start();
             }
             if (send_work_thread == null)
             {
                 send_work_thread = new Thread(SendWorkThread);
                 send_work_thread.Start();
             }
         }
         else
         {
             ErrorMessage = "Can卡初始化失败!";
         }
     }
     return(this.IsOpen);
 }
Exemple #2
0
 static extern UInt32 VCI_InitCAN(UInt32 DeviceType, UInt32 DeviceInd, UInt32 CANInd, ref VCI_INIT_CONFIG pInitConfig);