LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Putting data obtained using visa into table

I have established an ethernet connection with a device and am trying to write out a command to that device and then read the response from the device back into a table in my GUI.  The code I have already is shown below but I have a couple of questions on my errors.

    ViUInt32 writeSize=13;      //Here I write out the command to the gateway - the command is in the buffer
    char buffer[13];
   
    switch (event)
    {
        case EVENT_COMMIT:
       
            buffer[0] = 0x00;
            buffer[1] = 0x1A;
            buffer[2] = 0x00;
            buffer[3] = 0x2B;
            buffer[4] = 0x01;
            buffer[5] = 0x00;
            buffer[6] = 0x0D;
            buffer[7] = 0x6F;
            buffer[8] = 0x00;
            buffer[9] = 0x00;
            buffer[10] = 0x12;
            buffer[11] = 0x88;
            buffer[12] = 0xBE;
           
            viWrite (gateway, buffer, writeSize, VI_NULL);


  ViUInt32 readSize=42;                  //Here I try and read back the data I have obtained from the TCPIP device
    char dataArray[42];

    typedef struct
    {
        int x;
        int y;
    } Point;
            
    switch (event)
    {
        case EVENT_COMMIT:

            viRead (gateway, dataArray, readSize, VI_NULL);
            
            GetTableCellVal (panelHandle, TABPANEL_TABLE_VALUES, Make Point (1,1), dataArray);            //How do I put this into a table correctly?  I want the data I receive back to be put into my char dataArray, and then I want to put this array into row1,col1 of a table i have in my uir.

Any help on how I should do this would be appreciated.  I have tried including Point MakePoint( int x, int y) but I still get errors.  What is the proper syntax for this problem?

Thanks,
neemtt
0 Kudos
Message 1 of 7
(3,997 Views)
I will try splitting your question into two major problems: obtaining the correct values first and displaying them on the table after that.
 
The first question is: how are data transmitted from your instrument? That is: what does your dataArray variable contain? A string with data in plain text (e.g. "123.45  7.63E2 ...") or numeric data packed in some way? After answering this question you will be able to extract your data in the proper way from the received buffer.
 
Once you have obtained your data and have an array of values, to display it on a table you can use a single SetTableCellRangeVals or a series of SetTableCellVal depending on whether all of your data have the same data type or not (I am considering a series of results from the instrument: if a single result is handled at a time you will use only one SetTableCellVal).
 
If you add some detail about your instrument language we can give you some hint about extracting data from the buffer.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 7
(3,992 Views)
the dataArray variable contains numeric data packaged in a specific way so i need to read that data into the buffer and then display the data in the table... if that makes sense...
i have made some changes to the code (shown below) but i am getting these errors - 
NON-FATAL RUN-TIME ERROR:   "pucklocation.c", line 150, col 13, thread id 0x00000E08:   Function viRead: (return value == -1073807339 [0xbfff0015]). Timeout expired before operation completed.
NON-FATAL RUN-TIME ERROR:   "pucklocation.c", line 161, col 13, thread id 0x00000E08:   Library function error (return value == -13 [0xfffffff3]). Invalid control ID
Any ideas on why that is?

//Data being read back from Gateway is 42 bytes long
    ViChar viDataArray[42];
    ViUInt32 viReadSize = 42;
    ViPUInt32 viDataSize = 0;
    int dataSize;
    char dataArray[42];
    int i;
   
   
    switch (event)
    {
        case EVENT_COMMIT:
            //Read in data from gateway... stored in viDataArray
            viRead( gateway, viDataArray, viReadSize, viDataSize);
           
                //Convert VISA type int to regular int
                dataSize = (int) viDataSize;
               
                for(i=0;i<42;i++)
                {
                    dataArray[i] = (int) viDataArray[i];
                }
           
           
            SetTableCellVal (panelHandle, TABPANEL_TABLE_VALUES, MakePoint (1,1), dataArray);
           
            break;
0 Kudos
Message 3 of 7
(3,990 Views)

The first error simply means that no data arrived from the instrument before the stated timeout period expired: you should revise you instrument documentation and the timeout settings for your communication to allow enough time for viRead instruction to receive all expected characters from the instrument.

Additionally, you should pass the last parameter of viRead as a pointer, to receive in it actual number of bytes read, that is
  viRead (gateway, viDataArray, viReadSize, &viDataSize);

The second error is usually related to an incorrect panel handle: as far as I understand, your table is located on a tab control which is on a panel whose handle is stored in panelHandle variable. To correctly address your table you must use the panel handle associated to the tab page (each tab page acts like a panel with its proper handle), which can be obtained with something like
  GetPanelHandleFromTabPage (panelHandle, PANEL_TABCONTROL, index, &tabHandle);

Obtained panel handle must be used when addressing the table:
  SetTableCellVal (tabHandle, TABPANEL_TABLE_VALUES, MakePoint (1,1), dataArray);



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 7
(3,986 Views)
Hi Roberto
Thanks for your help so far.  I was wondering, I am still having some problems with the time out error.  I'm using the viSetAttribute function and disabling the timeout mechanism.  Now, when I run the program, it freezes up on me and I have to force close the solution because CVI locks up and won't respond to the "Stop" command.  I then created a ViUInt32 variable time and initialized that with numbers ranging from 1000-10000 (ms) but it still said it timed out before the operation completed, and this error popped up at the same time interval, no matter what my timeout time was listed at.  Wondering if you can recognize any problems here.

    ViChar viDataArray[256];
    ViUInt32 viReadSize = 256;
    ViPUInt32 viDataSize = 0;
    int dataSize;
    char dataArray[256];
    int i;
    ViUInt32 time=1000;//in milliseconds
   
    switch (event)
    {
        case EVENT_COMMIT:
            //Set time for GUI to read data
            status = viSetAttribute (gateway, VI_ATTR_TMO_VALUE, time); // also used VI_TMO_INFINITE in place of time but instead of timeout error, cvi freezes up
           
            //Read in data from gateway... stored in viDataArray
            status = viRead( gateway, viDataArray, viReadSize, viDataSize );

Thanks,
neemtt
P.S. I'm using CVI version 8.0.1


Message Edited by neemtt on 06-02-2008 12:41 PM
0 Kudos
Message 5 of 7
(3,948 Views)
Hello
I think I have the problem solved concerning why my device was timing out.  Due to a mixture between the fact that my array viDataArray was the wrong size and another small error, I believe it is reading the data from the gateway device properly.  However, now I have reached another problem.  Is it possible to directly place that array into my table (as I do with my SetTableCellVal function), or do I need to add another function to allow this to be done.  I am thinking there might be a problem because I'm getting the data using the VISA viRead function and storing the data in the buffer.  Do I need to write the information from this buffer (viDataArray) into a string possibly (using viScanf), and if so, how would I do this.
If I should be able to transfer data directly from viRead into my table, do you have any ideas on why it won't do that.
Thanks, and sorry for all the questions!
neemtt
0 Kudos
Message 6 of 7
(3,938 Views)

Here we are cominto into the second part of the problem...

AFAIK there is no direct way to read and format data to a table, you will need to read your data from the instrument and then pass them to the table, possibly after some formatting. You said that your data are packed someway, so you will need to understand this packing and unpack them to a numeric format before passing them to the table. In your instrument documentation the packing of data should be described and maybe there are examples of reading them back in some programming language...



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 7
(3,934 Views)