summaryrefslogtreecommitdiff
path: root/libvxi11client/libvxi11client.c
diff options
context:
space:
mode:
authordaniel <danieruru@gmail.com>2013-01-05 20:56:25 +0900
committerdaniel <danieruru@gmail.com>2013-01-05 20:56:25 +0900
commit18fb047d74d3078223a0a27ffcd31e3467b0d27d (patch)
tree023107523d0f799a92ba31234b508e021630552d /libvxi11client/libvxi11client.c
parente5656b476c9168cfe7852bce4e2ce59876a45d12 (diff)
A bit more fleshing out of the VXI server and client
Diffstat (limited to 'libvxi11client/libvxi11client.c')
-rw-r--r--libvxi11client/libvxi11client.c148
1 files changed, 116 insertions, 32 deletions
diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c
index 41ad046..20fa0fa 100644
--- a/libvxi11client/libvxi11client.c
+++ b/libvxi11client/libvxi11client.c
@@ -5,10 +5,10 @@
static CLIENT* clnt = NULL;
static Device_Link link;
-void vxi11_open(char* address, char* device) {
+int vxi11_open(char* address, char* device) {
clnt = clnt_create(address, DEVICE_CORE, DEVICE_CORE_VERSION, "tcp");
if (clnt == NULL) {
- printf("error creating client\n");
+ return 0;
}
else {
Create_LinkParms link_parms;
@@ -18,34 +18,52 @@ void vxi11_open(char* address, char* device) {
link_parms.device = device;
Create_LinkResp* linkresp = create_link_1(&link_parms, clnt);
- link = linkresp->lid;
+ if (linkresp != NULL && linkresp->error == 0) {
+ link = linkresp->lid;
+ return 1;
+ }
+ else if (linkresp == NULL)
+ return 0;
+ else
+ return -(linkresp->error);
}
}
-void vxi11_readstatusbyte() {
+int vxi11_readstatusbyte() {
if (clnt == NULL)
return;
Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout =
VXI11_DEFAULT_TIMEOUT };
Device_ReadStbResp* resp = device_readstb_1(&params, clnt);
+
+ if (resp != NULL && resp->error == 0)
+ return resp->stb;
+ else if (resp == NULL)
+ return 0;
+ else
+ return -1;
}
-void vxi11_write() {
+int vxi11_write(char* data, unsigned int len) {
if (clnt == NULL) {
return;
}
- char* IDENTIFY = "*IDN?";
-
Device_WriteParms params = { .lid = link, .io_timeout = VXI11_DEFAULT_TIMEOUT,
.lock_timeout = VXI11_DEFAULT_TIMEOUT, .flags = 0x0 };
- params.data.data_len = sizeof(IDENTIFY);
- params.data.data_val = IDENTIFY;
+ params.data.data_len = len;
+ params.data.data_val = data;
Device_WriteResp* resp = device_write_1(&params, clnt);
+ if (resp != NULL && resp->error == 0)
+ return resp->size;
+ else if (resp == NULL)
+ return 0;
+ else
+ return -1;
}
-void vxi11_read() {
+int vxi11_read() {
if (clnt == NULL) {
return;
}
@@ -54,89 +72,155 @@ void vxi11_read() {
VXI11_DEFAULT_TIMEOUT, .flags = 0x0, .termChar = 0x0 };
Device_ReadResp* resp = device_read_1(&params, clnt);
+ if (resp != NULL && resp->error == 0)
+ return resp->data.data_len;
+ else if (resp == NULL)
+ return 0;
+ else
+ return -1;
}
-void vxi11_docmd() {
+int vxi11_docmd(unsigned long cmd) {
if (clnt == NULL)
return;
Device_DocmdParms params = { .lid = link, .flags = 0x0, .io_timeout = VXI11_DEFAULT_TIMEOUT, .lock_timeout =
- VXI11_DEFAULT_TIMEOUT, .cmd = 0, .network_order = 0, .datasize = 0 };
+ VXI11_DEFAULT_TIMEOUT, .cmd = cmd, .network_order = 0, .datasize = 0 };
params.data_in.data_in_len = 0;
params.data_in.data_in_val = NULL;
Device_DocmdResp* resp = device_docmd_1(&params, clnt);
+ if (resp != NULL && resp->error == 0)
+ return 1;
+ else if (resp == NULL)
+ return 0;
+ else
+ return -(resp->error);
}
-void vxi11_trigger() {
+int vxi11_trigger() {
if (clnt == NULL)
return;
Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout =
VXI11_DEFAULT_TIMEOUT };
- device_trigger_1(&params, clnt);
+ Device_Error* error = device_trigger_1(&params, clnt);
+
+ if (error->error == 0)
+ return 1;
+ else
+ return -1;
}
-void vxi11_clear() {
+int vxi11_clear() {
if (clnt == NULL)
return;
Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout =
VXI11_DEFAULT_TIMEOUT };
- device_clear_1(&params, clnt);
+ Device_Error* error = device_clear_1(&params, clnt);
+ if (error != NULL && error->error == 0)
+ return 1;
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
}
-void vxi11_remote() {
+int vxi11_remote() {
if (clnt == NULL)
return;
Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout =
VXI11_DEFAULT_TIMEOUT };
- device_remote_1(&params, clnt);
+ Device_Error* error = device_remote_1(&params, clnt);
+ if (error != NULL && error->error == 0)
+ return 1;
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
}
-void vxi11_local() {
+int vxi11_local() {
if (clnt == NULL)
return;
Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout =
VXI11_DEFAULT_TIMEOUT };
- device_local_1(&params, clnt);
+ Device_Error* error = device_local_1(&params, clnt);
+ if (error != NULL && error->error == 0)
+ return 1;
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
}
-void vxi11_lock() {
+int vxi11_lock() {
if (clnt == NULL)
return;
Device_LockParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT };
- device_lock_1(&params, clnt);
+ Device_Error* error = device_lock_1(&params, clnt);
+ if (error != NULL && error->error == 0)
+ return 1;
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
}
-void vxi11_unlock() {
+int vxi11_unlock() {
if (clnt == NULL)
return;
- device_unlock_1(&link, clnt);
+ Device_Error* error = device_unlock_1(&link, clnt);
+ if (error != NULL && error->error == 0)
+ return 1;
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
}
-void vxi11_create_intr_chan() {
+int vxi11_create_intr_chan() {
if (clnt == NULL)
return;
Device_RemoteFunc remotefunc = { .hostAddr = 0x0, .hostPort = 0x0, .progNum = 0x0, .progVers = 0x0, .progFamily =
DEVICE_TCP };
- create_intr_chan_1(&remotefunc, clnt);
+ Device_Error* error = create_intr_chan_1(&remotefunc, clnt);
+ if (error != NULL && error->error == 0)
+ return 1;
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
}
-void vxi11_destroy_intr_chan() {
+int vxi11_destroy_intr_chan() {
if (clnt == NULL)
return;
- destroy_intr_chan_1(NULL, clnt);
+ Device_Error* error = destroy_intr_chan_1(NULL, clnt);
+ if (error != NULL && error->error == 0)
+ return 1;
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
}
-void vxi11_abort() {
+int vxi11_abort() {
if (clnt == NULL)
return;
- device_abort_1(&link, clnt);
+ Device_Error* error = device_abort_1(&link, clnt);
+ if (error != NULL && error->error == 0)
+ return 1;
+ else if (error == NULL)
+ return 0;
+ else
+ return -(error->error);
}
-void vxi11_close() {
- destroy_link_1(&link, clnt);
+int vxi11_close() {
+ Device_Error* error = destroy_link_1(&link, clnt);
clnt_destroy(clnt);
clnt = NULL;
+ return 1;
}