Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt CanBus,SYSTEC CAN can't read CAN frames
QtWS25 Last Chance

Qt CanBus,SYSTEC CAN can't read CAN frames

Scheduled Pinned Locked Moved Solved General and Desktop
qcanbusdevice
7 Posts 3 Posters 1.7k 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.
  • B Offline
    B Offline
    Babs
    wrote on 12 Apr 2019, 09:46 last edited by
    #1

    Hello, I'm working on a CAN API.
    I write a frame to my CAN bus device and should receive data in response. I see the received packet in CAN example API when i write that frame.
    The problem is i can't read that received frame when i use QCanBusDevice::readFrame()
    This is my code to read the response:

     QCanBusDevice *device=QCanBus::instance()->createDevice("systeccan","can1.0");
       device->setConfigurationParameter(QCanBusDevice::BitRateKey,125000);
       device->setConfigurationParameter(QCanBusDevice::CanFdKey,false);
       device->connectDevice();
       char data[8]={0x40,0x00,0x10,0x00,0x00,0x00,0x00,0x00};
       QByteArray frame(data,8);
       QCanBusFrame myframe;
       myframe.setPayload(frame);
       myframe.setFrameId(0x617);
       qDebug()<<myframe.toString();
       qDebug()<<device->writeFrame(myframe);
       QCanBusFrame frameR=device->readFrame();
       qDebug()<<frameR.toString();
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 12 Apr 2019, 09:49 last edited by mrjj 4 Dec 2019, 09:50
      #2

      Hi
      Did you try call
      https://doc.qt.io/qt-5/qcanbusdevice.html#framesAvailable
      to see if there is something to read ?

      Also, i think it will work better if you connect a slot
      to void QCanBusDevice::framesReceived()
      and there call framesAvailable and readFrame.
      The way you are using it now, suggests its blocking but i think its actually async.

      B 1 Reply Last reply 12 Apr 2019, 10:06
      1
      • M mrjj
        12 Apr 2019, 09:49

        Hi
        Did you try call
        https://doc.qt.io/qt-5/qcanbusdevice.html#framesAvailable
        to see if there is something to read ?

        Also, i think it will work better if you connect a slot
        to void QCanBusDevice::framesReceived()
        and there call framesAvailable and readFrame.
        The way you are using it now, suggests its blocking but i think its actually async.

        B Offline
        B Offline
        Babs
        wrote on 12 Apr 2019, 10:06 last edited by
        #3

        @mrjj i created a function processReceivedFrames and connected it to framesReceived() function.
        I still get 0 as number of available frames.
        This is the way i made the connection:

            connect(m_device, &QCanBusDevice::framesReceived, this, &DevicesManagement::processReceivedFrames,Qt::UniqueConnection);
        
        

        I'm sure that data should be received i tested that in CAN example like shown in picture below:![alt text]0_1555063572416_qtforum.PNG

        Regards

        M 1 Reply Last reply 12 Apr 2019, 10:21
        0
        • B Babs
          12 Apr 2019, 10:06

          @mrjj i created a function processReceivedFrames and connected it to framesReceived() function.
          I still get 0 as number of available frames.
          This is the way i made the connection:

              connect(m_device, &QCanBusDevice::framesReceived, this, &DevicesManagement::processReceivedFrames,Qt::UniqueConnection);
          
          

          I'm sure that data should be received i tested that in CAN example like shown in picture below:![alt text]0_1555063572416_qtforum.PNG

          Regards

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 12 Apr 2019, 10:21 last edited by
          #4

          @Babs
          Hi
          Something else must be missing then. If the sample can.

          B 1 Reply Last reply 12 Apr 2019, 12:59
          0
          • M mrjj
            12 Apr 2019, 10:21

            @Babs
            Hi
            Something else must be missing then. If the sample can.

            B Offline
            B Offline
            Babs
            wrote on 12 Apr 2019, 12:59 last edited by
            #5

            @mrjj Thanks you, i'll check my code then.May have made a mistake somewhere.

            M A 2 Replies Last reply 12 Apr 2019, 13:04
            1
            • B Babs
              12 Apr 2019, 12:59

              @mrjj Thanks you, i'll check my code then.May have made a mistake somewhere.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 12 Apr 2019, 13:04 last edited by
              #6

              @Babs
              Yep. good plan.
              Its hard to guess at on forum but the sample is small, so should be easy to spot if its has more code
              for the Can class than you have.

              1 Reply Last reply
              1
              • B Babs
                12 Apr 2019, 12:59

                @mrjj Thanks you, i'll check my code then.May have made a mistake somewhere.

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 12 Apr 2019, 13:19 last edited by
                #7

                Hi @Babs,

                Just one note:

                device->setConfigurationParameter(QCanBusDevice::CanFdKey,false);

                That is not needed, as CanFd is disabled by default (and SYSTEC hardware is not FD capable, at least as far as I know).

                Regards

                Qt has to stay free or it will die.

                1 Reply Last reply
                0
                • A aha_1980 has marked this topic as solved on 31 Dec 2023, 12:14

                7/7

                12 Apr 2019, 13:19

                • Login

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