#include <cmlogClient.h>
#include <unistd.h>
#ifndef __vxworks
main (int argc, char** argv)
#else
clientTest (char* name)
#endif
{
int status;
#ifndef __vxworks
cmlogClient *client = new cmlogClient (argv[0]);
#else
cmlogClient *client = cmlogClient::logClient ();
#endif
if (client->connect () == CMLOG_SUCCESS) {
cdevData::insertTag (322, "highVIn");
cdevData::insertTag (323, "highVOut");
client->setThrottle ("highVIn", 100, 25, 1.0);
cdevData data;
for (int i = 0; i < 100; i++) {
sprintf (temp, "Test program error happend %d\n", i);
status = client->postError (32, 12, CMLOG_ERROR,
"EPICS",
highVIn = %d highVOut = %d text = %s",
i, i*100, temp);
}
client->disconnect ();
}
else
printf ("Cannot connect to daemon\n");
}
The following is the sample makefile for the above C++ code (clientTest.cc) on a Unix machine (Let us assume this machine is a hpux machine).
CXX = CC
CXXFLAGS = -I$(CMLOG)/include -D_CMLOG_BUILD_CLIENT
OBJS = clientTest.o
LIBS = -L$(CMLOG)/lib/hpux -lcmlog
all: clientTest
clientTest: $(OBJS)
rm -f $@
$(CXX) -o $@ $(LIBS)
.cc.o:
rm -f $@
$(CXX) $(CXXFLAGS) -c $< -o $@
clean:
rm -f *.o clientTest core *~
The following is the sample makefile for the above C++ code (clientTest.cc) on a mv162 machine (Let us assume this board is running vxWorks 5.2)
CXX = c++68k
CXXFLAGS = -I$(CMLOG)/include -D_CMLOG_BUILD_CLIENT -O \
-I$(VX_VW_BASE)/h -fstrength-reduce -fforce-mem \
-finline-functions -fno-builtin -fno-for-scope -nostdinc \
-DCPU=MC68040 -DCPU_FAMILY=MC680X0 -ansi -pipe \
-Dvxworks -msoft-float
OBJS = clientTest.o
MAKELIB = ld68k -r -o
all: clientTest
clientTest: $(OBJS)
rm -f $@
$(MAKELIB) -o $@ $(OBJS)
.cc.o:
rm -f $@
$(CXX) $(CXXFLAGS) -c $< -o $@
clean:
rm -f *.o clientTest core *~
The following is a simple c code example using the CMLOG client APIs to log messages.
#include <stdio.h>
#include <string.h>
#include <cmlog.h>
#ifndef __vxworks
main (int argc, char** argv)
#else
client_test (char* name)
#endif
{
int status;
cmlog_client_t cl;
int i = 0;
char message[256];
#ifndef __vxworks
cl = cmlog_open (argv[0]);
#else
cl = cmlog_open (name);
#endif
if (cl == 0) {
fprintf (stderr, "cannot open cmlog client\n");
exit (1);
}
for (i = 0; i < 100; i++) {
sprintf (message, "Test error c interface at %d\n", i);
status = cmlog_logmsg (cl, 32, 12, CMLOG_ERROR,
"EPICS", "value = %d status = %d text = %s",
i*10, 0, message);
#ifndef __vxworks
sleep (1);
#else
taskDelay (sysClkRateGet ());
#endif
}
cmlog_close (cl);
}
Once again we show a example Makefile for the above c test code (client_test.c).
CXX = CC
CC = cc
CFLAGS = -I$(CMLOG)/include -D_CMLOG_BUILD_CLIENT
OBJS = client_test.o
LIBS = -L$(CMLOG)/lib/hpux -lcmlog
all: client_test
client_test: $(OBJS)
rm -f $@
$(CXX) -o $@ $(OBJS) $(LIBS)
.c.o:
rm -f $@
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f *~ *.o core client_test
The following is the sample makefile for the above c code (client_test.c) on a mv167 machine (Let us assume this board is running vxWorks 5.3)
CC = cc68k
CFLAGS = -I$(CMLOG)/include -D_CMLOG_BUILD_CLIENT -O \
-I$(WIND_BASE)/target/h -fstrength-reduce -fforce-mem \
-finline-functions -fno-builtin -nostdinc \
-DCPU=MC68040 -DCPU_FAMILY=MC680X0 -ansi -pipe \
-Dvxworks
OBJS = client_test.o
MAKELIB = ld68k -r -o
all: client_test
client_test: $(OBJS)
rm -f $@
$(MAKELIB) -o $@ $(OBJS)
.c.o:
rm -f $@
$(CXX) $(CFLAGS) -c $< -o $@
clean:
rm -f *.o client_test core *~