public static void Main() { // PJ5 is LD2 in STM32F769I_DISCO //_led = GpioController.GetDefault().OpenPin(PinNumber('J', 5)); // PG14 is LEDLD4 in F429I_DISCO //_led = GpioController.GetDefault().OpenPin(PinNumber('G', 14)); // PD13 is LED3 in DISCOVERY4 _led = GpioController.GetDefault().OpenPin(PinNumber('D', 13)); _led.SetDriveMode(GpioPinDriveMode.Output); // set settings for CAN controller CanSettings canSettings = new CanSettings(6, 8, 1, 0); // get controller for CAN1 CanController1 = CanController.FromId("CAN1", canSettings); // get controller for CAN2 CanController2 = CanController.FromId("CAN2", canSettings); //CanController1.MessageReceived += CanController_DataReceived; CanController2.MessageReceived += CanController_DataReceived; while (true) { CanController1.WriteMessage(new CanMessage(0x01234567, CanMessageIdType.EID, CanMessageFrameType.Data, new byte[] { 0xCA, 0xFE })); //CanController2.WriteMessage(new CanMessage(0x01234567, false, true, new byte[] { 0xFE, 0xCA })); Thread.Sleep(2000); } }
private static void OnboardCanToCanSpi() { var Msg1 = new CanMessage() { ArbitrationId = 0x00, Length = 8, RemoteTransmissionRequest = false, ExtendedId = false }; for (var i = 0; i < 10; i++) { Msg1.Data = Encoding.UTF8.GetBytes($"Hello{Msg1.ArbitrationId:X3}"); Debug.WriteLine($"Onboard CAN sending message 'Hello{Msg1.ArbitrationId:X3}', ID 0x{Msg1.ArbitrationId:X3} --->"); _onboardCan.WriteMessage(Msg1); Msg1.ArbitrationId++; Thread.Sleep(200); } }
private void CanController_MessageReceived(CanController sender, MessageReceivedEventArgs e) { var msgs = new GHIElectronics.TinyCLR.Devices.Can.CanMessage[e.Count]; for (var i = 0; i < msgs.Length; i++) { msgs[i] = new GHIElectronics.TinyCLR.Devices.Can.CanMessage(); } this.messageReceiveCount += sender.ReadMessages(msgs, 0, msgs.Length); for (var i = 0; i < msgs.Length; i++) { this.UpdateStatusText(ArbitrationId + msgs[i].ArbitrationId, true); this.UpdateStatusText(FdCanMode + msgs[i].FdCan, false); this.UpdateStatusText(ExtendedId + msgs[i].ExtendedId, false); this.UpdateStatusText(RTR + msgs[i].RemoteTransmissionRequest, false); this.UpdateStatusText(BitRateSwitch + msgs[i].BitRateSwitch, false); var dataText = string.Empty; for (var ii = 0; ii < 8; ii++) { dataText += msgs[i].Data[ii] + " "; } this.UpdateStatusText(Data + dataText, false); this.UpdateStatusText(TotalReceived + this.messageReceiveCount, false); try { msgs[i].ArbitrationId += 1; sender.WriteMessage(msgs[i]); } catch { } } }