LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

DataSocket problem writing data to a web site. Error: Can't write data.

LabWindows/CVI 2013 and 8.1

 

DataSocket problem writing data to a web site.

 

I am getting the following error when trying to write "Dennis" (or any string) with DS_OpenEx with access mode of
DSConst_ReadWriteBufferedAutoUpdate to a web site http://www.google.com/ (or any web site):

 

Error: Can't write data.


Code:


char SHIFT_BUFFER[30];

sprintf(SHIFT_BUFFER, "%s","Dennis"); 
 
char URL_loc[100]  = "http://www.google.com/";


printf("\n%s","A");

DS_OpenEx (URL_loc, DSConst_ReadWriteBufferedAutoUpdate,DSCallback, NULL,DSConst_EventModel, DSConst_InfiniteTimeout,&dsHandle);

 

void CVICALLBACK DSCallback (DSHandle dsHandle, int event,void *pUserData)
{
unsigned type;
int status = FAILURE;
HRESULT hr = S_OK;
int  slength;  

 

 switch (event)
 {
   case DS_EVENT_DATAUPDATED:
   
   printf("\n%s","x");    
      
   hr = DS_GetDataType (dsHandle, &type, NULL, NULL);   
   
   if(type == 103)
   {
   
     printf("\nL = %d",type);
     printf("\n%s",message);
    
   }else
       { 
       printf("\nS = %d",type);
       printf("\n%s%s","connected: ", message); 
       }

            break;
   
        case DS_EVENT_STATUSUPDATED:
   
                       printf("\n%s","y");    
   
                        hr = DS_GetLastMessage (dsHandle, message, 1000);
   
                        hr = DS_GetDataType (dsHandle, &type, NULL, NULL);   
   
   if(type == 103)
   {   
     printf("\nlong= %d",type);
     printf("\n%s",message);
    
   }else
       {     
       DS_SetDataValue (dsHandle, CAVT_CSTRING, SHIFT_BUFFER, 0, 0);
     
       printf("\nstring= %d",type);
       printf("\n%s%s","connected: ", message); 
       }
      
            break;
   
    }
    return; 
}

0 Kudos
Message 1 of 14
(6,001 Views)

If you change the access mode to DSConst_WriteAutoUpdate, are you able to write? 

0 Kudos
Message 2 of 14
(5,977 Views)

Yes, and it's worst.

I don't even get the "Connecting: Parsing URL." message with using DSConst_WriteAutoUpdate.

 

0 Kudos
Message 3 of 14
(5,964 Views)
I meant no , I still can't write
0 Kudos
Message 4 of 14
(5,941 Views)

Are you trying to enter a google search term using data socket? Doing so would be much more complicated than simply writing a word to the website. The link below walks through getting started with DataSocket, and there are also shipped examples you could use. 

 

If you are interested in interacting mroe directly with the Google API, the following link discusses interacting with Google Docs via LabVIEW through a .NET object

 

https://decibel.ni.com/content/docs/DOC-15430#comment-14631

0 Kudos
Message 5 of 14
(5,930 Views)

You do realize that I am using LABWINDOWS/CVI and not Labview. The example you have given me is in Labview.

 

I would like to write a string to any web page (not necessarily www.google.com). The site I want to write to is a private internal web page where I want to store test data. I used google as an example.

 

I can read the web page via datasockets but can't write to it. I have tried all the different Access Modes.

 DSConst_ReadWriteBufferedAutoUpdate is the only one that returns anything.

 

Could the problem be how the web site is setup? Does something about it need to be changed?

 

0 Kudos
Message 6 of 14
(5,921 Views)

Oh I see.  Check out this resource. It discusses writing live data to a website using data socket and would be a good starting point for you 

 

 

0 Kudos
Message 7 of 14
(5,910 Views)

This "www.ni.com/pdf/wp/wp1680.pdf" document you referred me to is from 1998 and it shows functions that don’t exist anymore (DS_OpenConnection).  A better resource is here:

"https://decibel.ni.com/content/docs/DOC-24802"

but this is very complicated.

 

I can do a HTTP GET request using DataSockets.

 

I want to automate a HTTP POST request using DataSockets (DSConst_ReadWriteBufferedAutoUpdate)

 

The manual way is using Google Chrome web browser with POSTMAN add-on. Is there a way to do this in CVI?

0 Kudos
Message 8 of 14
(5,882 Views)

One way you could try to automate HTTP POST in CVI would be to call a library such as cURL. cURL is an open source library for transferring data with URL syntax. Here's the download page and the example page

 

 

0 Kudos
Message 9 of 14
(5,840 Views)

Looks like cURL would be the answer but I can't get it to compile in CVI. It even has a Pascal function in Winsock2.h file that needs to be included in the project to compile, along with some ways to do a struct that the CVI compiler does not like.

 

__control_entrypoint(DllExport) extern int PASCAL FAR __WSAFDIsSet(SOCKET fd, fd_set FAR *);   in Winsock2.h

 

 

0 Kudos
Message 10 of 14
(5,821 Views)