LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem using Datasocket Polling with arrays

I am having a problem using Datasocket with CVI.  My goal is to post and retrieve structures from a Datasocket server.  I am successfully able to run the application using event mode.  When I switched to polled mode, I am unable to send the data over.  The following is my transmit command:

hr = DS_SetDataValue (Module->DS_Handle, CAVT_UCHAR|CAVT_ARRAY, &(Module->data), sizeof(MODDATA), 0);

This very easily converts the data object into an array of unsigned characters (basically just the raw data).  In Event mode this works great.  In polling mode, when the type is checked using

             hr = DS_GetDataType (Module->DS_Handle, &type, &x, &y);

the type always returns 103  (CAVT_LONG) .  I checked to see if everything was working correctly by changing my transmit command to send a CAVT_LONG and I was able to send that data over without a problem.  If I change the type to anything else I endup with a mismatched type when trying to read the data, including CAVT_LONG|CAVT_ARRAY.

Am I doing something wrong? 

Jim



0 Kudos
Message 1 of 3
(3,166 Views)

Hi Jim,

Have you taken a look at the DataSocket examples that ship with CVI?  There is a pair called Reader and Writer which demonstrate how to set up a datasocket polling queue (Help>>Find Examples>>Search "datasocket").  I was looking through the code for the Reader and saw that it is receiving a CAVT_DOUBLE.  Are you able to get this code working on your machine? 

Hope this helps!
Megan B.
National Instruments

0 Kudos
Message 2 of 3
(3,149 Views)
Hi Megan,

I was able to get the demonstration program to work, and identified the problem.

Here is a snippet of my code:

            hr = DS_GetDataType (Module->DS_Handle, &type, &x, &y);

            if (type & CAVT_ARRAY)
            {
                hr = DS_GetDataValue (Module->DS_Handle, CAVT_UCHAR|CAVT_ARRAY, &data,
                                    sizeof(MODDATA), &sz, NULL);
                if (SUCCEEDED(hr))
                    memcpy (&(Module->data), &data, sizeof(MODDATA));
            }       
            else
            {
                hr = DS_GetDataValue (Module->DS_Handle, CAVT_UCHAR|CAVT_ARRAY, &data,
                                    sizeof(MODDATA), &sz, NULL);
            }           

Here is the write expression:
 
             hr = DS_SetDataValue (Module->DS_Handle, CAVT_UCHAR|CAVT_ARRAY, &(Module->data), sizeof(MODDATA), 0);

And the structure of MODDATA:
typedef struct MODDATA       
{
    int        Cmd;
    int        CmdReply;

    int        RemoteStatus;    //    remote status
    int        RemoteStatus2;  //
    int        CurrentTray;   
    int        FailureTray;
    int        Sock1Status;
    int        Sock2Status;
    int        Sock3Status;
    int        Sock4Status;
    BOOL    SMEMA_TrayAvail;
    BOOL    SMEMA_Busy;
    BOOL    SMEMA_ReqTray;
    BOOL    SMEMA_AcqTray;
    char    ModuleStatus[50];
} MODDATA;


I had to add the statement after the "else", because after the connection is established the DS_GetDataType is returning a 103 until a DS_GetDataValue is exectued.    (without the else, the DS_GetDataValue never returns the right value)  On subsequent calls the type is returned correctly.  Despite the fact that the type is returning a 103, the DS_GetDataValue using a CAVT_UCHAR|CAVT_ARRAY works without throwing an error.  The sample polling code does not check the type, though the sample event code recommends that the type be checked.  I haven't checked to see what data is returned on the first call to see if it's valid or not.

This is pretty useful since it allows the sending of a complete structure over DataSocket without having to break it up or do anything fancy.

Jim



0 Kudos
Message 3 of 3
(3,137 Views)