Main Page | Features | Central Services | csv-Files | Types | Transfer | Access | API-C | API-.NET | API-Java | Examples | Downloads
page generated on 04.05.2024 - 04:45
A Simple TINE Client (console)

Introduction

TINE console client applications play an important role in middle-layer servers, automatic servers, scripts, diagnostic checks, etc. Client applications requiring a user interface are best written as GUI applications.

The example below is a simple client code module which obtains the sine curve from the simple console server example, and illustrates both synchronous and asynchronous calls.

Step 1 Global Variables and Routines

First some necessary #includes, #defines, and global variables:

#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include "tine.h"
#define DEVSRVNAME "/TEST/SINEWAVE"
#define NUM 1024
float sdat[NUM], refdat[NUM];

For convenience we've #defined the device server name to refer to the one exported in the simple server example. Likewise we have #defined the total number used in the call, and we have assigned the global arrays sdat[] and refdat[].

The function below (showsine()) will be used as an asynchronous callback. Note that this is just an example. In general, displaying 1024 float values on the console at 1 Hz is a bad idea!

void showsine(int id,int cc)
{
int i;
if (cc)
{
printf("link %d : %s\n>",id,gLastStatusString);
return;
}
for (i=0; i<NUM; i++) printf("%f ",sdat[i] – refdat[i]);
printf("\n>");
}

Step 2 Initialization

Below is an initialization routine PostSystemInit() which is used to obtain a reference sine curve via a synchronous call ExecLink(). This routine also sets up an asynchronous link through AttachLink(), which is to receive a sine curve every 1000 milliseconds. Note that CM_POLL mode is used (and not CM_REFRESH). This is because we know a priori that the data at the server will change with every call (due to the dataMode being either TRAVELLING or NOISE). In both the synchronous and the asynchronous call, there is only an output data set (dout) and no need to send data to the server, hence argument 4 is NULL.
Also note that for a client call, the full device name is formed via the concatenation of DEVSRVNAME and “/#1”. The way the server is written in Example 1, the specific device name is ignored, so appending “/#1” is actually irrelevant here.

void PostSystemInit(void)
{
int cc;
char devname[64], errstr[128];
DTYPE dout;
sprintf(devname,"%s/#1",DEVSRVNAME);
dout.dFormat = CF_FLOAT;
dout.dArrayLength = NUM;
dout.data.fptr = refdat;
/* Get a reference array : synchronous call */
if ((cc=ExecLink(devname, “SINE", &dout, NULL, CA_READ)) != 0)
{
printf("EXECUTE : %s\n>", GetLastLinkError(cc,errstr));
}
/* Establish a data link : asyncrhonous call */
dout.data.fptr = sdat;
sineID = AttachLink(devname, “SINE", &dout, NULL, CA_READ, 1000, showsine, CM_POLL);
if (sineID < 0)
{
printf("ATTACH : %s\n>", GetLastLinkError(-sineID,errstr));
}
}

Step 3 Main

Below is a simple main() routine. Please see the corresponding comments in Example 1 for more details.

int main()
{
int cc;
PostSystemInit(); /* call specific initialization: */
for(;;)
{
SystemCycle(TRUE);
}
return 0;
}

Note that even though the initialization routine is call 'PostSystemInit' there is no call to SystemInit() in a pure console client. The duties of SystemInit() are primarily to initialize a server.

Step 4 Running the Client

You can try compiling and linking the above code. You will need to have a repository containing the TINE kernel library and the TINE include files. Please see the section on 'Recipes' for your platform as to how to generate the library and suggestions as to where to keep the include files and library.

In order to contact the simple server from Example 1, the TINE ENS must be available. So either a cshosts.csv should be available in the TINE_HOME directory (pointing to a functioning equipment name server) or a DNS request to tineens (or tineens1) should resolve to a functioning equipment name server.

DTYPE::data
DUNION data
Definition: tinetype.h:1006
GetLastLinkError
TINE_EXPORT char * GetLastLinkError(short cc, char *errstr)
The error string associated with the input error number.
Definition: client.c:9974
DTYPE::dFormat
short dFormat
Definition: tinetype.h:999
DTYPE
Defines a TINE data object.
Definition: tinetype.h:996
DUNION::fptr
float * fptr
Definition: tinetype.h:987
ExecLink
TINE_EXPORT int ExecLink(const char *devName, const char *devProperty, DTYPE *dout, DTYPE *din, short access)
Executes a synchronous link.
Definition: client.c:9705
DTYPE::dArrayLength
UINT32 dArrayLength
Definition: tinetype.h:998

Impressum   |   Imprint   |   Datenschutzerklaerung   |   Data Privacy Policy   |   Declaration of Accessibility   |   Erklaerung zur Barrierefreiheit
Generated for TINE API by  doxygen 1.5.8