Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build/
build-static/
build-shared/
vxi11.h
vxi11_cmd
vxi11_clnt.c
Expand All @@ -8,7 +10,9 @@ TAGS
vxi11_test.cc
vxi11_test.cc
docs
libvxi11.so.0
libvxi11.a
libvxi11.so
libvxi11.so.*
vxi11_send
*.o
*.pyc
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=2.0
VERSION=2.1

include config.mk

Expand Down
32 changes: 23 additions & 9 deletions library/Makefile
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
include ../config.mk

.PHONY : all install clean dist distclean
.PHONY : all static shared install clean dist distclean

UNAME:=$(shell uname -s)

ifneq ($(UNAME),SunOS)
LDFLAGS:=$(LDFLAGS) -Wl,--version-script=linker.version
endif

all : libvxi11.so.${SOVERSION}
OBJ:=vxi11_user.o vxi11_clnt.o vxi11_xdr.o
SDIR:=build-static
DDIR:=build-shared

libvxi11.so.${SOVERSION} : vxi11_user.o vxi11_clnt.o vxi11_xdr.o
all : static shared
static : libvxi11.a
shared : libvxi11.so

libvxi11.so : libvxi11.so.${SOVERSION}
ln -sf libvxi11.so.${SOVERSION} libvxi11.so

libvxi11.so.${SOVERSION} : $(addprefix ${DDIR}/,${OBJ})
$(CC) $(LDFLAGS) -shared -Wl,-soname,libvxi11.so.${SOVERSION} $^ -o $@

vxi11_user.o: vxi11_user.c vxi11.h
$(CC) -fPIC $(CFLAGS) -c $< -o $@
libvxi11.a : $(addprefix ${SDIR}/,${OBJ})
$(AR) rcs $@ $^

vxi11_clnt.o : vxi11_clnt.c
${DDIR}/%.o : %.c vxi11.h | ${DDIR}
$(CC) -fPIC $(CFLAGS) -c $< -o $@

vxi11_xdr.o : vxi11_xdr.c
$(CC) -fPIC $(CFLAGS) -c $< -o $@
${SDIR}/%.o : %.c vxi11.h | ${SDIR}
$(CC) $(CFLAGS) -c $< -o $@

vxi11.h vxi11_clnt.c vxi11_xdr.c : vxi11.x
rpcgen -M vxi11.x

${SDIR} ${DDIR}:
@mkdir $@

TAGS: $(wildcard *.c) $(wildcard *.h) $(wildcard *.c)
etags $^

clean:
rm -f *.o libvxi11.so.${SOVERSION} vxi11.h vxi11_svc.c vxi11_xdr.c vxi11_clnt.c TAGS
rm -rf ${SDIR} ${DDIR}
rm -f *.o libvxi11.so libvxi11.so.${SOVERSION} libvxi11.a vxi11.h vxi11_svc.c vxi11_xdr.c vxi11_clnt.c TAGS

install: all
$(INSTALL) -d $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/
$(INSTALL) libvxi11.a $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/
$(INSTALL) libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/
ln -sf libvxi11.so.${SOVERSION} $(DESTDIR)$(prefix)/lib${LIB_SUFFIX}/libvxi11.so
$(INSTALL) -d $(DESTDIR)$(prefix)/include/
Expand Down
4 changes: 3 additions & 1 deletion library/linker.version
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
* symbols are exported.
*/

VXI11_2.0 {
VXI11_2.1 {
global:
vxi11_close_device;
vxi11_close_device_clients;
vxi11_lib_version;
vxi11_obtain_double_value;
vxi11_obtain_double_value_timeout;
vxi11_obtain_long_value;
vxi11_obtain_long_value_timeout;
vxi11_open_device;
vxi11_open_device_clients;
vxi11_receive;
vxi11_receive_data_block;
vxi11_receive_timeout;
Expand Down
37 changes: 19 additions & 18 deletions library/vxi11_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,7 @@ struct _VXI11_CLINK {
* with the same address or not
*/

struct _vxi11_client_t {
struct _vxi11_client_t *next;
char address[20];
#ifndef WIN32
CLIENT *client_address;
#endif
int link_count;
};

static struct _vxi11_client_t *VXI11_CLIENTS = NULL;
static vxi11_client_t *VXI11_CLIENTS = NULL;

/* Internal function declarations. */
static int _vxi11_open_link(VXI11_CLINK * clink, const char *address,
Expand All @@ -99,13 +90,18 @@ int vxi11_lib_version(int *major, int *minor, int *revision)
/* Use this function from user land to open a device and create a link. Can be
* used multiple times for the same device (the library will keep track).*/
int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device)
{
return vxi11_open_device_clients(clink, address, device, &VXI11_CLIENTS);
}

int vxi11_open_device_clients(VXI11_CLINK **clink, const char *address, char *device, vxi11_client_t **clients)
{
#ifdef WIN32
ViStatus status;
char buf[256];
#else
int ret;
struct _vxi11_client_t *tail, *client = NULL;
vxi11_client_t *tail, *client = NULL;
#endif
char default_device[6] = "inst0";
char *use_device;
Expand Down Expand Up @@ -141,7 +137,7 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device)
#else
/* Have a look to see if we've already initialised an instrument with
* this address */
tail = VXI11_CLIENTS;
tail = *clients;
while (tail) {
if (strcmp(address, tail->address) == 0) {
client = tail;
Expand All @@ -156,7 +152,7 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device)
* is, for this address. Because it's a new client, this
* must be link number 1. Keep track of how many devices we've
* opened so we don't run out of storage space. */
client = (struct _vxi11_client_t *)calloc(1, sizeof(struct _vxi11_client_t));
client = (vxi11_client_t *)calloc(1, sizeof(vxi11_client_t));
if (!client) {
free(*clink);
*clink = NULL;
Expand Down Expand Up @@ -186,8 +182,8 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device)
strncpy(client->address, address, 20);
client->client_address = (*clink)->client;
client->link_count = 1;
client->next = VXI11_CLIENTS;
VXI11_CLIENTS = client;
client->next = *clients;
*clients = client;
} else {
/* Copy the client pointer address. Just establish a new link
* not a new client). Add one to the link count */
Expand All @@ -205,16 +201,21 @@ int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device)
/* Use this function from user land to close a device and/or sever a link. Can
* be used multiple times for the same device (the library will keep track).*/
int vxi11_close_device(VXI11_CLINK * clink, const char *address)
{
return vxi11_close_device_clients(clink, address, &VXI11_CLIENTS);
}

int vxi11_close_device_clients(VXI11_CLINK * clink, const char *address, vxi11_client_t **clients)
{
int ret = 0;
#ifdef WIN32
viClose(clink->session);
viClose(clink->rm);
#else
struct _vxi11_client_t *tail, *last = NULL, *client = NULL;
vxi11_client_t *tail, *last = NULL, *client = NULL;

/* Which instrument are we referring to? */
tail = VXI11_CLIENTS;
tail = *clients;
while (tail) {
if (strncmp(address, tail->address, 20) == 0) {
client = tail;
Expand Down Expand Up @@ -245,7 +246,7 @@ int vxi11_close_device(VXI11_CLINK * clink, const char *address)
if (last) {
last->next = client->next;
} else {
VXI11_CLIENTS = client->next;
*clients = client->next;
}
}
}
Expand Down
47 changes: 46 additions & 1 deletion library/vxi11_user.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ extern "C" {
#endif

#include <stdlib.h>
#include <rpc/rpc.h>


#define LIBVXI11_MAJOR 2
#define LIBVXI11_MINOR 0
#define LIBVXI11_MINOR 1
#define LIBVXI11_REVISION 0
/* LIBVXI11_VERSION_NUMBER looks like 2002001 for e.g. version 2.2.1. */
#define LIBVXI11_VERSION_NUMBER (LIBVXI11_MAJOR*1000000+LIBVXI11_MINOR*1000+LIBVXI11_REVISION)
Expand All @@ -65,6 +66,15 @@ typedef struct _VXI11_CLINK VXI11_CLINK;
/* vxi11_send() return value if a sent command times out ON THE INSTRUMENT. */
#define VXI11_NULL_WRITE_RESP 51

/* client list stucture */
typedef struct _vxi11_client_t {
struct _vxi11_client_t *next;
char address[20];
#ifndef WIN32
CLIENT *client_address;
#endif
int link_count;
} vxi11_client_t;

/* Function: vxi11_library_version
*
Expand Down Expand Up @@ -105,6 +115,27 @@ vx_EXPORT int vxi11_lib_version(int *major, int *minor, int *revision);
vx_EXPORT int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *device);


/* Function: vxi11_open_device_clients
*
* Open a connection to an instrument.
*
* Parameters:
* clink - pointer to a VXI11_CLINK pointer, will be initialised on a
* successful connection.
* address - the IP address or (where supported) USB address for the
* instrument to connect to.
* device - some instruments have multiple interfaces, this allows you to
* specify which to connect to. Set to NULL to use the default of
* "inst0".
* clients - pointer to a vxi11_clients structure
*
* Returns:
* 0 - on success
* 1 - on failure. clink will not be a valid pointer.
*/
vx_EXPORT int vxi11_open_device_clients(VXI11_CLINK **clink, const char *address, char *device, vxi11_client_t **clients);


/* Function: vxi11_close_device
*
* Parameters:
Expand All @@ -118,6 +149,20 @@ vx_EXPORT int vxi11_open_device(VXI11_CLINK **clink, const char *address, char *
vx_EXPORT int vxi11_close_device(VXI11_CLINK *clink, const char *address);


/* Function: vxi11_close_device_clients
*
* Parameters:
* clink - a valid VXI11_CLINK pointer.
* address - the IP address or (where supported) USB address for the
* instrument.
* clients - pointer to a vxi11_clients structure
*
* Returns:
* 0 - on success
*/
vx_EXPORT int vxi11_close_device_clients(VXI11_CLINK *clink, const char *address, vxi11_client_t **clients);


/* Function: vxi11_send
*
* Send data to an instrument.
Expand Down
11 changes: 3 additions & 8 deletions utils/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ include ../config.mk
.PHONY : all install clean

CFLAGS:=${CFLAGS} -I../library
LDFLAGS:=${LDFLAGS} -L../library -lvxi11

all : vxi11_cmd vxi11_send

vxi11_cmd: vxi11_cmd.o ../library/libvxi11.so.${SOVERSION}
vxi11_cmd vxi11_send: %: %.o
$(CC) -o $@ $^ $(LDFLAGS)

vxi11_cmd.o: vxi11_cmd.c ../library/vxi11_user.c ../library/vxi11.h
$(CC) $(CFLAGS) -c $< -o $@

vxi11_send: vxi11_send.o ../library/libvxi11.so.${SOVERSION}
$(CC) -o $@ $^ $(LDFLAGS)

vxi11_send.o: vxi11_send.c ../library/vxi11_user.c ../library/vxi11.h
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

clean:
Expand Down