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. National Instruments USB 6002 read data in Qt Creator
QtWS25 Last Chance

National Instruments USB 6002 read data in Qt Creator

Scheduled Pinned Locked Moved Unsolved General and Desktop
39 Posts 8 Posters 12.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.
  • R Offline
    R Offline
    rockon209
    wrote on 29 Mar 2017, 06:10 last edited by
    #21

    @JKSH Yes the device is plugged into the computer. But when i see in the NI Measurement and automation explorer its not detected. I read some where if you have USB3.0 drivers then its not detecting the earlier format devices (even it is connected to USB1.0 or USB 2.0) not sure though what is the problem.
    I got this

    Received 0 points
    Error code for DAQmxCreateTask(): 0
    Error code for DAQmxCreateAIVoltageChan(): -88302
    Error code for DAQmxCfgSampClkTiming(): -200477
    Error code for DAQmxStartTask(): -200478
    Error code for DAQmxReadAnalogF64(): -200478
    Error code for DAQmxStopTask(): 0
    Error code for DAQmxClearTask (): 0

    J 1 Reply Last reply 29 Mar 2017, 09:03
    0
    • R rockon209
      29 Mar 2017, 06:10

      @JKSH Yes the device is plugged into the computer. But when i see in the NI Measurement and automation explorer its not detected. I read some where if you have USB3.0 drivers then its not detecting the earlier format devices (even it is connected to USB1.0 or USB 2.0) not sure though what is the problem.
      I got this

      Received 0 points
      Error code for DAQmxCreateTask(): 0
      Error code for DAQmxCreateAIVoltageChan(): -88302
      Error code for DAQmxCfgSampClkTiming(): -200477
      Error code for DAQmxStartTask(): -200478
      Error code for DAQmxReadAnalogF64(): -200478
      Error code for DAQmxStopTask(): 0
      Error code for DAQmxClearTask (): 0

      J Offline
      J Offline
      JKSH
      Moderators
      wrote on 29 Mar 2017, 09:03 last edited by
      #22

      @rockon209 said in National Instruments USB 6002 read data in Qt Creator:

      @JKSH Yes the device is plugged into the computer. But when i see in the NI Measurement and automation explorer its not detected. I read some where if you have USB3.0 drivers then its not detecting the earlier format devices (even it is connected to USB1.0 or USB 2.0) not sure though what is the problem.
      ...
      Error code for DAQmxCreateAIVoltageChan(): -88302

      Error -88302 seems to be related to driver problems: http://digital.ni.com/public.nsf/allkb/19E7993CF8366EED8625764200771C68?OpenDocument

      Anyway, your issue is definitely under National Instruments territory. I suggest you re-install your DAQmx drivers (preferably the latest version), and if you're still having issues, ask at the NI forum.

      Error code for DAQmxCfgSampClkTiming(): -200477
      Error code for DAQmxStartTask(): -200478
      Error code for DAQmxReadAnalogF64(): -200478

      See http://digital.ni.com/public.nsf/3efedde4322fef19862567740067f3cc/01d50d3f86ee67d8862576cf00745e78/$FILE/NI-DAQmxErrorCodes.PDF -- Errors -200477 and -200478 mean that DAQmx is complaining that you have no devices or channels.

      Once you fix error -88302, these should go away.

      (Final note: Since you are getting meaningful error codes from the DAQmx functions, this is further proof that your Qt application has successfully linked to the DAQmx library)

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rockon209
        wrote on 11 Apr 2017, 07:33 last edited by
        #23

        @JKSH It was the problem with NI software and uninstall the full software and install it again and now it works.
        I have one more question i want to read the digital Input signal and i am using "DAQmxReadDigitalU16" function to read but i am not getting the ouput
        i am getting following error:-
        The program has unexpectedly finished.

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rockon209
          wrote on 11 Apr 2017, 08:14 last edited by
          #24

          NO worries all good.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rockon209
            wrote on 13 Apr 2017, 09:41 last edited by
            #25

            @JKSH
            Hello JKSH as the code above mentioned i can get 1000 sample points when i run the code but if i want to read and store continuously the data from a port of the device how i can do it. Can you please helm me in this?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              smanchineella
              wrote on 8 Dec 2020, 19:27 last edited by
              #26

              @JKSH or anyone else how many experience in this field, I have encountered a similar issue to the one you have described in your previous posts. I have copied the sample code you posted above and have done extensive research, yet I am still receiving an error "Undefined Reference to DAQmxCreateTask' and so on for all my DAQmx commanddseventhough I have explicitly defined how the library is connected to the project in the project file as you have described in your previous post with the include path and library path. My paths also match yours exactly so I am incredibly confused on where this error is coming form. I have attached my source code, do you think you could take a quick look at what may be going wrong.

              projectfilescreenshot.PNG mainfilescreenshot.PNG errormessagedisplayed.PNG

              A 1 Reply Last reply 8 Dec 2020, 20:35
              0
              • S smanchineella
                8 Dec 2020, 19:27

                @JKSH or anyone else how many experience in this field, I have encountered a similar issue to the one you have described in your previous posts. I have copied the sample code you posted above and have done extensive research, yet I am still receiving an error "Undefined Reference to DAQmxCreateTask' and so on for all my DAQmx commanddseventhough I have explicitly defined how the library is connected to the project in the project file as you have described in your previous post with the include path and library path. My paths also match yours exactly so I am incredibly confused on where this error is coming form. I have attached my source code, do you think you could take a quick look at what may be going wrong.

                projectfilescreenshot.PNG mainfilescreenshot.PNG errormessagedisplayed.PNG

                A Offline
                A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on 8 Dec 2020, 20:35 last edited by
                #27

                Hi @smanchineella,

                some questions:

                • which compiler are you using?
                • which architecture, 32 or 64 bit?
                • where is the file NIDAQmx.lib located on your computer?

                Regards

                Qt has to stay free or it will die.

                S 1 Reply Last reply 9 Dec 2020, 19:37
                0
                • S Offline
                  S Offline
                  smanchineella
                  wrote on 9 Dec 2020, 18:22 last edited by smanchineella 12 Sept 2020, 19:37
                  #28
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • A aha_1980
                    8 Dec 2020, 20:35

                    Hi @smanchineella,

                    some questions:

                    • which compiler are you using?
                    • which architecture, 32 or 64 bit?
                    • where is the file NIDAQmx.lib located on your computer?

                    Regards

                    S Offline
                    S Offline
                    smanchineella
                    wrote on 9 Dec 2020, 19:37 last edited by
                    #29

                    @aha_1980 I am using the default compiler which came with qt (I believe it is MinGW-64 bit). Both the compiler and my pc are both 64 bit. The NIDAQmx.lib file is located at C:\Program Files (x86)\National Instruments\NI-DAQ\DAQmx ANSI C Dev\lib\msvc\NIDAQmx.lib

                    Please let me know if you see any issues with how it is setup on my pc. Any suggestions are greatly appreciated!

                    A 1 Reply Last reply 9 Dec 2020, 19:44
                    0
                    • S smanchineella
                      9 Dec 2020, 19:37

                      @aha_1980 I am using the default compiler which came with qt (I believe it is MinGW-64 bit). Both the compiler and my pc are both 64 bit. The NIDAQmx.lib file is located at C:\Program Files (x86)\National Instruments\NI-DAQ\DAQmx ANSI C Dev\lib\msvc\NIDAQmx.lib

                      Please let me know if you see any issues with how it is setup on my pc. Any suggestions are greatly appreciated!

                      A Offline
                      A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on 9 Dec 2020, 19:44 last edited by
                      #30

                      Hi @smanchineella,

                      ...\lib\msvc\NIDAQmx.lib suggests that this is an import library for MSVC compiler. It does not say if that import library is for 32 or 64 bit. Both can be a problem.

                      In principle, you cannot mix MSVC and MinGW compiler, so you will either need to switch to MSVC too, or find an include lib for MinGW.

                      Also, make sure both have the same bitness, otherwise it will likely also fail.

                      Regards

                      Qt has to stay free or it will die.

                      Pablo J. RoginaP J 2 Replies Last reply 9 Dec 2020, 19:55
                      1
                      • A aha_1980
                        9 Dec 2020, 19:44

                        Hi @smanchineella,

                        ...\lib\msvc\NIDAQmx.lib suggests that this is an import library for MSVC compiler. It does not say if that import library is for 32 or 64 bit. Both can be a problem.

                        In principle, you cannot mix MSVC and MinGW compiler, so you will either need to switch to MSVC too, or find an include lib for MinGW.

                        Also, make sure both have the same bitness, otherwise it will likely also fail.

                        Regards

                        Pablo J. RoginaP Offline
                        Pablo J. RoginaP Offline
                        Pablo J. Rogina
                        wrote on 9 Dec 2020, 19:55 last edited by
                        #31

                        It does not say if that import library is for 32 or 64 bit

                        Based on the installation folder C:\Program Files (x86)\National Instruments\... under Windows 64 bit, we can assume it's a 32 bit version of the library.

                        @smanchineella as @aha_1980 mentioned please pay attention at the compiler and bitness of the library you're trying to use.

                        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

                        S 1 Reply Last reply 9 Dec 2020, 20:25
                        2
                        • Pablo J. RoginaP Pablo J. Rogina
                          9 Dec 2020, 19:55

                          It does not say if that import library is for 32 or 64 bit

                          Based on the installation folder C:\Program Files (x86)\National Instruments\... under Windows 64 bit, we can assume it's a 32 bit version of the library.

                          @smanchineella as @aha_1980 mentioned please pay attention at the compiler and bitness of the library you're trying to use.

                          S Offline
                          S Offline
                          smanchineella
                          wrote on 9 Dec 2020, 20:25 last edited by smanchineella 12 Sept 2020, 20:29
                          #32

                          @Pablo-J-Rogina @aha_1980 When I downloaded the NIDAQmx file from the NI website, it said it includes both 32 and 64 bit import library depending on the bitness of the computer and the compiler. However, based on your both replies, how would I go about installing a 32 bit MSVC library and linking that in?

                          1 Reply Last reply
                          0
                          • A aha_1980
                            9 Dec 2020, 19:44

                            Hi @smanchineella,

                            ...\lib\msvc\NIDAQmx.lib suggests that this is an import library for MSVC compiler. It does not say if that import library is for 32 or 64 bit. Both can be a problem.

                            In principle, you cannot mix MSVC and MinGW compiler, so you will either need to switch to MSVC too, or find an include lib for MinGW.

                            Also, make sure both have the same bitness, otherwise it will likely also fail.

                            Regards

                            J Offline
                            J Offline
                            JKSH
                            Moderators
                            wrote on 9 Dec 2020, 22:03 last edited by
                            #33

                            @smanchineella said in National Instruments USB 6002 read data in Qt Creator:

                            I am using the default compiler which came with qt (I believe it is MinGW-64 bit).

                            The online Qt installer provides both 32-bit and 64-bit versions of MinGW. There is no default; you select the one you want to install.

                            You must install 3 things:

                            • A compiler
                            • Qt libraries
                            • DAQmx libraries

                            All 3 things must have the same bitness, and the Qt libraries must match your compiler.

                            @aha_1980 said in National Instruments USB 6002 read data in Qt Creator:

                            In principle, you cannot mix MSVC and MinGW compiler, so you will either need to switch to MSVC too, or find an include lib for MinGW.

                            The compiler for NIDAQmx.lib doesn't really matter because it is a C library, not a C++ library.

                            @smanchineella said in National Instruments USB 6002 read data in Qt Creator:

                            how would I go about installing a 32 bit MSVC library and linking that in?

                            You already have 32-bit DAQmx libraries. Now you need a 32-bit compiler and matching 32-bit Qt.

                            • Download the 32-bit MSVC compiler from Microsoft: https://visualstudio.microsoft.com/vs/features/cplusplus/
                            • Run MaintenanceTool.exe in your Qt folder and install Qt 5.15.2 for MSVC2019 (32-bit)

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            A 1 Reply Last reply 10 Dec 2020, 06:32
                            2
                            • J JKSH
                              9 Dec 2020, 22:03

                              @smanchineella said in National Instruments USB 6002 read data in Qt Creator:

                              I am using the default compiler which came with qt (I believe it is MinGW-64 bit).

                              The online Qt installer provides both 32-bit and 64-bit versions of MinGW. There is no default; you select the one you want to install.

                              You must install 3 things:

                              • A compiler
                              • Qt libraries
                              • DAQmx libraries

                              All 3 things must have the same bitness, and the Qt libraries must match your compiler.

                              @aha_1980 said in National Instruments USB 6002 read data in Qt Creator:

                              In principle, you cannot mix MSVC and MinGW compiler, so you will either need to switch to MSVC too, or find an include lib for MinGW.

                              The compiler for NIDAQmx.lib doesn't really matter because it is a C library, not a C++ library.

                              @smanchineella said in National Instruments USB 6002 read data in Qt Creator:

                              how would I go about installing a 32 bit MSVC library and linking that in?

                              You already have 32-bit DAQmx libraries. Now you need a 32-bit compiler and matching 32-bit Qt.

                              • Download the 32-bit MSVC compiler from Microsoft: https://visualstudio.microsoft.com/vs/features/cplusplus/
                              • Run MaintenanceTool.exe in your Qt folder and install Qt 5.15.2 for MSVC2019 (32-bit)
                              A Offline
                              A Offline
                              aha_1980
                              Lifetime Qt Champion
                              wrote on 10 Dec 2020, 06:32 last edited by
                              #34

                              @JKSH said in National Instruments USB 6002 read data in Qt Creator:

                              The compiler for NIDAQmx.lib doesn't really matter because it is a C library, not a C++ library.

                              While it is true you can use a C-API DLL with both compilers, the same is not true for the import library, at least based on my experience.

                              @smanchineella

                              When I downloaded the NIDAQmx file from the NI website, it said it includes both 32 and 64 bit import library

                              Then these must be somewhere in the directory tree, please have a look.

                              However, based on your both replies, how would I go about installing a 32 bit MSVC library and linking that in?

                              That's not what I said. I said, if you only get an import library for MSVC, then you have to use the MSVC compiler to use that lib.

                              Regards

                              Qt has to stay free or it will die.

                              J 1 Reply Last reply 10 Dec 2020, 07:32
                              1
                              • A aha_1980
                                10 Dec 2020, 06:32

                                @JKSH said in National Instruments USB 6002 read data in Qt Creator:

                                The compiler for NIDAQmx.lib doesn't really matter because it is a C library, not a C++ library.

                                While it is true you can use a C-API DLL with both compilers, the same is not true for the import library, at least based on my experience.

                                @smanchineella

                                When I downloaded the NIDAQmx file from the NI website, it said it includes both 32 and 64 bit import library

                                Then these must be somewhere in the directory tree, please have a look.

                                However, based on your both replies, how would I go about installing a 32 bit MSVC library and linking that in?

                                That's not what I said. I said, if you only get an import library for MSVC, then you have to use the MSVC compiler to use that lib.

                                Regards

                                J Offline
                                J Offline
                                JKSH
                                Moderators
                                wrote on 10 Dec 2020, 07:32 last edited by
                                #35

                                @aha_1980 said in National Instruments USB 6002 read data in Qt Creator:

                                @JKSH said in National Instruments USB 6002 read data in Qt Creator:

                                The compiler for NIDAQmx.lib doesn't really matter because it is a C library, not a C++ library.

                                While it is true you can use a C-API DLL with both compilers, the same is not true for the import library, at least based on my experience.

                                Ah, I see. I'd better double-check the libraries then.

                                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                S 1 Reply Last reply 18 Dec 2020, 15:49
                                0
                                • J JKSH
                                  10 Dec 2020, 07:32

                                  @aha_1980 said in National Instruments USB 6002 read data in Qt Creator:

                                  @JKSH said in National Instruments USB 6002 read data in Qt Creator:

                                  The compiler for NIDAQmx.lib doesn't really matter because it is a C library, not a C++ library.

                                  While it is true you can use a C-API DLL with both compilers, the same is not true for the import library, at least based on my experience.

                                  Ah, I see. I'd better double-check the libraries then.

                                  S Offline
                                  S Offline
                                  smanchineella
                                  wrote on 18 Dec 2020, 15:49 last edited by
                                  #36

                                  @JKSH @aha_1980
                                  I was able to fix the compilation error by adding two lines in my project file to link to a 64-bit version of the library and use a 64-bit compiler. However, I am not receiving another error which I think may be related.

                                  I am using the following import and include statements in my project file to link the library and the compiler

                                  LIBS += "C:/Program Files (x86)/National Instruments/Shared/ExternalCompilerSupport/C/lib64/msvc/NIDAQmx.lib"
                                  INCLUDEPATH += "C:/Program Files (x86)/National Instruments/Shared/ExternalCompilerSupport/C/include"
                                  When I build the sample code to obtain just some voltage samples, I am receiving an error

                                  DAQmx Error: Internal Software Error occurred in MIG software. Please contact National Instruments Support.
                                  Task Name: MyTask

                                  Status Code: -229771

                                  DAQmxErrChk(DAQmxCreateTask("MyTask", &taskHandle));

                                  The line above is the line which is throwing the error. When I did not have to mess with the bitness of the library and compiler on a linux machine, I did not receive any such errors.

                                  If anyone has any ideas on how to fix this issue please let me know as soon as possible. I have attached screenshots of my project file and my main file for additional reference as well. Thank you in advance!

                                  daqmxprojecterror.PNG daqmxmainerror.PNG

                                  J 1 Reply Last reply 19 Dec 2020, 01:35
                                  0
                                  • S smanchineella
                                    18 Dec 2020, 15:49

                                    @JKSH @aha_1980
                                    I was able to fix the compilation error by adding two lines in my project file to link to a 64-bit version of the library and use a 64-bit compiler. However, I am not receiving another error which I think may be related.

                                    I am using the following import and include statements in my project file to link the library and the compiler

                                    LIBS += "C:/Program Files (x86)/National Instruments/Shared/ExternalCompilerSupport/C/lib64/msvc/NIDAQmx.lib"
                                    INCLUDEPATH += "C:/Program Files (x86)/National Instruments/Shared/ExternalCompilerSupport/C/include"
                                    When I build the sample code to obtain just some voltage samples, I am receiving an error

                                    DAQmx Error: Internal Software Error occurred in MIG software. Please contact National Instruments Support.
                                    Task Name: MyTask

                                    Status Code: -229771

                                    DAQmxErrChk(DAQmxCreateTask("MyTask", &taskHandle));

                                    The line above is the line which is throwing the error. When I did not have to mess with the bitness of the library and compiler on a linux machine, I did not receive any such errors.

                                    If anyone has any ideas on how to fix this issue please let me know as soon as possible. I have attached screenshots of my project file and my main file for additional reference as well. Thank you in advance!

                                    daqmxprojecterror.PNG daqmxmainerror.PNG

                                    J Offline
                                    J Offline
                                    JKSH
                                    Moderators
                                    wrote on 19 Dec 2020, 01:35 last edited by JKSH
                                    #37

                                    @smanchineella said in National Instruments USB 6002 read data in Qt Creator:

                                    Task Name: MyTask

                                    Your C++ application was able to understand your Task name, which means your application is correctly linking to the DAQmx libraries. So everything is now correct on the Qt side, congratulations!

                                    DAQmx Error: Internal Software Error occurred in MIG software. Please contact National Instruments Support.

                                    That probably means your PC's NI hardware database is corrupted. Follow the instructions here to reset the database: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P8awSAC

                                    If that doesn't help, see here for other possible causes: https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P7a7SAC

                                    I have attached screenshots of my project file and my main file for additional reference as well.

                                    In the future, please post code as text instead of pictures. Text is easier for us to process.

                                    Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                    1 Reply Last reply
                                    3
                                    • S Offline
                                      S Offline
                                      smanchineella
                                      wrote on 25 Jan 2021, 18:18 last edited by JKSH
                                      #38
                                      #include <QObject>
                                      #include <QThread>
                                      #include <QCoreApplication>
                                      #include <atomic>
                                      #include <array>
                                      #include <NIDAQmx.h>
                                      #include <stdio.h>
                                      #include <QApplication>
                                      #include <QWidget>
                                      #include <QDebug>
                                      #include <iostream>
                                      #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
                                      
                                      using namespace std;
                                      
                                      int main(int argc, char **argv)
                                      {
                                      // Initialize a usual Qt application
                                      QApplication app(argc, argv);
                                      QWidget w;
                                      TaskHandle taskHandle = 0;
                                      int32 error = 0;
                                      int32 samplesReceived = 0;
                                      float64 data[1000];
                                      char errBuff[2048]={'\0'};
                                      DAQmxErrChk(DAQmxCreateTask("MyTask", &taskHandle));
                                      while(true)
                                      {
                                          cout << "Checkpoint 1" << endl;
                                          cout << "Checkpoint 2" << endl;
                                          DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
                                          DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 10000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000));
                                          DAQmxErrChk(DAQmxStartTask(taskHandle));
                                          DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 10.0, DAQmx_Val_GroupByChannel, data, 1000, &samplesReceived, NULL));
                                      
                                          // Print results
                                          qDebug() << "Received" << samplesReceived << "points";
                                          for (int i = 0; i < samplesReceived; i++)
                                              qDebug() << data[i];
                                      }
                                          DAQmxStopTask(taskHandle);
                                          DAQmxClearTask(taskHandle);
                                      
                                          Error:
                                      
                                                 if( DAQmxFailed(error) )
                                      
                                                        DAQmxGetExtendedErrorInfo(errBuff,2048);
                                      
                                                 if( taskHandle!=0 )  {
                                      
                                                        DAQmxStopTask(taskHandle);
                                      
                                                        DAQmxClearTask(taskHandle);
                                      
                                                 }
                                      
                                                 if( DAQmxFailed(error) ){
                                                        printf("DAQmx Error: %s\n",errBuff);
                                                        return 0;
                                                  }
                                      
                                          // Run Qt event loop
                                          w.show();
                                          return app.exec();
                                      }
                                      

                                      With this code, I tried the avenue you had presented to me but did not find much success in trying those methods. After a little more debugging, I was able to obtain a new error as follows:

                                      DAQmx Error: Specified operation cannot be performed while the task is running.
                                      Task Name: MyTask

                                      Status Code: -200479

                                      If you have any idea on how to resolve this issue please let me know. My project file has not changed since my last post. Thanks so much for the help.

                                      J 1 Reply Last reply 26 Jan 2021, 00:43
                                      0
                                      • S smanchineella
                                        25 Jan 2021, 18:18
                                        #include <QObject>
                                        #include <QThread>
                                        #include <QCoreApplication>
                                        #include <atomic>
                                        #include <array>
                                        #include <NIDAQmx.h>
                                        #include <stdio.h>
                                        #include <QApplication>
                                        #include <QWidget>
                                        #include <QDebug>
                                        #include <iostream>
                                        #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
                                        
                                        using namespace std;
                                        
                                        int main(int argc, char **argv)
                                        {
                                        // Initialize a usual Qt application
                                        QApplication app(argc, argv);
                                        QWidget w;
                                        TaskHandle taskHandle = 0;
                                        int32 error = 0;
                                        int32 samplesReceived = 0;
                                        float64 data[1000];
                                        char errBuff[2048]={'\0'};
                                        DAQmxErrChk(DAQmxCreateTask("MyTask", &taskHandle));
                                        while(true)
                                        {
                                            cout << "Checkpoint 1" << endl;
                                            cout << "Checkpoint 2" << endl;
                                            DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle, "Dev1/ai0", "", DAQmx_Val_Cfg_Default, -10.0, 10.0, DAQmx_Val_Volts, NULL));
                                            DAQmxErrChk(DAQmxCfgSampClkTiming(taskHandle, "", 10000.0, DAQmx_Val_Rising, DAQmx_Val_FiniteSamps, 1000));
                                            DAQmxErrChk(DAQmxStartTask(taskHandle));
                                            DAQmxErrChk(DAQmxReadAnalogF64(taskHandle, 1000, 10.0, DAQmx_Val_GroupByChannel, data, 1000, &samplesReceived, NULL));
                                        
                                            // Print results
                                            qDebug() << "Received" << samplesReceived << "points";
                                            for (int i = 0; i < samplesReceived; i++)
                                                qDebug() << data[i];
                                        }
                                            DAQmxStopTask(taskHandle);
                                            DAQmxClearTask(taskHandle);
                                        
                                            Error:
                                        
                                                   if( DAQmxFailed(error) )
                                        
                                                          DAQmxGetExtendedErrorInfo(errBuff,2048);
                                        
                                                   if( taskHandle!=0 )  {
                                        
                                                          DAQmxStopTask(taskHandle);
                                        
                                                          DAQmxClearTask(taskHandle);
                                        
                                                   }
                                        
                                                   if( DAQmxFailed(error) ){
                                                          printf("DAQmx Error: %s\n",errBuff);
                                                          return 0;
                                                    }
                                        
                                            // Run Qt event loop
                                            w.show();
                                            return app.exec();
                                        }
                                        

                                        With this code, I tried the avenue you had presented to me but did not find much success in trying those methods. After a little more debugging, I was able to obtain a new error as follows:

                                        DAQmx Error: Specified operation cannot be performed while the task is running.
                                        Task Name: MyTask

                                        Status Code: -200479

                                        If you have any idea on how to resolve this issue please let me know. My project file has not changed since my last post. Thanks so much for the help.

                                        J Offline
                                        J Offline
                                        JKSH
                                        Moderators
                                        wrote on 26 Jan 2021, 00:43 last edited by
                                        #39

                                        @smanchineella said in National Instruments USB 6002 read data in Qt Creator:

                                        DAQmx Error: Specified operation cannot be performed while the task is running.

                                        You get this error because your code repeatedly tries to call DAQmxCreateAIVoltageChan(), DAQmxCfgSampClkTiming(), and DAQmxStartTask() in the while loop. Those functions should only be called once; the while loop should only read the data.

                                        Note: Your while(true) loop blocks the Qt event loop. You won't be able to use the GUI if you run a permanent while loop. Qt is based on event-driven programming, so you should use a QTimer to read your data at fixed intervals instead: https://doc.qt.io/qt-5/qtimer.html

                                        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                        1 Reply Last reply
                                        2

                                        • Login

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