Fez Raptor & Can DW Trouble

Hi,
I’m try to use the can port, but what ever I try, it crashes.
I’m use .net 4.3.

Please se below:

Using GHI’s example


Can = New GHI.IO.ControllerAreaNetwork(ControllerAreaNetwork.Channel.One, _
                                               ControllerAreaNetwork.Speed.Kbps500)

Can.Enabled = True
 '//here is what trigger the error, and no way to use the can with out this is set to enable.

Error:
#### Exception System.Exception - 0xffffffff (1) ####
#### Message:
#### GHI.IO.ControllerAreaNetwork::NativeEnable [IP: 0000] ####
#### GHI.IO.ControllerAreaNetwork::set_Enabled [IP: 0021] ####
#### AlevoDevice.AlevoDevice.AlevoCanBus::Test [IP: 0017] ####
#### AlevoDevice.AlevoDevice.Program::ProgramStarted [IP: 0028] ####
A first chance exception of type ‘System.Exception’ occurred in GHI.Hardware.dll
An unhandled exception of type ‘System.Exception’ occurred in GHI.Hardware.dll

Using Gadgeteer created name:


canDW1.Initialize(ControllerAreaNetwork.Speed.Kbps500, ControllerAreaNetwork.Channel.One)
'//The gadgeteer way, is Initialize method and this crash as well.

Error:
Using mainboard GHI Electronics FEZ Raptor version 1.0
#### Exception System.Exception - 0xffffffff (1) ####
#### Message:
#### GHI.IO.ControllerAreaNetwork::NativeEnable [IP: 0000] ####
#### GHI.IO.ControllerAreaNetwork::set_Enabled [IP: 0021] ####
#### AlevoDevice.AlevoDevice.AlevoCanBus::Test [IP: 0014] ####
#### AlevoDevice.AlevoDevice.Program::ProgramStarted [IP: 0028] ####
A first chance exception of type ‘System.Exception’ occurred in GHI.Hardware.dll
An unhandled exception of type ‘System.Exception’ occurred in GHI.Hardware.dll

Must be a bug related to G400 or Raptor.
I just tried the same code on a Fez Spider and it worked on first try!
the can bus send and receive just fine with 2 wire DW module.

@ eikeland - I was able to use both CAN channels without error on the G400. Can you create and post a complete and simple program that shows the error outside of your main project?

Sure,
Here we go:
The CanDW is connected to Port 11 and USB DP Power to port 8. (Nothing else is connected)
Running firmware 4.3.6 and bootloader 4.3.6.

Still the same error. here is the test code (the same code working just fine on the spider):


Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Imports GHI.IO


Namespace G400TestApp1
    Partial Public Class Program
        ' This is run when the mainboard is powered up or reset. 
        Public Sub ProgramStarted()
            
'//The Next line is what generate the error.
            canDW.Initialize(GHI.IO.ControllerAreaNetwork.Speed.Kbps500, GHI.IO.ControllerAreaNetwork.Channel.One)

            Dim msg As New ControllerAreaNetwork.Message()
            msg.ArbitrationId = &H123
            msg.Data(0) = 1
            msg.Length = 1
            msg.IsExtendedId = False
            canDW.SendMessage(msg)


            ' Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started")



        End Sub

        Private Sub canDW_ErrorReceived(sender As CANDW, e As CANDW.ErrorReceivedEventArgs) Handles canDW.ErrorReceived
            Debug.Print("Error on CAN: " & e.Error.ToString())
        End Sub

        Private Sub canDW_MessagesReceived(sender As CANDW, e As CANDW.MessagesReceivedEventArgs) Handles canDW.MessagesReceived

Dim received As ControllerAreaNetwork.Message = sender.Can.ReadMessage()

            Dim data As String = ""
            For i As Integer = 0 To received.Length - 1
                data += "0x" + received.Data(i).ToString("x2") + " "
           Next
                Debug.Print("   CAN Message   ")
                Debug.Print("-----------------")
                Debug.Print("    ID: " + received.ArbitrationId.ToString())
                Debug.Print("  Time: " + received.TimeStamp.ToString())
                Debug.Print("   RTR: " + received.IsRemoteTransmissionRequest.ToString())
                Debug.Print("   EID: " + received.IsExtendedId.ToString())
                Debug.Print("Length: " + received.Length.ToString())
                Debug.Print("  Data: " + data)
                Debug.Print("")
            
        End Sub

        Private Sub canDW_MessagesSent(sender As CANDW, e As EventArgs) Handles canDW.MessagesSent
            
        End Sub

    End Class
End Namespace

Here is the error log:

Using mainboard GHI Electronics FEZ Raptor version 1.0
#### Exception System.Exception - 0xffffffff (1) ####
#### Message:
#### GHI.IO.ControllerAreaNetwork::NativeEnable [IP: 0000] ####
#### GHI.IO.ControllerAreaNetwork::set_Enabled [IP: 0021] ####
#### G400TestApp1.G400TestApp1.Program::ProgramStarted [IP: 0009] ####
A first chance exception of type ‘System.Exception’ occurred in GHI.Hardware.dll
An unhandled exception of type ‘System.Exception’ occurred in GHI.Hardware.dll
The program ‘[3] Micro Framework application: Managed’ has exited with code 0 (0x0).

@ John -
Hi John, it did sudently working …
First I reinstalled the firmware again and then
I started from scratch demounted an unscrewed all gadgets from the board.
Plugged in power and can module connected to my "Can Test Network"
Voila! it worked.
One thing to remember is Channel one only works on Gadget Port 10 and Channel 2 only in Port 11 (Is this in the doc?, I must have missed it).

Well look at the positive side, If I pull this project trough, we will need 300 to 1000 custom units pr. year based on the G400 Module. :slight_smile:

R.E

OK,
What I have found out so far.
The Can do not crash anymore, but I must use events from the CanControllerNetwork object and not events from the CanDW module.

Her is how I solved it (for now anyway):
I get my CanBus object from CanDW.Can object,
I’m use the events from Can object instead of the CanDW Module.
ALL inncoming and outgoing messages seams to work.
if I use the event “MessagesReceived” from CandDW module.
this works sometimes, but mostly It block everything as soon as I try to read the message, and no more debug info from any other modules.


'// The CanDW Module is connected to Gadgetport 10
Imports GT = Gadgeteer
Imports GTM = Gadgeteer.Modules
Imports Gadgeteer.Modules.GHIElectronics
Imports GHI.IO


Namespace G400TestApp1
    Partial Public Class Program
        Private WithEvents MyCan As ControllerAreaNetwork
     
        Public Sub ProgramStarted()
          

            canDW.Initialize(GHI.IO.ControllerAreaNetwork.Speed.Kbps250, GHI.IO.ControllerAreaNetwork.Channel.One)
            MyCan = canDW.Can

            Dim msg As New ControllerAreaNetwork.Message()
            msg.ArbitrationId = &H123
            msg.Data = New Byte() {1, 2, 3, 4, 5, 6, 7, 8}
            msg.Length = 8
            msg.IsExtendedId = False
            canDW.SendMessage(msg)

            Debug.Print("Program Started")

        End Sub


        Private Sub MyCan_ErrorReceived(sender As ControllerAreaNetwork, e As ControllerAreaNetwork.ErrorReceivedEventArgs) Handles MyCan.ErrorReceived
            Debug.Print("Error on CAN: " & e.Error.ToString())
        End Sub

        Private Sub MyCan_MessageAvailable(sender As ControllerAreaNetwork, e As ControllerAreaNetwork.MessageAvailableEventArgs) Handles MyCan.MessageAvailable
            Dim received As ControllerAreaNetwork.Message = sender.ReadMessage()

            Dim data As String = ""
            For i As Integer = 0 To received.Data.Length - 1
                data += "0x" + received.Data(i).ToString("x2") + " "
            Next

            Debug.Print("   CAN Message   ")
            Debug.Print("-----------------")
            Debug.Print("    ID: " + received.ArbitrationId.ToString())
            Debug.Print("  Time: " + received.TimeStamp.ToString())
            Debug.Print("   RTR: " + received.IsRemoteTransmissionRequest.ToString())
            Debug.Print("   EID: " + received.IsExtendedId.ToString())
            Debug.Print("Length: " + received.Data.Length.ToString())
            Debug.Print("  Data: " + data)
            Debug.Print("")

        End Sub
    End Class
End Namespace

@ Ricky - You are indeed correct that CAN channel 1 is on socket 10 and channel 2 is on socket 11. I’ve documented it here: https://www.ghielectronics.com/docs/321/fez-raptor-developers-guide

Something to keep in mind: the MessagesReceived event can signal the receipt of more than one message. If you read one at a time in high traffic situations, messages might be lost. The ReadMessages overloads can be used to read every available message.