static void Main(string[] args) { /*Elérhető adapterek megjelnítése*/ foreach (CanAdapterItem item in CanAdapterDevice.GetAdapters()) { Console.WriteLine(item); } /*Adapter példányosítása*/ CanAdapterDevice adapter = new CanAdapterDevice(); /*Kapcsolódás a tömb 0. indexén lévő adapterhez*/ adapter.ConnectTo(CanAdapterDevice.GetAdapters()[0]); /*Kapcsolat bontása*/ adapter.Disconnect(); Console.Read(); /*Konzol kimenete: * CAN Bus Adapter - MCAN120803 3869366E3133 * CAN Bus Adapter - MCAN120803 3873366E3133 * CAN Bus Adapter - MCAN120803 387536633133 */ }
public void Setup() { Adapter = new CanAdapterDevice(); Adapter.ConnectTo("3869366E3133"); Adapter.Attributes.Termination = true; Adapter.Open(250000); }
static void Main(string[] args) { /*Elérhető adapterek megjelnítése*/ foreach (CanAdapterItem item in CanAdapterDevice.GetAdapters()) { Console.WriteLine(item); } /*Adapter példányosítása*/ CanAdapterDevice adapter = new CanAdapterDevice(); /*Kapcsolódás a 3873366E3133 azonosítójú adapterhez*/ adapter.ConnectTo("3873366E3133"); Console.WriteLine("Connected to: " + adapter.Attributes.SerialNumber); /*Kapcsolat bontása*/ adapter.Disconnect(); Console.Read(); /*Konzol kimenete: * CAN Bus Adapter - MCAN120803 3869366E3133 * CAN Bus Adapter - MCAN120803 3873366E3133 * CAN Bus Adapter - MCAN120803 387536633133 * Connected to: 3873366E3133 */ }
/// <summary> /// Connect To Can Adapter /// </summary> /// <param name="serialNumber"></param> public void Connect(string serialNumber) { Adapter.ConnectTo(serialNumber); Adapter.Services.Reset(); Adapter.Attributes.Termination = true; //Worker.RunWorkerAsync(); Adapter.Open(250000); }
/*ExpectedMessage = "_adapter not found by Serial Number. Code:-8603."*/ public void _0001_ConnectByInvalidSerialNumberException() { Assert.Catch <CanAdapterException>(() => { _adapter = new CanAdapterDevice(); _adapter.ConnectTo("abc"); }); }
public void Setup() { _adapterWriter = new CanAdapterDevice(); _adapterWriter.ConnectTo(CanAdapterDevice.GetAdapters()[0]); _adapterReader = new CanAdapterDevice(); _adapterReader.ConnectTo(CanAdapterDevice.GetAdapters()[1]); _targetBaudrate = 125000; }
public void Setup() { _adapterWriter = new CanAdapterDevice(); _adapterWriter.ConnectTo(CanAdapterDevice.GetAdapters()[0]); _targetBaudrate = 500000; _adapterWriter.Services.Reset(); _adapterWriter.Open(_targetBaudrate); }
/// <summary> /// /// </summary> /// <param name="serialNumber"></param> public void Connect(string serialNumber) { Adapter.ConnectTo(serialNumber); Adapter.Services.Reset(); Adapter.Attributes.Termination = true; }
void AsyncTest(int msgCount, uint baudrate) { CanAdapterDevice adapterWriter = new CanAdapterDevice(); var selectedAdapterWriter = CanAdapterDevice.GetAdapters()[0]; //{CAN Bus Adpater - MCAN120803 3873366E3133 } adapterWriter.ConnectTo(selectedAdapterWriter); CanAdapterDevice adapterReader = new CanAdapterDevice(); var selectedAdapterReader = CanAdapterDevice.GetAdapters()[1]; //{CAN Bus Adpater - MCAN120803 387536633133 } adapterReader.ConnectTo(selectedAdapterReader); Stopwatch watch = new Stopwatch(); 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; try { CanMessage[] txFrames = new CanMessage[msgCount]; Action writer = () => { try { for (int i = 0; i < msgCount; i++) { txFrames[i] = CanMessage.MessageStdC8; byte[] valuebytes = BitConverter.GetBytes((uint)i + 1); Buffer.BlockCopy(valuebytes, 0, txFrames[i].Data, 0, valuebytes.Length); } adapterWriter.Write(txFrames); } catch (Exception ex) { Console.WriteLine(ex.Message); } }; CanMessage[] rxFrames = new CanMessage[msgCount]; int offset = 0; watch.Start(); long startTick = DateTime.Now.Ticks; AutoResetEvent doneEv = new AutoResetEvent(false); Action reader = () => { try { do { if (DateTime.Now.Ticks - startTick > 15000 * 10000) { throw new Exception("Timeout"); } int length = adapterReader.Attributes.PendingRxMessages; adapterReader.Read(rxFrames, offset, length); //Console.WriteLine("Pending: " + length + "Length: " + offset ); offset += length; } while (offset != msgCount); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine("RxTotal:" + adapterReader.Attributes.RxTotal.ToString()); Console.WriteLine("RxDrop:" + adapterReader.Attributes.RxDrop.ToString()); } doneEv.Set(); }; adapterWriter.Open(baudrate); adapterReader.Open(baudrate); reader.BeginInvoke(null, null); Thread.Sleep(50); writer.BeginInvoke(null, null); doneEv.WaitOne(); watch.Stop(); double calcBps1 = ((msgCount * 8E+0) / (watch.ElapsedMilliseconds / 1000E+0)); double calcBps2 = ((msgCount * 8E+0) / (((DateTime.Now.Ticks - startTick) / 10000E+0) / 1000E+0)); uint rxTotal = adapterReader.Attributes.RxTotal; Console.WriteLine("Reader RxDrop: " + adapterReader.Attributes.RxDrop); Console.WriteLine("Writer TxDrop: " + adapterWriter.Attributes.TxDrop); Console.WriteLine("Átjött Host FIFO-jába: " + offset); Console.WriteLine("Számított Baudrate 1: " + calcBps1.ToString()); Console.WriteLine("Számított Baudrate 2: " + calcBps2.ToString()); adapterReader.Close(); adapterWriter.Close(); Assert.AreEqual(msgCount, rxTotal, "Az adapter FIFO-jába nem jött meg minden."); Assert.AreEqual(msgCount, offset, "A Host FIFO-jaba nem jött meg minden."); } catch { throw; } finally { adapterWriter.Disconnect(); adapterReader.Disconnect(); } }