private void rxThread() { uint temp = 0; uint len; while (running) { len = CAN.VCI_Receive(CAN.DEV_USBCAN2, 0, 0, receive, 500, 10); if (len == 0xFFFFFFFF) //Return value of -1 indicates failure { len = 0; } if (len > 20) { temp++; } for (int pkt = 0; pkt < len; pkt++) { rxBuffer[rxBufferWPos] = receive[pkt]; rxBufferWPos = (rxBufferWPos + 1) % RX_BUF_SIZE; } System.Threading.Thread.Sleep(1); } }
private void cmdTx_Click(object sender, EventArgs e) { UInt32 retval; if (CANConnected) { CAN.VCI_CAN_OBJ[] send = new CAN.VCI_CAN_OBJ[1]; CAN.VCI_CAN_OBJ[] receive = new CAN.VCI_CAN_OBJ[3]; send[0].ID = 0xA; send[0].TimeFlag = 0; send[0].SendType = 0; send[0].RemoteFlag = 0; send[0].ExternFlag = 1; send[0].DataLen = 1; send[0].Data = new byte[8]; send[0].Data[0] = 0; retval = CAN.VCI_Transmit(CAN.DEV_USBCAN2, 0, 0, send, 1); receive[0].Data = new byte[8]; receive[1].Data = new byte[8]; receive[2].Data = new byte[8]; receive[0].Reserved = new byte[3]; receive[1].Reserved = new byte[3]; receive[2].Reserved = new byte[3]; retval = CAN.VCI_Receive(CAN.DEV_USBCAN2, 0, 0, receive, 50, 1000); //retval = CAN.VCI_Receive(CAN.DEV_USBCAN2, 0, 0, receive, 1, 1000); //retval = CAN.VCI_Receive(CAN.DEV_USBCAN2, 0, 0, receive, 1, 1000); int a; a = 0; } }