07-23-2014 12:09 PM
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;
}
07-24-2014 05:58 PM
If you change the access mode to DSConst_WriteAutoUpdate, are you able to write?
07-25-2014 06:11 AM
Yes, and it's worst.
I don't even get the "Connecting: Parsing URL." message with using DSConst_WriteAutoUpdate.
07-28-2014 09:49 AM
07-28-2014 04:39 PM
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
07-29-2014 06:34 AM
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?
07-29-2014 04:22 PM
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
07-31-2014 10:09 AM
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?
08-04-2014 01:23 PM
08-05-2014 01:44 PM
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