summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-09 14:02:09 +0900
committerdaniel <danieruru@gmail.com>2013-01-09 14:02:09 +0900
commitee9413282d02d936185dc88a34bb817a1a273e6d (patch)
tree159f3b558a9da24c4b0166889d11f2833dc72e99
parentc4ef0522de10e86ff7af432066123e59665913c4 (diff)
A few more clean ups
-rw-r--r--libvxi11client/Makefile14
-rw-r--r--libvxi11client/client.c11
-rw-r--r--libvxi11client/libvxi11client.c25
-rw-r--r--libvxi11client/libvxi11client.h9
4 files changed, 38 insertions, 21 deletions
diff --git a/libvxi11client/Makefile b/libvxi11client/Makefile
index 9b82fac..3b6348a 100644
--- a/libvxi11client/Makefile
+++ b/libvxi11client/Makefile
@@ -1,19 +1,21 @@
+CFLAGS = -Wall
+
all: client
client: libvxi11client.o vxi11_clnt.o vxi11_xdr.o client.o
- $(CC) -o $@ $^
+ $(CC) $(CFLAGS) -o $@ $^
-client.o: client.c
- $(CC) -c $^
+client.o: client.c libvxi11client.h
+ $(CC) $(CFLAGS) -c $<
libvxi11client.o: libvxi11client.c libvxi11client.h
- $(CC) -c $<
+ $(CC) $(CFLAGS) -c $<
vxi11_clnt.o: vxi11_clnt.c
- $(CC) -c $<
+ $(CC) $(CFLAGS) -c $<
vxi11_xdr.o: vxi11_xdr.c
- $(CC) -c $^
+ $(CC) $(CFLAGS) -c $^
.PHONY: clean perl
diff --git a/libvxi11client/client.c b/libvxi11client/client.c
index 747947b..eb224f2 100644
--- a/libvxi11client/client.c
+++ b/libvxi11client/client.c
@@ -1,5 +1,5 @@
-#include "vxi11.h"
#include <stdio.h>
+#include "libvxi11client.h"
#define IDENTIFY "*IDN?"
@@ -25,17 +25,17 @@ int main(int argc, char *argv[]) {
int err = 0;
- if ((err = vxi11_open(argv[1])) > 0) {
+ if ((err = vxi11_open(argv[1], NULL)) > 0) {
// write some bytes
- int byteswritten = vxi11_write(IDENTIFY, sizeof(IDENTIFY));
+ int byteswritten = vxi11_write(IDENTIFY, sizeof(IDENTIFY), false);
if (byteswritten >= 0)
printf("Wrote %d bytes\n", byteswritten);
else
printf("Error writing data\n");
// read some bytes
- int bytesread = vxi11_read();
+ int bytesread = vxi11_read(NULL, 0, false, false, 0);
if (bytesread >= 0)
printf("Read %d bytes\n", bytesread);
else
@@ -89,7 +89,7 @@ int main(int argc, char *argv[]) {
// docmd
if ((err = vxi11_docmd(0x00)) > 0)
- printf("did command, should fail! %d\n");
+ printf("did command, should fail!\n");
else
printf("Error calling docmd; %s\n", geterrorstring(err));
@@ -101,4 +101,5 @@ int main(int argc, char *argv[]) {
printf("Error opening device; %s\n", geterrorstring(err));
exit(1);
}
+ return 0;
}
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c
index 0cb4ab9..ba7d7b4 100644
--- a/libvxi11client/libvxi11client.c
+++ b/libvxi11client/libvxi11client.c
@@ -1,3 +1,4 @@
+#include <stdbool.h>
#include "vxi11.h"
/**
@@ -5,11 +6,26 @@
* Only one server with a single link is supported.
*/
+#define FLAG_TERMCHRSET (1 << 7)
+#define FLAG_END (1 << 3)
+#define FLAG_WAITLOCK 1
+
#define VXI11_DEFAULT_TIMEOUT 1000
static CLIENT* clnt = NULL;
static Device_Link link;
+static Device_Flags vxi11_generateflags(bool waitlock, bool end, bool termchrset) {
+ Device_Flags flags = 0;
+ if (waitlock)
+ flags |= FLAG_WAITLOCK;
+ if (end)
+ flags |= FLAG_END;
+ if (termchrset)
+ flags |= FLAG_TERMCHRSET;
+ return flags;
+}
+
/**
* create an RPC client and open a link to the server at $address.
* $device is apparently used for VXI-11 -> GPIB gateways.. this is untested.
@@ -63,12 +79,12 @@ int vxi11_readstatusbyte() {
* write to the connected device
*/
-int vxi11_write(char* data, unsigned int len) {
+int vxi11_write(char* data, unsigned int len, bool waitlock, bool end) {
if (clnt == NULL)
return 0;
Device_WriteParms params = { .lid = link, .io_timeout = VXI11_DEFAULT_TIMEOUT,
- .lock_timeout = VXI11_DEFAULT_TIMEOUT, .flags = 0x0 };
+ .lock_timeout = VXI11_DEFAULT_TIMEOUT, .flags = vxi11_generateflags(waitlock, end, false) };
params.data.data_len = len;
params.data.data_val = data;
@@ -85,12 +101,13 @@ int vxi11_write(char* data, unsigned int len) {
* read from the connected device
*/
-int vxi11_read() {
+int vxi11_read(char* buffer, unsigned int bufferlen, bool waitlock, bool termchrset, char termchr) {
if (clnt == NULL)
return 0;
Device_ReadParms params = { .lid = link, .requestSize = 256, .io_timeout = VXI11_DEFAULT_TIMEOUT, .lock_timeout =
- VXI11_DEFAULT_TIMEOUT, .flags = 0x0, .termChar = 0x0 };
+ VXI11_DEFAULT_TIMEOUT, .flags = vxi11_generateflags(waitlock, false, termchrset), .termChar =
+ termchrset ? termchr : 0 };
Device_ReadResp* resp = device_read_1(&params, clnt);
if (resp != NULL && resp->error == 0)
diff --git a/libvxi11client/libvxi11client.h b/libvxi11client/libvxi11client.h
index b65e711..6f92744 100644
--- a/libvxi11client/libvxi11client.h
+++ b/libvxi11client/libvxi11client.h
@@ -1,3 +1,4 @@
+#include <stdbool.h>
#include "vxi11.h"
#define ERR_SYNTAXERROR -1
@@ -15,16 +16,12 @@
#define ERR_ABORT -23
#define ERR_CHANNELALREADYESTABLISHED -29
-#define FLAG_TERMCHRSET (1 << 7)
-#define FLAG_END (1 << 3)
-#define FLAG_WAITLOCK 1
-
int vxi11_open(char* address, char* device);
int vxi11_abort();
int vxi11_trigger();
int vxi11_clear();
-int vxi11_write();
-int vxi11_read();
+int vxi11_write(char* data, unsigned int len, bool end);
+int vxi11_read(char* buffer, unsigned int bufferlen, bool waitlock, bool termchrset, char termchr);
int vxi11_lock();
int vxi11_unlock();
int vxi11_local();