Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. CANBus Payload Extraction

CANBus Payload Extraction

Scheduled Pinned Locked Moved Solved Mobile and Embedded
canbusdebugging
8 Posts 2 Posters 1.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    williamsk
    wrote on 19 Oct 2020, 19:04 last edited by
    #1

    I have the CANBus sending working fine. And my custom function for receiving a CANBus frame triggers when I send one. I can even read the payload size and the frame ID in the debugger. But when I try to read the payload, I get <not accessible>, or in the case of the QString a 10000 character string.

    Here is my code.

     const QCanBusFrame frame = device->readFrame();
     const quint8 dataLength = frame.payload().size();
     const quint16 id = frame.frameId();
     const auto &payload = frame.payload();
     const QByteArray data = payload.data();
     QString stringData = frame.toString();
    

    The frame.toString() at the end is what Qt has in their CANBus example code so I figured I'd try it.

    Qt_CANBus.png

    So I get the frame payload size and the CAN Frame ID which is correct. But I can't get the data out. What am I missing or forgetting to do here?

    A 1 Reply Last reply 20 Oct 2020, 12:50
    0
    • W williamsk
      19 Oct 2020, 19:04

      I have the CANBus sending working fine. And my custom function for receiving a CANBus frame triggers when I send one. I can even read the payload size and the frame ID in the debugger. But when I try to read the payload, I get <not accessible>, or in the case of the QString a 10000 character string.

      Here is my code.

       const QCanBusFrame frame = device->readFrame();
       const quint8 dataLength = frame.payload().size();
       const quint16 id = frame.frameId();
       const auto &payload = frame.payload();
       const QByteArray data = payload.data();
       QString stringData = frame.toString();
      

      The frame.toString() at the end is what Qt has in their CANBus example code so I figured I'd try it.

      Qt_CANBus.png

      So I get the frame payload size and the CAN Frame ID which is correct. But I can't get the data out. What am I missing or forgetting to do here?

      A Offline
      A Offline
      aha_1980
      Lifetime Qt Champion
      wrote on 20 Oct 2020, 12:50 last edited by
      #2

      HI @williamsk, welcome.

      What happens if you debug-print to the console?

      qDebug() << frame.toString();

      Also, can you provide some more information? Which operating system is that, which Qt version, which compiler?

      And finally, which CAN hardware and therefore which CAN bus plugin are you using?

      Also please note that this:

       const auto &payload = frame.payload();
       const QByteArray data = payload.data();
      

      is wrong, as frame.payload() already is a QByteArray, and by accessing the data() (which is a char *) you might truncate it at the first 0x00. So what you really want to do is: const QByteArray data = frame.payload().

      Regards

      Qt has to stay free or it will die.

      W 1 Reply Last reply 20 Oct 2020, 14:59
      3
      • A aha_1980
        20 Oct 2020, 12:50

        HI @williamsk, welcome.

        What happens if you debug-print to the console?

        qDebug() << frame.toString();

        Also, can you provide some more information? Which operating system is that, which Qt version, which compiler?

        And finally, which CAN hardware and therefore which CAN bus plugin are you using?

        Also please note that this:

         const auto &payload = frame.payload();
         const QByteArray data = payload.data();
        

        is wrong, as frame.payload() already is a QByteArray, and by accessing the data() (which is a char *) you might truncate it at the first 0x00. So what you really want to do is: const QByteArray data = frame.payload().

        Regards

        W Offline
        W Offline
        williamsk
        wrote on 20 Oct 2020, 14:59 last edited by
        #3

        @aha_1980

        Okay! So qDebug works and prints the correct data to the console. So why then, when I try to extract this data to a variable, the debugger says <not accessible>? Is this a deficiency in the debugger? If I simply try to use the data, will the screen respond appropriately? I just have to do a lot of parsing and processing on this data so being able to see it in the debugger would be immensely helpful.

        As for more information, I'm running a Toradex iMX6 SoM. It is running the standard Boot2Qt image which I think is based on Debian. I'm using Qt Creator 4.13.1 based on Qt 5.15.1 using mingw32 as the compiler. I'm using the on-chip CAN interface and using canutils and libsocketcan to talk to it.

        And thanks for the notes. I was just trying everything I could think of to see the data in the debugger. qDebug is probably the first thing I should have tried.

        A 1 Reply Last reply 21 Oct 2020, 07:05
        0
        • W williamsk
          20 Oct 2020, 14:59

          @aha_1980

          Okay! So qDebug works and prints the correct data to the console. So why then, when I try to extract this data to a variable, the debugger says <not accessible>? Is this a deficiency in the debugger? If I simply try to use the data, will the screen respond appropriately? I just have to do a lot of parsing and processing on this data so being able to see it in the debugger would be immensely helpful.

          As for more information, I'm running a Toradex iMX6 SoM. It is running the standard Boot2Qt image which I think is based on Debian. I'm using Qt Creator 4.13.1 based on Qt 5.15.1 using mingw32 as the compiler. I'm using the on-chip CAN interface and using canutils and libsocketcan to talk to it.

          And thanks for the notes. I was just trying everything I could think of to see the data in the debugger. qDebug is probably the first thing I should have tried.

          A Offline
          A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on 21 Oct 2020, 07:05 last edited by
          #4

          Hi @williamsk

          Okay! So qDebug works and prints the correct data to the console.

          Good. At least you know your hardware and software is working then.

          So why then, when I try to extract this data to a variable, the debugger says <not accessible>? Is this a deficiency in the debugger?

          Probably. I had problems debugging a lambda the last time I tried. Is your code in a real function? Try something like this:

          void slotFramesReceived()
          {
            const QCanBusFrame frame = device->readFrame();
            const quint8 dataLength = frame.payload().size();
            const quint16 id = frame.frameId();
            const QByteArray data =  frame.payload();
            constQString stringData = frame.toString();
            qDebug() << stringData; // break here
          }
          

          Then you should be able to see all the variables - or there is really a problem with the debugger

          If I simply try to use the data, will the screen respond appropriately? I just have to do a lot of parsing and processing on this data so being able to see it in the debugger would be immensely helpful.

          Agreed.

          As for more information, I'm running a Toradex iMX6 SoM. It is running the standard Boot2Qt image which I think is based on Debian.

          At least it should be some Linux, so the plugin is socketcan.

          I'm using Qt Creator 4.13.1 based on Qt 5.15.1 using mingw32 as the compiler.

          As the board is running Linux, that's probably some kind of cross-gcc? Is you Host running Windows? (That's just a side question out of curiosity, I've never cross-compiled from Windows to Linux)

          And thanks for the notes. I was just trying everything I could think of to see the data in the debugger. qDebug is probably the first thing I should have tried.

          Sometimes good old printf is indeed the rescue.

          Regards

          Qt has to stay free or it will die.

          W 1 Reply Last reply 21 Oct 2020, 12:01
          0
          • A aha_1980
            21 Oct 2020, 07:05

            Hi @williamsk

            Okay! So qDebug works and prints the correct data to the console.

            Good. At least you know your hardware and software is working then.

            So why then, when I try to extract this data to a variable, the debugger says <not accessible>? Is this a deficiency in the debugger?

            Probably. I had problems debugging a lambda the last time I tried. Is your code in a real function? Try something like this:

            void slotFramesReceived()
            {
              const QCanBusFrame frame = device->readFrame();
              const quint8 dataLength = frame.payload().size();
              const quint16 id = frame.frameId();
              const QByteArray data =  frame.payload();
              constQString stringData = frame.toString();
              qDebug() << stringData; // break here
            }
            

            Then you should be able to see all the variables - or there is really a problem with the debugger

            If I simply try to use the data, will the screen respond appropriately? I just have to do a lot of parsing and processing on this data so being able to see it in the debugger would be immensely helpful.

            Agreed.

            As for more information, I'm running a Toradex iMX6 SoM. It is running the standard Boot2Qt image which I think is based on Debian.

            At least it should be some Linux, so the plugin is socketcan.

            I'm using Qt Creator 4.13.1 based on Qt 5.15.1 using mingw32 as the compiler.

            As the board is running Linux, that's probably some kind of cross-gcc? Is you Host running Windows? (That's just a side question out of curiosity, I've never cross-compiled from Windows to Linux)

            And thanks for the notes. I was just trying everything I could think of to see the data in the debugger. qDebug is probably the first thing I should have tried.

            Sometimes good old printf is indeed the rescue.

            Regards

            W Offline
            W Offline
            williamsk
            wrote on 21 Oct 2020, 12:01 last edited by
            #5

            @aha_1980

            I'm not sure what you mean by "real function". The code is in a function that is declared in the public slots. I tried using the code as you have it written. Here is what I get out of qDebug in the terminal:

            "     06E   [8]  48 65 6C 6C 6F 21 21 21"
            

            And here is what the debugger shows:

            Qt_CAN_String.png

            So I guess I'll have to make heavy use of qDebug to get it all parsed correctly.

            And yes, I'm developing on a Windows machine. MinGW stands for Minimalist GNU for Windows and is a cross compiler supplied by Toradex, the SoM manufacturer.

            Thanks for the help. I'll update this thread if I stumble across a way to get the debugger to display correctly.

            A 1 Reply Last reply 21 Oct 2020, 12:06
            1
            • W williamsk
              21 Oct 2020, 12:01

              @aha_1980

              I'm not sure what you mean by "real function". The code is in a function that is declared in the public slots. I tried using the code as you have it written. Here is what I get out of qDebug in the terminal:

              "     06E   [8]  48 65 6C 6C 6F 21 21 21"
              

              And here is what the debugger shows:

              Qt_CAN_String.png

              So I guess I'll have to make heavy use of qDebug to get it all parsed correctly.

              And yes, I'm developing on a Windows machine. MinGW stands for Minimalist GNU for Windows and is a cross compiler supplied by Toradex, the SoM manufacturer.

              Thanks for the help. I'll update this thread if I stumble across a way to get the debugger to display correctly.

              A Offline
              A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on 21 Oct 2020, 12:06 last edited by
              #6

              Hi @williamsk

              I'm not sure what you mean by "real function".

              I meant not a lambda, as I encountered problems within there.

              Did you break after all variable assignments have been made? And did you use a Debug build?

              If the problem persists, the Views > Debugger Log window might give more insight.

              Regards

              Qt has to stay free or it will die.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                williamsk
                wrote on 21 Oct 2020, 12:07 last edited by
                #7

                And I just did. Simple matter of changing the display format from Automatic to Raw. Now I can see my payload in both my QByteArray and my QString.

                qt_CAN_String_Fix.png

                It's always the simplest thing. Thanks again!

                A 1 Reply Last reply 21 Oct 2020, 12:09
                2
                • W williamsk
                  21 Oct 2020, 12:07

                  And I just did. Simple matter of changing the display format from Automatic to Raw. Now I can see my payload in both my QByteArray and my QString.

                  qt_CAN_String_Fix.png

                  It's always the simplest thing. Thanks again!

                  A Offline
                  A Offline
                  aha_1980
                  Lifetime Qt Champion
                  wrote on 21 Oct 2020, 12:09 last edited by
                  #8

                  @williamsk

                  Ah, cool. So as your problem is solved, please mark this topic as SOLVED too (button Topic Tools).

                  Thanks and regards

                  Qt has to stay free or it will die.

                  1 Reply Last reply
                  1

                  1/8

                  19 Oct 2020, 19:04

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved