public void CANListenTest() { STLinkBridgeWrapper.STLinkBridgeWrapper wrapper = new STLinkBridgeWrapper.STLinkBridgeWrapper(); var devices = new List <DeviceInfo>(); STLinkIf_StatusT linkStatus = wrapper.EnumerateDevices(out devices); DeviceInfo selectedDevice = devices.FirstOrDefault(); if (selectedDevice == null) { throw new Exception("No STLink device found"); } Brg_StatusT bridgeStatus = wrapper.OpenBridge(selectedDevice); wrapper.CanMessageReceived += Wrapper_CanMessageReceived; Assert.IsTrue(wrapper.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); wrapper.CanInit(1000000, false); Assert.IsTrue(wrapper.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); wrapper.StartTransmission(null); Assert.IsTrue(wrapper.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); System.Threading.Thread.Sleep(100); var ReceivedMessages = wrapper.CanRead(); wrapper.StopTransmission(); Debug.Assert(ReceivedMessages.Count < 0); }
private void InitializeCAN(DeviceInfo selectedDevice, uint baudrate, double polltime) { if (selectedDevice == null) { throw new Exception("No STLink device found"); } Brg_StatusT bridgeStatus = StLinkBridge.OpenBridge(selectedDevice); Debug.Assert(StLinkBridge.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); try { StLinkBridge.CanInit(baudrate, false); Debug.Assert(StLinkBridge.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); } catch (Exception e) { MessageBox.Show($"{e.Message}\n\n{e.StackTrace}", e.Message, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // TODO: Handle the other errors in a similar manner StLinkBridge.StartTransmission(polltime); Debug.Assert(StLinkBridge.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); }
public List <CanMessage> CanRead() { List <CanMessage> receivedMessages = new List <CanMessage>(); bool OverrunDetected = false; Brg_StatusT status = base.CanReadLL(out receivedMessages, OverrunDetected); if (status == Brg_StatusT.BRG_USB_COMM_ERR || status == Brg_StatusT.BRG_CONNECT_ERR) { this.CloseConnection(); // TODO: Consider allowing a few errors for increased robustness } return(receivedMessages); }
public void CANLoopBackTest() { Wrapper wrapper = new Wrapper(); var devices = new List <DeviceInfo>(); STLinkIf_StatusT linkStatus = wrapper.EnumerateDevices(out devices); Console.WriteLine("test1"); Debug.WriteLine("test2"); Trace.WriteLine("test3"); DeviceInfo selectedDevice = devices.FirstOrDefault(); if (selectedDevice == null) { throw new Exception("No STLink device found"); } Brg_StatusT bridgeStatus = wrapper.OpenBridge(selectedDevice); bridgeStatus = wrapper.CanTest(); }
public void CANLoopBackTest() { STLinkBridgeWrapper.STLinkBridgeWrapper wrapper = new STLinkBridgeWrapper.STLinkBridgeWrapper(); var devices = new List <DeviceInfo>(); STLinkIf_StatusT linkStatus = wrapper.EnumerateDevices(out devices); DeviceInfo selectedDevice = devices.FirstOrDefault(); if (selectedDevice == null) { throw new Exception("No STLink device found"); } Brg_StatusT bridgeStatus = wrapper.OpenBridge(selectedDevice); wrapper.CanMessageReceived += Wrapper_CanMessageReceived; Assert.IsTrue(wrapper.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); wrapper.CanInit(125000, true); Assert.IsTrue(wrapper.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); wrapper.StartTransmission(null); Assert.IsTrue(wrapper.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); var canMessage = GenerateSimpleCanMessageType(); var signal1 = canMessage.Signals["TestSignal1"]; var signal2 = canMessage.Signals["TestSignal2"]; var signal3 = canMessage.Signals["TestSignal3"]; signal1.CalculateBitMask(); signal2.CalculateBitMask(); signal3.CalculateBitMask(); //wrapper.canMessageTypes = new SortedList<uint, CanMessageType>(); //wrapper.canMessageTypes.Add((uint)canMessage.ID, canMessage); double value1 = -1.3; double value2 = 1.4; double value3 = 5; //var message = canMessage.GenerateCanMessageTx((signal1, value1), (signal2, value2), (signal3, value3)); var message = new CanMessage(); wrapper.WriteMessage(message); Assert.IsTrue(wrapper.GetBridgeStatus() == Brg_StatusT.BRG_NO_ERR); System.Threading.Thread.Sleep(1000); var ReceivedMessages = wrapper.CanRead(); var listOfMessages = new SortedList <uint, CanMessageType>(); listOfMessages.Add((uint)canMessage.Id, canMessage); //var dataPoints = CanDB.CanDbcParser.ParseReceivedCanMessagesRx(ReceivedMessages, listOfMessages); //Assert.AreEqual(3, dataPoints.Count); //Assert.AreEqual(value1, dataPoints[0].data); //Assert.AreEqual(value2, dataPoints[1].data); //Assert.AreEqual(value3, dataPoints[2].data); wrapper.StopTransmission(); }