public void _0012_WriteBeginReadCallback() { if (_adapterWriter.IsOpen) { _adapterWriter.Close(); } if (_adapterReader.IsOpen) { _adapterReader.Close(); } if (_adapterWriter.Attributes.State != CanState.SDEV_IDLE) { _adapterWriter.Services.Reset(); } if (_adapterReader.Attributes.State != CanState.SDEV_IDLE) { _adapterReader.Services.Reset(); } _adapterWriter.Attributes.Termination = true; _adapterReader.Attributes.Termination = true; _adapterWriter.Open(_targetBaudrate); Thread.Sleep(50); _adapterReader.Open(_targetBaudrate); for (int i = 0; i < 12; i++) { _adapterWriter.Write(new CanMessage[] { new CanMessage(0x295, new byte[] { 0x01, 0x02, 0x03 }) }); _adapterWriter.Write(new CanMessage[] { new CanMessage(0x296, new byte[] { 0x04, 0x05, 0x06 }) }); _adapterWriter.Write(new CanMessage[] { new CanMessage(0x4D9, new byte[] { 0x07, 0x08, 0x09 }) }); } CanMessage[] rxFrames = new CanMessage[128]; var state = new MessageReaderAsynState(rxFrames, _adapterReader, 0); _adapterReader.BeginRead(rxFrames, state.Offset, 3, ReadComplete, state); Thread.Sleep(1000); Assert.AreEqual(12, rxFrames.Count(n => n.ArbitrationId == 0x295), "0x295/200ms"); Assert.AreEqual(12, rxFrames.Count(n => n.ArbitrationId == 0x296), "0x296/200ms"); Assert.AreEqual(12, rxFrames.Count(n => n.ArbitrationId == 0x4D9), "0x4D9/1000ms"); }
public void _0011_Filtering() { if (_adapterWriter.IsOpen) { _adapterWriter.Close(); } if (_adapterReader.IsOpen) { _adapterReader.Close(); } if (_adapterWriter.Attributes.State != CanState.SDEV_IDLE) { _adapterWriter.Services.Reset(); } if (_adapterReader.Attributes.State != CanState.SDEV_IDLE) { _adapterReader.Services.Reset(); } _adapterWriter.Attributes.Termination = true; _adapterReader.Attributes.Termination = true; Assert.AreEqual(0, _adapterReader.Attributes.RxTotal, "RxTotal"); Assert.AreEqual(0, _adapterReader.Attributes.RxDrop, "RxDrop"); Assert.AreEqual(0, _adapterWriter.Attributes.TxTotal, "TxTotal"); Assert.AreEqual(0, _adapterWriter.Attributes.TxDrop, "TxDrop"); UInt32 maskAndFilter = 0x503; _adapterReader.Attributes.Mask = (0x000007FF & maskAndFilter) << 21; _adapterReader.Attributes.Filter = (0x000007FF & maskAndFilter) << 21; _adapterWriter.Open(_targetBaudrate); Thread.Sleep(50); _adapterReader.Open(_targetBaudrate); CanMessage[] rxFrames = new CanMessage[128]; int offset = 0; int length = 0; long startTick = 0; bool isTimeout = false; for (int i = 0; i < 2; i++) { _adapterWriter.Write(new CanMessage[] { new CanMessage(0x295, new byte[] { 0x01, 0x02, 0x03 }) }); _adapterWriter.Write(new CanMessage[] { new CanMessage(0x296, new byte[] { 0x04, 0x05, 0x06 }) }); _adapterWriter.Write(new CanMessage[] { new CanMessage(0x4D9, new byte[] { 0x07, 0x08, 0x09 }) }); _adapterWriter.Write(new CanMessage[] { new CanMessage(0x503, new byte[] { 0x10, 0x11, 0x12 }) }); } startTick = DateTime.Now.Ticks; do { if (DateTime.Now.Ticks - startTick > 1000 * 10000) { isTimeout = true; } length = _adapterReader.Attributes.PendingRxMessages; _adapterReader.Read(rxFrames, offset, length); offset += length; } while (!isTimeout); Assert.AreEqual(0, rxFrames.Count(n => n.ArbitrationId == 0x295), "0x295/200ms"); Assert.AreEqual(0, rxFrames.Count(n => n.ArbitrationId == 0x296), "0x296/200ms"); Assert.AreEqual(0, rxFrames.Count(n => n.ArbitrationId == 0x4D9), "0x4D9/1000ms"); Assert.AreEqual(2, rxFrames.Count(n => n.ArbitrationId == 0x503), "0x503/1000ms"); Assert.AreEqual(2, _adapterReader.Attributes.RxTotal, "RxTotal"); Assert.AreEqual(0, _adapterReader.Attributes.RxDrop, "RxDrop"); Assert.AreEqual(8, _adapterWriter.Attributes.TxTotal, "TxTotal"); Assert.AreEqual(0, _adapterWriter.Attributes.TxDrop, "TxDrop"); }