Windows DLL

Top  Previous  Next

With the Windows DLL you can communicate with the DAQConnect servers from your own application, or from any application that can link to a Windows DLL.  This section gives a brief description of the DLL's API.  It is assumed that you know how to link to a DLL.

To DAQConnector DLL distribution contains three files:
 
DAQConnector.dll:  the actual DLL that is loaded at runtime and does all the work.

DAQConnector.lib: a lib file for those that want to link to the DLL at compile time.

DAQConnector.h: the header file that lists the prototypes for the API.

There are only a few functions needed to communicate with DAQConnect:

short DAQConn_Initialize(const char *ConnectorID)

 

Call this function once with the Connector ID you are using.  The Connector ID is the one listed in your My Account page.  This function returns 0 if it successful and non-zero if there is an error.  You can get errors using the DAQConn_GetErrors() function described below.

short DAQConn_AddValue(const char *TagName, double val, double time, long maxstorage)

 

This is the primary function for sending data to DAQConnect.  It should only be called after you have successfully initialized the connection.  You should call this function once for each data point you want sent.  TagName is the name of the Tag, val is the value to be sent.  time is the timestamp (in seconds since 1970, UTC time).  maxstorage is the number of historical data points to keep for this tag.  You should always pass the same value for a particular tag otherwise any accumulated historical data is lost.  You can pass -1 to have DAQConnect automatically configure the history based on the account plan.

This function does not actually send the data to DAQConnect.  Instead it queues the data until the next interval.  That interval is determined by your plan.  An internal thread, created when you successfully initialize a connection, handles sending the data. The function will only fail if you try and send data that is spaced too closely together in time.

NOTE: if you lose your Internet connection or otherwise have troubles sending data to DAQConnect, the data will queue up until a connection can be reestablished.  There is a hard limit of 10,000 data points per packet across all tags to ensure you don't run out of RAM.  If more than 10,000 data points queue up while waiting for a connection, the packet will be cleared and all accumulated data will be lost.  New data will then reaccumulate until the connection is established or the process repeats.

short DAQConn_GetErrors(char *Message, long MaxLen)

 

Since the sending of data runs asynchronously, you must call this function to retrieve any errors that have occurred.  Errors are essentially stored in a FIFO buffer internally.  Each call to DAQConn_GetErrors() returns the oldest error and clears it from the FIFO.  If an error is returned, the function will return 1.  You should then repetitively call this function until it returns 0.  Message should be a preallocate buffer.  MaxLen is the length of this buffer.  Make sure and save an extra byte for the \0 character.

short DAQConn_SetStatusCallback(tStatusCallback fCallback, void *pData)

 

For advanced users wanting to provide more detailed debugging information, you can have the DAQConnector DLL perform a callback function for various status events.  fCallback is a function pointer for a function with the tStatusCallback form shown in the header.  pData is a void pointer to whatever data you want.  This data is then also passed to the callback function when it is called.  Note that since your callback will most often be called by a secondary thread, you MUST ensure that your callback function is fast and doesn't call any Windows API calls, including updating screen controls.

Control capability:

If you would like DAQConnect to be able to send messages to your application such as controlling outputs, you will need to create another callback function and then tell the DLL about it using this function:

short DAQConn_SetControlCallback(tControlCallback fCallback, void *pData)

 

fCallback is the callback function which should have this prototype: void foo(const char *key, const char *value, void *pData).  pData is a void pointer to whatever data you want which is passed back to your function.  In your callback function, key is a string containing whatever key was specified using the Set() command in DAQConnect.  Note that the connector information is stripped from the key, so "remote.mykey" becomes just "mykey".  The connector part is used to determine who gets the response.  "value" is also a string, but could contain a numeric value, i.e. "3.412", and is simply the value parameter of the Set() command.  Like the Status Callback, your function will be called by a secondary thread so you must ensure that it is fast and doesn't call any Windows API calls.