Acquire continuous data but write to excel at intervals

I am acquiring continuous data (voltage & temp) from a DAQmx unit. At the same time I would like to record to a spreadsheet X number of samples (say 100) at 1minute intervals only. Also, I would like to really only record two values from those 100 samples (a min & max value). I have a working code, however I cannot figure out how to write to spreadsheet at the 1 minute intervals for X number of samples. So I am stuck. TIA
Solved!
Go to Solution.
Attachments:
Prog3.vi ‏220 KB

Thanks for the info. I will have to examine how to modify my code to use the producer/consumer design. Would I simply put my acquisition of data in the first loop, with my graphs etc. Then create a second while loop to record the data. I dont under stand the third part of the diagram "release queue". Sorry I'm a NOOB!

Similar Messages

  • Continuous data acquisition, visual c, excel

     Hi,
    I’m trying to build an MFC application with MSVC++6, where I would continuously acquire
    samples
    from 2 channels of a USB-6289. I’m using the DAQmx C functions. First I
    declear the callback fun as static function in the dialog class:
           class DataCollectionWin : public CDialog 
    static int32 CVICALLBACK
    EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType,
    uInt32 nSamples, void *callbackData);
    static int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
    CString str;
     char* FileName;
    Click "start tracking" to start data collection and save to an excel file:
    void DataCollectionWin:nStartTracking()
        // TODO: Add your control notification handler code here
    float64 data[2000];
    int32    read=0;
    int32 errorcode=0;
    int i,length;
    int32   error=0;
        char    errBuff[2048]={'\0'};
    //********Connect DAQ channels***********
        CString    szButtonText;
        CString szFilter = "Excel Files (*.xls)|*.xls|All Files (*.*)|*.*||";
        CFileDialog dlg(FALSE,"Excel",NULL,OFN_OVERWRITEPROMPT,szFilter);
        GetDlgItem( IDStartTracking)->GetWindowText( szButtonText );
        /* if the text read Start, then we start, else we stop tracking */
        if (  szButtonText == "Start Tracking" )
              if(dlg.DoModal()==IDOK)
            str=dlg.GetPathName ();
            UpdateData(TRUE);
            if(!cfData.Open (str,CFile::modeCreate|CFile::modeReadWrite))
     MessageBox("create/read/write file fail","warning",
    MB_ICONWARNING | MB_OK);
            length=str.GetLength();
            FileName=new char[length];
            for(i=0;i<length;i++)
            *(FileName+i)=str.GetAt(i);
            *(FileName+length)=NULL;
       DAQmxErrChk(DAQmxCreateTask ("connect", &taskHandle));
    DAQmxErrChk(DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0,Dev1/ai1","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
     DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,1000,-1,DAQmx_Val_GroupByChannel,data,2000,&read,NULL));
            DAQmxErrChk
    (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
            DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
            Error:
        if( DAQmxFailed(error) ) {
            DAQmxGetExtendedErrorInfo(errBuff,2048);
            MessageBox(errBuff);
            DAQmxStopTask(taskHandle);
            DAQmxClearTask(taskHandle);
                return;
            GetDlgItem( IDStartTracking )->SetWindowText("Stop Tracking");
        else
        //    nStopTracking();
        {    GetDlgItem( IDStartTracking )->SetWindowText("Start Tracking");
        DAQmxStopTask(taskHandle);
        DAQmxClearTask(taskHandle);
         cfData.Close();
    static int32 EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData)
        int32       error=0;
        char    errBuff[2048]={'\0'};
        static int  totalRead=0;
        int32       read=0;
        float64     data[1000];
        FILE *datafile;
        datafile = fopen(FileName,"w+");
        int i;
     if (datafile == NULL )
          printf( "The file was not opened\n" );
        // DAQmx Read Code
        DAQmxErrChk(DAQmxReadAnalogF64(taskHandle,1000,-1,DAQmx_Val_GroupByChannel,data,2000,&read,NULL));
        printf("data number: %d\n",read);
            if( read>0 ) {
        for (i=0;i<2000;i++)
                fprintf(datafile,"%f\n",data[i]);
            fflush(stdout);
                 Error:
        if( DAQmxFailed(error) )
            DAQmxGetExtendedErrorInfo(errBuff,2048);
            DAQmxStopTask(taskHandle);
            DAQmxClearTask(taskHandle);
            printf("DAQmx Error: %s\n",errBuff);
                return 0;
    static int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
        int32   error=0;
        char    errBuff[2048]={'\0'};
        printf("hello"); 
        // Check to see if an error stopped the task.
        DAQmxErrChk (status);
    Error:
        if( DAQmxFailed(error) ) {        DAQmxGetExtendedErrorInfo(errBuff,2048);
                  DAQmxClearTask(taskHandle);
        return 0;
     Can anyone check the codes for me? when i run the program, no data is save into the excel file. It seems the EveryNCallback
    function does not work, because when I put "printf("hello"); "for
    checking,nothing happens. Also there is an debug assertion error (see
    enclosure). 
    Actually how does the callback function work to continuously collect the data? 
    Thank you!
    kg 
    Attachments:
    error.JPG ‏31 KB

    Loaded symbols for 'C:\WINDOWS\system32\MFC42D.DLL'
    Loaded symbols for 'C:\WINDOWS\system32\MSVCRTD.DLL'
    Loaded symbols for 'C:\WINDOWS\system32\MFCO42D.DLL'
    Loaded 'C:\WINDOWS\system32\shimeng.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\imm32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\lpk.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\usp10.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\comctl32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\uxtheme.dll', no matching symbolic information found.
    Loaded 'C:\Program Files\Aculearn\AcuSTUDIO5\MsnHookDll.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\winmm.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\serwvdrv.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\umdmxfrm.dll', no matching symbolic information found.
    Loaded 'C:\Program Files\SweetIM\Messenger\mgAdaptersProxy.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\MSCTF.dll', no matching symbolic information found.
    Loaded 'C:\kaiguo\Powerword 2003\Cjktl32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\Downloaded Program Files\BDPlugin.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\version.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\apphelp.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\MSCTFIME.IME', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\comdlg32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\clbcatq.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\comres.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\cscui.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\cscdll.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\browseui.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\userenv.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\ntshrui.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\atl.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\netapi32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\shdocvw.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\crypt32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\msasn1.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\cryptui.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\wintrust.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\imagehlp.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\wininet.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\wldap32.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\riched20.dll', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\MAX\mxs.dll', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\MAX\mxsutils.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\msvcp71.dll', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\MAX\mxsout.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\mswsock.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\hnetcfg.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\wshtcpip.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\nismslu.dll', no matching symbolic information found.
    Loaded 'C:\WINDOWS\system32\nidevldu.dll', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NI6535.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nics.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NIDSA.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\niem.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nies.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NIFILTER.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NIHWDB.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NIMAS.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NISCXI.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nisd.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NISFT.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\niss.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\NISWCH.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nitio.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\niwf.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\nixs.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NI5690.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NIDWG.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NIHSD.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NIPS.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NIRFSA.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NISL.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NISRC.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NISYNC.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NITNR.sdc', no matching symbolic information found.
    Loaded 'C:\Program Files\National Instruments\NI-DAQ\Caps\Compat\NITSU.sdc', no matching symbolic information found.

  • Acquiring continuous data using an event structure

    I am new to labview, having recently taken the Core I and II courses.
    I am programming a test rig to acquire the linear position of a hydraulic cylinder and plot it over time.  In programming this code, I elected to use an event structure so that when a front panel button is pressed, a certain part of the test is run. 
    In one particular part of the test, called the Snub Test, I need to measure the position of the cylinder over time and plot it to a graph.  The data acquisition needs to be continuous, however the event structure only allows the loop to run once. 
    I have attached a portion of my code for reference.
    Can someone please advise how I can get this data acquisition to run continuously until the user (or a reference trigger) stops the test?
    Thanks
    Attachments:
    Front Panel.vi ‏115 KB

    A few comments to your VI in general:
    You changed the stop button to "switch until released", most likely because you fabricated a race condition and did this as a quick fix. The reason is (1) your placement of the stop terminal outside the event structure and (2) the use of a local variable wired to the stop condition. The button terminal of a latch action boolean belong inside it's associated event case! This way it gets read (and reset to false) when the event occurs. In your case, the local variable and the button get read before the event occurs and the loop needs to spin once more at the event that occurs when you release it (true->false). At this point, the local is still true from the earlier event and the loop stops. Correct would be: latch action, stop terminal inside stop case and wired to the stop condition from inside the event. Other cases use the default output (false) and don't stop the loop.
    Your "equal false" code fragment is just an invert, right? So why complicate things?
    Why do you need a wait if there is an event structure?
    LabVIEW Champion . Do more with less code and in less time .

  • Problem with writing continuous data to excel using using Report Generation vi's

    Hey Everyone,
    I am trying to read the data from DAQ and write to excel continuously using Report Generation vi's. 
    But when I run the VI, it writes only one interation of the while loop (gathering data from DAQ continuously) and doesn't append the data into the same file when I run it again after stoping the VI. 
    I have attached the VI i created. Please let me know if you have any idea to solve this issue. 
    Thanks
    Attachments:
    sample 5.vi ‏35 KB

    There are two problems with your VI.  First, the basic logic of writing/appending to a file (Excel, TDMS, anything) should go something like this:  Open the file, position yourself at the end of the file, then, in the loop, acquire data and write it to the file until you are finished with data acquisition.  When you exit the acquire/write to file loop, then close the file.  In particular, the opening and the closing of the file should not be inside the loop.
    As others have pointed out, writing to Excel might not be optimal, particularly if you are acquiring data at a high rate (and would therefore be writing a lot of data). We actually use Excel in our data acquisition routine, mainly reading from a WorkSheet to get the parameters of a particular stimulus, but also writing the outcome of the response to the stimulus.  As it happens, our "acquisition rate" in this example is on the order of several samples per minute, so there's no problem using Excel (we also sample 16 channels of analog data at 1 KHz -- this gets written as a binary file).
    Second, if you really do want to use Excel, use the (existing) Excel file to which you want to append as the "template" argument of the New Report function.  Then use the Excel Get Last Row function to position yourself at "end of file", as noted above.
    Good Luck.
    Bob Schor

  • How do I write an excel file and check what the next empty column would be to put the data in?

    I have somehow managed to write the portion of labview that prompts the user for a name. It checks a file to see if they are a new user or not and then assigns a number if they are. The program then acquires data that is to be put into a spreadsheet. Each subject will have ten trials which will have three columns. How do I get the information into the columns and then check each time to see which column it should go into (i.e. the next empty column for that subject). I have attached what I have thus far. I wrote this a long time ago and haven't touched it for some time so everything is a blur.
    Attachments:
    promptForSwimmerName.vi ‏76 KB
    Swimmers.dat ‏1 KB
    Main__dummy.vi ‏28 KB

    To perform those operations in excel you will use ActiveX. I will attach some examples of using Excel in LabVIEW and you can use these to do exactly what you want.
    These three examples show how to manipulate properties, write to excel and read from excel. Let me know if there is more I can do.
    Allan S.
    Applications Engineering
    National Instruments
    Attachments:
    BorderExample.vi ‏102 KB
    ActiveX_write_Rows_To_Excel2000.vi ‏90 KB
    ReadExample.vi ‏80 KB

  • How to use ActiveX to open/write to Excel template but not to overwrite it

    Hi there again (it's me...if anyone recognised me...)
    I managed to use ActiveX to open Excel and make it visible onto the screen. But I would like to know how can I make Excel open an Excel template and let me write data to the cells without overwriting the original template. I did try to use another program source such as the EXCEL TOOLKIT but I can't still figure out how does it work for my case. Is there a simpler example for me to refer too? Please help.
    Thank you,
    juni

    Hi Mike..
    I have tried to use the examples provided LabView 6.0. I don't understand how to use the Range value to get the data from my global array and also how to open the template and write data to it.
    At the moment, I could only open a saved dialog box and a default string filename is used to save my data into a new Excel but not the formatted excel which I want.
    If possible, please help again. Vi attached.
    Attachments:
    savefile.vi ‏109 KB
    datarecords.vi ‏12 KB

  • Please Help...!!  Is this to possible add data to write excel via java script

    Team:
    Is this possible to write data to Excel using javascript.
    I have created ScriptUI Dialog window. but i can't able to store datas in Excel.
    I can add data column wise in excel( using writeln comment) but I can't able add data to Row wise.
    Please anyone help me to solve this problem...
    Thanks in Advance.
    -yajiv
    Source Window :
    and the outputs wants......
    save the excel name to the Batch ID..

    Hi Everyone!
    I can add data column wise in excel( using writeln comment) but I can't able add data to Row wise.
    Please anyone help me to solve this problem...
    Thanks in Advance...
    -yajiv....
    Code :
    var myDoc = app.activeDocument;
    var myAllLinks = myDoc.allGraphics;
    var myLink=new Array()
    var mySeen = Object;
        var myLogFile = new File("~/Desktop/Link Files.xls");
        myLogFile.open("w", undefined, undefined)
        myLogFile.writeln("Link Name");
          for ( i = 1; i < myAllLinks.length; i++ )
                var myLinkName = myAllLinks[i].itemLink.name;
                var l=myLinkName.length;
               var T=myLinkName.substring(l-4);
                if (T==".tif"){
                    myLogFile.writeln(myAllLinks[i].itemLink.name);

  • How concatenate date and array to write in excel?

    Hello
    I have a problem to concatenate a date array and numeric array. can you help me?
    I want save Measurement of a sensor with save time in an excel (row 1 column1 save date and row 1 coulmn : save sensor data). but I cant save these two value seperatly(my clocks cant do it). now, I want concatenate them at first and then save them. is it possible?
    Best Regards
    Solved!
    Go to Solution.
    Attachments:
    concatenate.jpg ‏82 KB

    Try the attached.  You'll understand it as soon as you see it.  If not, shout.
    Attachments:
    write_to_file.vi ‏8 KB

  • Write to excel file slows down reading voltage channels

    Hi all,
    I read in input voltage data using PCI 6143 throught finite sampling. This VI is supposed to, for example, after acquiring 240 samples, I write all collected voltages to an excel file. Before I write the data into excel, I need to re-arrange the data array. This re-arranging task takes up quite a significant amount of time (about ~30ms). Hence, the 2nd batch of 240 samples collected is only done after arranging data and writing to file.
    Hence the process will be like, 0.9milli sec of data, wait 30milli sec, 0.9milli sec of data, wait 30milli sec and so on.
    So is it possible to pass this huge chunk of data to another VI, specifically doing the data manipulation and writing to file while the main VI continue collecting the voltage data without data losses?
    Does anyone have any suggestion by which mean am I able to do this?
    I saw a nice example in LV 7.1 example finder-> optimizing applications synchronizing tasks->Pass Data with Notifiers.vi
    Is this notifier method the solution to my problem or is there some other means to achieve the results?
    Thanks everybody!
    Best regards,
    Dick

    Hi Dick,
    I have some question you set the Sample Mode to Finite samples, why. If you do this you will miss samples!
    You start and stop the tasks every iteration, this will cause great wait times
    You can move the constat vi's outside the while loops.
    If you use continious samples you have to wire up the samples per channel to the ai read vi.
    If i profile the VI I see that voltage data-constants takes 3.6 ms of time (average).
    Also you should open the file outside the while loop and use the array to to spreadsheet string vi and write to text file to write the data. Successfully close the file after the while loop.
    In general opening/starting/closing/ending should not be done inside a repetative loop.
    It looks to me that 'voltage data constants.vi' generates an spreadsheet string from the data with a time column added.:
    this can be done like this:
    EDIT:Also you'r vi will 'remember' all the previous string and adds these together. If you don't want this initialize the shift register with an empty string, i missed the 'firstrun' case, but it is still better to initialize the shift register correctly, or you can connect the iteration number straight to the switch case
    Ton
    Message Edited by TonP on 09-28-2006 11:34 AM
    Message Edited by TonP on 09-28-2006 11:45 AM
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!
    Attachments:
    Example_BD.png ‏2 KB

  • Oracle Database Table data Load it into Excel

    Hello All,
    Please I need your help for this problem:
    I need to load Oracle database Table data and load it into Excel and saved with xls format.
    Example -Select * from Slase data load it into the Excel.
    I appreciate ans sample code to help me do that, Please help me out. This is very urgent.
    Thanks alot and best regards,
    anbu

    >
    I need to load Oracle database Table data and load it into Excel and saved with xls format.
    Example -Select * from Slase data load it into the Excel.
    I appreciate ans sample code to help me do that, Please help me out. This is very urgent.
    >
    Nothing in these forums is 'urgent'. If you have an urgent problem you should contact Oracle support or hire a consultant.
    You have proven over and over again that you are not a good steward of the forums. You continue to post questions that you say are 'urgent' but rarely take the time to mark your questions ANSWERED when they have been.
    Total Questions: 90 (78 unresolved)
    Are you willing to make a commitment to to revisit your 78 unresolved questions and mark them ANSWERED if they have been?
    The easiest way to export Oracle data to Excel is to use sql developer. It is a free download and this article by Jeff Smith shows how easy it is
    http://www.thatjeffsmith.com/archive/2012/09/oracle-sql-developer-v3-2-1-now-available/
    >
    And One Last Thing
    Speaking of export, sometimes I want to send data to Excel. And sometimes I want to send multiple objects to Excel – to a single Excel file that is. In version 3.2.1 you can now do that. Let’s export the bulk of the HR schema to Excel, with each table going to it’s own workbook in the same worksheet.
    >
    And you have previously been ask to read the FAQ at the top of the thread list. If you had done that you would have seen that there is a FAQ for links that have many ways, with code, to export data to Excel.
    5. How do I read or write an Excel file?
    SQL and PL/SQL FAQ

  • Conversion from scaled ton unscaled data using Graph Acquired Binary Data

    Hello !
    I want to acquire temperature with a pyrometer using a PCI 6220 (analog input (0-5V)). I'd like to use the VI
    Cont Acq&Graph Voltage-To File(Binary) to write the data into a file and the VI Graph Acquired Binary Data to read it and analyze it. But in this VI, I didn't understand well the functionnement of "Convert unscaled to scaled data", I know it takes informations in the header to scale the data but how ?
    My card will give me back a voltage, but how can I transform it into temperature ? Can I configure this somewhere, and then the "Convert unscaled to scaled data" will do it, or should I do this myself with a formula ?
    Thanks.

    Nanie, I've used these example extensively and I think I can help. Incidently, there is actually a bug in the examples, but I will start a new thread to discuss this (I haven't written the post yet, but it will be under "Bug in Graph Acquired Binary Data.vi:create header.vi Example" when I do get around to posting it). Anyway, to address your questions about the scaling. I've included an image of the block diagram of Convert Unscaled to Scaled.vi for reference.
    To start, the PCI-6220 has a 16bit resolution. That means that the range (±10V for example) is broken down into 2^16 (65536) steps, or steps of ~0.3mV (20V/65536) in this example. When the data is acquired, it is read as the number of steps (an integer) and that is how you are saving it. In general it takes less space to store integers than real numbers. In this case you are storing the results in I16's (2 bytes/value) instead of SGL's or DBL's (4 or 8 bytes/value respectively).
    To convert the integer to a scaled value (either volts, or some other engineering unit) you need to scale it. In the situation where you have a linear transfer function (scaled = offset + multiplier * unscaled) which is a 1st order polynomial it's pretty straight forward. The Convert Unscaled to Scaled.vi handles the more general case of scaling by an nth order polynomial (a0*x^0+a1*x^1+a2*x^2+...+an*x^n). A linear transfer function has two coefficients: a0 is the offset, and a1 is the multiplier, the rest of the a's are zero.
    When you use the Cont Acq&Graph Voltage-To File(Binary).vi to save your data, a header is created which contains the scaling coefficients stored in an array. When you read the file with Graph Acquired Binary Data.vi those scaling coefficients are read in and converted to a two dimensional array called Header Information that looks like this:
    ch0 sample rate, ch0 a0, ch0 a1, ch0 a2,..., ch0 an
    ch1 sample rate, ch1 a0, ch1 a1, ch1 a2,..., ch1 an
    ch2 sample rate, ch2 a0, ch2 a1, ch2 a2,..., ch2 an
    The array then gets transposed before continuing.
    This transposed array, and the unscaled data are passed into Convert Unscaled to Scaled.vi. I am probably just now getting to your question, but hopefully the background makes the rest of this simple. The Header Information array gets split up with the sample rates (the first row in the transposed array), the offsets (the second row), and all the rest of the gains entering the for loops separately. The sample rate sets the dt for the channel, the offset is used to intialize the scaled data array, and the gains are used to multiply the unscaled data. With a linear transfer function, there will only by one gain for each channel. The clever part of this design is that nothing has to be changed to handle non-linear polynomial transfer functions.
    I normally just convert everything to volts and then manually scale from there if I want to convert to engineering units. I suspect that if you use the express vi's (or configure the task using Create DAQmx Task in the Data Neighborhood of MAX) to configure a channel for temperature measurement, the required scaling coefficients will be incorporated into the Header Information array automatically when the data is saved and you won't have to do anything manually other than selecting the appropriate task when configuring your acquisition.
    Hope this answers your questions.
    ChrisMessage Edited by C. Minnella on 04-15-2005 02:42 PM
    Attachments:
    Convert Unscaled to Scaled.jpg ‏81 KB

  • Continuous Data Aquisition to SS File

    Recently we used the example from the Labview program "Continuous Data Acquisition to SS File.vi" and modified it a little and tried to keep all
    necessary things in the program to meet our test requirement. Basically we have 8 channels to collect the voltages from the test materials. After a
    test run, I realized that it only display the raw data for the channels (8 columns) but no corresponding time column to it. Can any one tell me how to add this time column. thanks
    Attachments:
    Voltage_Reading.vi ‏107 KB

    I could not open your VI as I do not have version 6.1 installed. So here are some comments...
    You can build a 1-D array of time steps by using a for loop, delta T (the inverse of the ACTUAL scan rate as indicated from the acquire VI), and the number of points (use the Array Size function on one of the data columns).
    Now, since the DAQ VIs output in column major order, first transpose the DAQ record and then use the bulid array fuction to add the new row to the first position.
    Transpose the new array back to column orientation and write to spreadsheet file.

  • How to find out each Cell having Data or Not in Excel File by Using WDJ

    Hi Friends,
    I have one doubt on WDJ.
    I have to Upload Excel File. Click on Upload Button in Excel file Data will move to One Bapi. This is I was done. But my Requirement is if any empty Cell in Excel That File not uploaded it display one error message Please upload Correct Excel File
    How to find out each Cell having Data or Not in Excel File by Using WDJ. Please tell me.
    By Using this Code I have Upload Excel File
    InputStream text = null;
         int temp = 0;
         //wdComponentAPI.getMessageManager().reportSuccess("filePath Vijay:::");
         try
                   File file = new File(wdContext.currentContextElement().getResource().getResourceName().toString());     
    FileOutputStream op = new FileOutputStream(file);
                   if (wdContext.currentContextElement().getResource()!= null)
                          text = wdContext.currentContextElement().getResource().read(false);
                             while((temp=text.read())!= -1)
                                  op.write(temp);
                                  op.flush();
                                  op.close();
                                  path = file.getAbsolutePath();
                                  //wdComponentAPI.getMessageManager().reportSuccess("Path Name :::::"+path);
         catch(Exception ex)               
                   ex.printStackTrace();
    But my Requirement is If excel having any Empty Cell that excel file not uploaded.How to do this...
    Regards
    Vijay Kalluri

    Hi my friend
    I would like to share you some APACHE APi´s that i use when i have to read excel files in Web Dynpro.
    JAR = poi-3.2-FINAL-20081019.jar
    Some Example:
    POIFSFileSystem fs;
    HSSFWorkbook wb;
    HSSFSheet sheet;
    String myMexican_ValueFromExcelis = "";
    try {
             fs = new POIFSFileSystem(new FileInputStream();
             // and select the cell "y"
            cell = row.getCell( 0 );
            myMexican_ValueFromExcelis = cell.getCellValue();  
    }cach(Exception e){
    REgargds

  • To fatch the data from sql to excel ??? any idea....

    dear all,
    my problem is - i want to retrive the data from sql server to excel sheet... can any one suggest the idea what to do ???
    thanks.

    You can open two connections. One to SQL Server (you can use a thin or JDBC-ODBC bridge), the other to your Excel spreadsheet using the JDBC-ODBC bridge. You could query the SQL Server database, massage and format your data, then write it to Excel. Excel works with a very limited set of SQL. Here is a program from a post by Tim Vickers that others sounded happy to have. I'm reposting here for your convenience. I have not personally run this program, so please use it at your own risk.
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import java.text.*;
    * Name: Excel.java
    * Purpose: To demonstrate how to use ODBC and Excel to create
    * a table,
    * insert data into it, and select it back out.
    * Version: Developed using JDK 1.3, but also works with JDK
    * 1.2.2
    * Instructions:
    * 1) Create a new Excel spreadsheet
    * 2) Create a new ODBC data source that points to this
    * spreadsheet
    * a) Go to Control Panel
    * b) Open "ODBC Data sources (32-bit) (wording may be
    * slightly
    * different for different platforms)
    * c) Under "User DSN" tab, press "Add" button
    * d) Select the "Microsoft Excel Driver (*.xls)" and
    * press
    * "Finish" button
    * e) Enter "Data Source Name" of "TestExcel"
    * f) Press "Select Workbook" button
    * g) Locate and select the spreadsheet you created in
    * Step 1
    * h) Unselect the "Read Only" checkbox
    * i) Press "Ok" button
    * 3) Compile and run Excel.java
    * 4) Open Excel spreadsheet and you will find a newly
    * created
    * sheet, GOOD_DAY, with three rows of data.
    * Notes:
    * If you want to select data from a spreadsheet that was
    * NOT
    * created via JDBC-ODBC (i.e. you entered data manually
    * into
    * a spreadsheet and want to select it out), you must
    * reference
    * the sheet name as "[sheetname$]".
    * When you create the table and insert the data using
    * Java, you
    * must reference the sheet name as "sheetname".
    * Also, do not have the spreadsheet open when you are
    * running
    * the program. You can get locking conflicts.
    public class Excel {
        public Excel() {
            setDefaults();
        private static void m(String pMessage) {
            System.out.println(pMessage);
        private void setDefaults() {
            setDriver("sun.jdbc.odbc.JdbcOdbcDriver");
            setUrl("jdbc:odbc");
            // ODBC data source named "TestExcel" defined from
            Control Panel
            setDataSource("TestExcel");
            setTableName("GOOD_DAY");
        public void openDatabase() {
            String lConnectStr = getUrl()+":"+getDataSource();
            try {
                Class.forName(getDriver());
                gConnection = DriverManager.getConnection(lConnectStr);
            catch (Exception e) {
                m("openDatabase(): "+e.getMessage());
        private void closeDatabase() {
            try {
                getConnection().close();
            catch (Exception e) {
                m("closeDatabase(): "+e.getMessage());
        private void createTable() {
            m("createTable() begin");
            Statement lStat = null;
            try {
                lStat = getConnection().createStatement();
                lStat.execute("CREATE TABLE "+getTableName()+" ("
                +" ID INTEGER"
                +" ,NAME VARCHAR"
                +")");
            catch (Exception e) {
                m("createTable(): "+e.getMessage());
            m("createTable() end");
        private void doInsert() {
            m("doInsert() begin");
            Statement lStat = null;
            try {
                lStat = getConnection().createStatement();
                lStat.executeUpdate("INSERT INTO "
                +getTableName()+"(ID,NAME) VALUES
                (10,'KANGAROO')");
                lStat.executeUpdate("INSERT INTO "
                +getTableName()+"(ID,NAME) VALUES (20,'KOALA')");
                lStat.executeUpdate("INSERT INTO "
                +getTableName()+"(ID,NAME) VALUES (30,'PAUL
                HOGAN')");
                lStat.close();
            catch (Exception e) {
                m("doInsert(): "+e.getMessage());
            m("doInsert() end");
        private void doQuery() {
            m("doQuery() begin");
            try {
                Statement lStat = getConnection().createStatement();
                ResultSet lRes = lStat.executeQuery(
                "SELECT * FROM "+getTableName()
                ResultSetMetaData lMeta = lRes.getMetaData();
                // print out the column headers separated by commas
                for (int i = 1; i <= lMeta.getColumnCount(); ++i) {
                    if (i > 1)
                        System.out.print(", ");
                    String lValue = lMeta.getColumnName(i);
                    System.out.print(lValue);
                System.out.println("");
                // print out the data separated by commas
                while (lRes.next()) {
                    for (int i=1; i<=lMeta.getColumnCount(); ++i) {
                        if (i > 1)
                            System.out.print(", ");
                        String lValue = lRes.getString(i);
                        System.out.print(lValue);
                    System.out.println("");
                lRes.close();
                lStat.close();
            catch (Exception e) {
                m("doQuery(): "+e.getMessage());
            m("doQuery() end");
        private void run() {
            openDatabase();
            createTable();
            doInsert();
            doQuery();
            closeDatabase();
        public static void main(String args[]) {
            m("main() begin");
            Excel lExcel = new Excel();
            lExcel.run();
            m("main() end");
            System.exit(0);
        public void setTableName(String pValue) {
            gTableName = pValue;
        public String getTableName() {
            return(gTableName);
        public void setSql(String pValue) {
            gSql = pValue;
        public String getSql() {
            return(gSql);
        public Connection getConnection() {
            return(gConnection);
        public String getDataSource() {
            return(gDataSource);
        public void setDataSource(String pValue) {
            gDataSource = pValue;
        public void setDriver(String pValue) {
            gDriver = pValue;
        public void setUrl(String pValue) {
            gUrl = pValue;
        public String getDriver() {
            return (gDriver);
        public String getUrl() {
            return (gUrl);
        private Connection
        gConnection = null
        private String
        gDataSource = null
        ,gTableName = null
        ,gSql = null
        ,gDriver = null
        ,gUrl = null
    }

  • Write to excel using Range function - Excel_write_range.vi

    I am using the write using range Excel function to dump some data into Excel.
    My data is an array consisting of decimal numbers (data type double) but I have to use "Number To Fractional String" before I can dump this array into Excel. And then when I open the output excel file, you have all these warnings for each cell saying, "number displayed as string". Is there a way to instead dump numbers (in format double) into the Excel. That way each cell in the excel output file will already be formatted as a number instead of string.
    Thanks in advance.

    I'm assuming you're actually using ActiveX to write out Excel files. I say this because a lot of people say "Excel files" when they're really talking about spreadsheet-formatted files, generated using the Write to Spreadsheet File VI. That said, the "Value" ("Value 2" in newer versions of Excel) is a variant, so you can wire any datatype to it. Just wire the numeric value directly.

Maybe you are looking for

  • Can I adjust color channels individually?

    In photoshop, if I have a photograph and want to select the color green, I get out my magic wand and select the color green. I can control the amount of selection by adjusting the wand settings. Can i do anything like that in FCPro? If I have video f

  • How can I apply an edit on a corner of a shape to all the corners so it would be symmetrical?

    I made this specific shape in Illustrator CC but I need all the corners and sides to be symmetrical, how can apply the same edit I make for one corner or side to all the corners of the rectangle? or is there any way to make them symmetrical? and is t

  • Streaming HTML

    One of the servlets my team maintains needs to output over 200 fields for several hundred records. Right now it takes awhile for the user to see anything because the entire HTML is created for all of the fields for all of the selected records before

  • Creating an acrobat Website

    I know there are better ways to go about creating a website, however, I am a mere animator and have no web training. I did once create a cd portfolio for a class with links and buttons to other pages. I have set up a series of .gif images that compos

  • Accessibility Features in Dreamweaver

    I am currently designing a site and was wondering how you set the access keys (you press alt and certain number and this takes you to specific page) like the ones found on the following site: Click Here To See Site Any help would be much appreciated.