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. Segmentation fault while using real time connection with device.
QtWS25 Last Chance

Segmentation fault while using real time connection with device.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 556 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.
  • P Offline
    P Offline
    powp
    wrote on last edited by
    #1

    Hi,
    I want to write a application which download data form device in real time.
    I writed library in c++ using cyusb_control_transfer() for comunicate with my device.
    When i use this library in console program all is working.
    But when i want to add it in window qt program it has problem with memory.

    I made window in .ui file with graphicsView and button.
    To button i add function:

    void Window::on_ButtonStart_clicked()
    {
        drawDataOnScreen();
    }
    

    Draw data function:

    void Window::drawDataOnScreen()
    {
        m_chart = new QChart;
        m_chart->setMinimumSize(721, 301);
        m_chart->setMaximumSize(721, 301);
        m_chart->legend()->hide();
    
        QLineSeries *series = new QLineSeries;
    
        cyusb_handle *h;
        h = cyusb_gethandle(0);
        globalResetAllDeviceRegister(h);
        switchONDevice(h);
    
        unsigned short len = packetLengthRegister(h);
        unsigned int *source = sourceFromPacket(h, len);
    
        for(int i=0; i<1; i++)
        {
            series->append(0.001*i, source[i+54]);
        }
    
        delete[] source;
    
        switchOFFDevice(h);
        globalResetAllDeviceRegister(h);
        closeDevices();
    
        m_chart->addSeries(series);
        m_chart->createDefaultAxes();
        m_chart->setAcceptHoverEvents(true);
    
        scene->addItem(m_chart);
    }
    

    When i debug i get this:

    Signal from system: SIGSEGV
    Meaning of signal: Segmentation fault
    

    And it stop in first data transfer:

    unsigned char *databuff = new unsigned char[2];
    
    if(cyusb_control_transfer(h, 0x02, 0x04, 0, 0, databuff, 0, TIME_OUT))
            return 1;
    

    What i do worng?

    Gojir4G 1 Reply Last reply
    0
    • P powp

      Hi,
      I want to write a application which download data form device in real time.
      I writed library in c++ using cyusb_control_transfer() for comunicate with my device.
      When i use this library in console program all is working.
      But when i want to add it in window qt program it has problem with memory.

      I made window in .ui file with graphicsView and button.
      To button i add function:

      void Window::on_ButtonStart_clicked()
      {
          drawDataOnScreen();
      }
      

      Draw data function:

      void Window::drawDataOnScreen()
      {
          m_chart = new QChart;
          m_chart->setMinimumSize(721, 301);
          m_chart->setMaximumSize(721, 301);
          m_chart->legend()->hide();
      
          QLineSeries *series = new QLineSeries;
      
          cyusb_handle *h;
          h = cyusb_gethandle(0);
          globalResetAllDeviceRegister(h);
          switchONDevice(h);
      
          unsigned short len = packetLengthRegister(h);
          unsigned int *source = sourceFromPacket(h, len);
      
          for(int i=0; i<1; i++)
          {
              series->append(0.001*i, source[i+54]);
          }
      
          delete[] source;
      
          switchOFFDevice(h);
          globalResetAllDeviceRegister(h);
          closeDevices();
      
          m_chart->addSeries(series);
          m_chart->createDefaultAxes();
          m_chart->setAcceptHoverEvents(true);
      
          scene->addItem(m_chart);
      }
      

      When i debug i get this:

      Signal from system: SIGSEGV
      Meaning of signal: Segmentation fault
      

      And it stop in first data transfer:

      unsigned char *databuff = new unsigned char[2];
      
      if(cyusb_control_transfer(h, 0x02, 0x04, 0, 0, databuff, 0, TIME_OUT))
              return 1;
      

      What i do worng?

      Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by
      #2

      @powp Hi,

      Probably cyusb_gethandle(0) returns null or not a valid pointer.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        Where are you calling cyusb_control_transfer from ?

        Did you declare a cyusb_handle named h class member variable ?

        If so you are likely not initialising it and the one you have in drawDataOnScreen is not the same.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • P Offline
          P Offline
          powp
          wrote on last edited by
          #4

          I don't know whats hapenned.
          I debug my program very cerrfully with much more traps and it starts works.
          I didn't change anything in my program.
          But thanks for help.

          Pablo J. RoginaP 1 Reply Last reply
          0
          • P powp

            I don't know whats hapenned.
            I debug my program very cerrfully with much more traps and it starts works.
            I didn't change anything in my program.
            But thanks for help.

            Pablo J. RoginaP Offline
            Pablo J. RoginaP Offline
            Pablo J. Rogina
            wrote on last edited by
            #5

            @powp if your issue is solved, please don't forget to mark your post as such. Thanks

            Upvote the answer(s) that helped you solve the issue
            Use "Topic Tools" button to mark your post as Solved
            Add screenshots via postimage.org
            Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0

            • Login

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