Libcaenrfid
From CAEN RFID support
The libcaenrfid library implements the client side implementation of the CAENRFID protocol.
The library as been designed for Debian/Linux squeeze system but it should run "as is" on other GNU/Linux systems too. You are encouraged to download, run and test it. Then, please, provide a feedback to us if you like it or you just need some improvements!
Note: the code is distributed with the GNU/LGPL version 2 license, so it is released as is without any warranty (unless you have brought our product equipped with this tool)! However you can ask for a software enhancement to our customers service.
Contents |
Downloading the code
GIT repository
Latest code version is on our GIT repository. You can download the code by using the command:
git clone git://support.caenrfid.it/libcaenrfid
After that you have the full code into the libcaenrfid directory.
Note: a password is needed for cloning.
Then to compile it and getting a Debian package you can use the following commands:
$ cd libcaenrfid $ libtoolize && aclocal && autoheader && automake --foreign --add-missing --copy && autoreconf -i $ fakeroot debian/rules binary
At the end, in the upper directory, you should find your new Debian packages ready to install by using:
# dpkg -i ../libcaenrfid0_version_i386.deb ../libcaenrfid-dev_version_i386.deb
Debian APT repository
If you are just interested in using the library you can use the default Debian packaging tools to download it and run on your Debian based systems (please refer to your specific Linux distribution's manual if you are running a different Linux distribution).
Just add the following two lines to the file /etc/apt/sources.list:
deb http://support.caenrfid.it/ unstable main
then run the commands:
# aptitude update # aptitude install libcaenrfid0
the system should start installing the package.
Getting help
If you are a CAENRFID's customer you can try our customers' support.
Development code installation
In order to build new programs with the CAENRFID library you must install proper package:
$ sudo aptitude install libcaenrfid-dev
New and standard (old) API
Package libcaenrfid-dev holds a new CAENRFID API which is designed to be platform independent, however you can still use standard (and old) CAENRFID API in order to be backward compatibility.
If you wish using standard API you must add the include file caenrfid_old.h into your code (see below), however you can safely build your code only on x86_32 platforms only!
Note: currently both new and standard (old) API are not thread-safe but, in near future, new API will be ported to be thread-safe.
Very simple example (standard API based)
The basic steps to do an inventory is by using four functions: CAENRFID_Init(), CAENRFID_InventoryTag(), CAENRFID_FreeTagsMemory() and CAENRFID_End().
Here the code (complete example files are located here):
/* Start a new connection with the CAENRFIDD server */
ret = CAENRFID_Init(TCP, argv[1], &handle);
if (ret != CAENRFID_StatusOK) {
fprintf(stderr, "cannot init lib (err=%d)\n", ret);
exit(EXIT_FAILURE);
}
/* Do the inventory */
ret = CAENRFID_InventoryTag(&handle, string, &tag, &size);
if (ret != CAENRFID_StatusOK) {
fprintf(stderr, "cannot get data (err=%d)\n", ret);
exit(EXIT_FAILURE);
}
/* Report results */
for (i = 0; i < size; i++) {
str = bin2hex(tag[i].ID, tag[i].Length);
if (!str) {
fprintf(stderr, "cannot allocate memory!\n");
exit(EXIT_FAILURE);
}
printf("%.*s %.*s %.*s %d\n",
tag[i].Length * 2, str,
MAX_LOGICAL_SOURCE_NAME, tag[i].LogicalSource,
MAX_READPOINT_NAME, tag[i].ReadPoint, tag[i].Type);
free(str);
}
/* Free inventory data */
CAENRFID_FreeTagsMemory(&tag);
/* Close the connection */
ret = CAENRFID_End(&handle);
if (ret != CAENRFID_StatusOK)
fprintf(stderr, "improper caenrfidlib closure!\n");
Note that needed includes are:
#define _YES_I_KNOW_USING_OLD_CAENRFID_API_IS_EVIL #include <caenrfid.h> #include <caenrfid_old.h>
The define _YES_I_KNOW_USING_OLD_CAENRFID_API_IS_EVIL can be used in order to suppress compiler warning regarding to standard (old) API.
To compile the code just download all files and the use the command make:
$ make inv_test_old cc inv_test_old.c -lcaenrfid -o inv_test_old
then run the program:
$ ./inv_test_old usage: ./inv_test_old: <server_addr>
If your CAENRFID server is at 10.0.7.161 just use the following command to do an inventory:
$ ./inv_test_old 10.0.7.161 cae000000000000000000002 Source_0 Ant0 3 cae000000000000000000003 Source_0 Ant0 3 cae000000000000000000007 Source_0 Ant0 3 cae00000000000000000000a Source_0 Ant0 3
That's all!
Very simple example (new API based)
The basic steps to do an inventory is by using three functions: caenrfid_open(), caenrfid_inventory() and caenrfid_close().
Here the code (complete example files are located here):
/* Start a new connection with the CAENRFIDD server */
ret = caenrfid_open(CAENRFID_PORT_TCP, argv[1], &handle);
if (ret < 0) {
fprintf(stderr, "cannot init lib (err=%d)\n", ret);
exit(EXIT_FAILURE);
}
/* Do the inventory */
ret = caenrfid_inventory(&handle, string, &tag, &size);
if (ret < 0) {
fprintf(stderr, "cannot get data (err=%d)\n", ret);
exit(EXIT_FAILURE);
}
/* Report results */
for (i = 0; i < size; i++) {
str = bin2hex(tag[i].id, tag[i].len);
if (!str) {
fprintf(stderr, "cannot allocate memory!\n");
exit(EXIT_FAILURE);
}
printf("%.*s %.*s %.*s %d\n",
tag[i].len * 2, str,
CAENRFID_SOURCE_NAME_LEN, tag[i].source,
CAENRFID_READPOINT_NAME_LEN, tag[i].readpoint,
tag[i].type);
free(str);
}
/* Free inventory data */
free(tag);
/* Close the connection */
ret = caenrfid_close(&handle);
if (ret < 0)
fprintf(stderr, "improper caenrfidlib closure!\n");
Note that this time just one include is needed:
#include <caenrfid.h>
To compile the code just download all files and the use the command make:
$ make inv_test cc inv_test.c -lcaenrfid -o inv_test
then run the program:
$ ./inv_test usage: ./inv_test: <server_addr>
If your CAENRFID server is at 10.0.7.161 just use the following command to do an inventory:
$ ./inv_test 10.0.7.161 cae000000000000000000002 Source_0 Ant0 3 cae000000000000000000003 Source_0 Ant0 3 cae000000000000000000007 Source_0 Ant0 3 cae00000000000000000000a Source_0 Ant0 3

