From c4ef0522de10e86ff7af432066123e59665913c4 Mon Sep 17 00:00:00 2001 From: daniel Date: Wed, 9 Jan 2013 13:35:18 +0900 Subject: Some little clean ups for the client library before I turn it into a perl module --- libvxi11client/libvxi11client.c | 115 ++++++++++++++++++++++++++++++++-------- 1 file changed, 94 insertions(+), 21 deletions(-) (limited to 'libvxi11client/libvxi11client.c') diff --git a/libvxi11client/libvxi11client.c b/libvxi11client/libvxi11client.c index 20fa0fa..0cb4ab9 100644 --- a/libvxi11client/libvxi11client.c +++ b/libvxi11client/libvxi11client.c @@ -1,15 +1,25 @@ #include "vxi11.h" +/** + * This is a thin wrapper around the rpcgen generated code to give it a simpler interface. + * Only one server with a single link is supported. + */ + #define VXI11_DEFAULT_TIMEOUT 1000 static CLIENT* clnt = NULL; static Device_Link link; +/** + * 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. + */ + int vxi11_open(char* address, char* device) { clnt = clnt_create(address, DEVICE_CORE, DEVICE_CORE_VERSION, "tcp"); - if (clnt == NULL) { + if (clnt == NULL) return 0; - } + else { Create_LinkParms link_parms; link_parms.clientId = (long) clnt; @@ -29,9 +39,14 @@ int vxi11_open(char* address, char* device) { } } +/** + * read the status byte of the connected server + */ + int vxi11_readstatusbyte() { if (clnt == NULL) - return; + return 0; + Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; Device_ReadStbResp* resp = device_readstb_1(¶ms, clnt); @@ -44,10 +59,13 @@ int vxi11_readstatusbyte() { return -1; } +/** + * write to the connected device + */ + int vxi11_write(char* data, unsigned int len) { - if (clnt == NULL) { - return; - } + if (clnt == NULL) + return 0; Device_WriteParms params = { .lid = link, .io_timeout = VXI11_DEFAULT_TIMEOUT, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .flags = 0x0 }; @@ -63,10 +81,13 @@ int vxi11_write(char* data, unsigned int len) { return -1; } +/** + * read from the connected device + */ + int vxi11_read() { - if (clnt == NULL) { - return; - } + 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 }; @@ -80,9 +101,13 @@ int vxi11_read() { return -1; } +/** + * + */ + int vxi11_docmd(unsigned long cmd) { if (clnt == NULL) - return; + return 0; Device_DocmdParms params = { .lid = link, .flags = 0x0, .io_timeout = VXI11_DEFAULT_TIMEOUT, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .cmd = cmd, .network_order = 0, .datasize = 0 }; @@ -99,9 +124,13 @@ int vxi11_docmd(unsigned long cmd) { return -(resp->error); } +/** + * trigger the connected device + */ + int vxi11_trigger() { if (clnt == NULL) - return; + return 0; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; @@ -110,12 +139,16 @@ int vxi11_trigger() { if (error->error == 0) return 1; else - return -1; + return -(error->error); } +/** + * clear the connected device + */ + int vxi11_clear() { if (clnt == NULL) - return; + return 0; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; Device_Error* error = device_clear_1(¶ms, clnt); @@ -127,9 +160,13 @@ int vxi11_clear() { return -(error->error); } +/** + * remote the connected device + */ + int vxi11_remote() { if (clnt == NULL) - return; + return 0; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; Device_Error* error = device_remote_1(¶ms, clnt); @@ -141,9 +178,13 @@ int vxi11_remote() { return -(error->error); } +/** + * local the connected device + */ + int vxi11_local() { if (clnt == NULL) - return; + return 0; Device_GenericParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT, .io_timeout = VXI11_DEFAULT_TIMEOUT }; Device_Error* error = device_local_1(¶ms, clnt); @@ -155,9 +196,13 @@ int vxi11_local() { return -(error->error); } +/** + * lock the connected device + */ + int vxi11_lock() { if (clnt == NULL) - return; + return 0; Device_LockParms params = { .lid = link, .flags = 0x0, .lock_timeout = VXI11_DEFAULT_TIMEOUT }; Device_Error* error = device_lock_1(¶ms, clnt); if (error != NULL && error->error == 0) @@ -168,9 +213,13 @@ int vxi11_lock() { return -(error->error); } +/** + * unlock the connected device + */ + int vxi11_unlock() { if (clnt == NULL) - return; + return 0; Device_Error* error = device_unlock_1(&link, clnt); if (error != NULL && error->error == 0) return 1; @@ -180,9 +229,12 @@ int vxi11_unlock() { return -(error->error); } +/** + * create an interrupt channel from the connected device + */ int vxi11_create_intr_chan() { if (clnt == NULL) - return; + return 0; Device_RemoteFunc remotefunc = { .hostAddr = 0x0, .hostPort = 0x0, .progNum = 0x0, .progVers = 0x0, .progFamily = DEVICE_TCP }; Device_Error* error = create_intr_chan_1(&remotefunc, clnt); @@ -194,9 +246,13 @@ int vxi11_create_intr_chan() { return -(error->error); } +/** + * destroy an interrupt channel from the connected device + */ + int vxi11_destroy_intr_chan() { if (clnt == NULL) - return; + return 0; Device_Error* error = destroy_intr_chan_1(NULL, clnt); if (error != NULL && error->error == 0) return 1; @@ -206,9 +262,13 @@ int vxi11_destroy_intr_chan() { return -(error->error); } +/** + * send an abort to the connected device + */ + int vxi11_abort() { if (clnt == NULL) - return; + return 0; Device_Error* error = device_abort_1(&link, clnt); if (error != NULL && error->error == 0) return 1; @@ -218,9 +278,22 @@ int vxi11_abort() { return -(error->error); } +/** + * close the current link and free the RPC client + */ + int vxi11_close() { + if (clnt == NULL) + return 0; + Device_Error* error = destroy_link_1(&link, clnt); clnt_destroy(clnt); clnt = NULL; - return 1; + + if (error != NULL && error->error == 0) + return 1; + else if (error == NULL) + return 0; + else + return -(error->error); } -- cgit