ION GETTING STARTED WITH C
- Ion Technical Information Manual
37
CAENRFIDTag *tag;
int size;
char *str;
int ret;
if (argc < 2) {
fprintf(stderr, "usage: %s: <server_addr>\n", argv[0]);
exit(EXIT_FAILURE);
}
/* 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");
return 0;
}
The define
_YES_I_KNOW_USING_OLD_CAENRFID_API_IS_EVIL
is used to suppress compiler warning generated by
the standard API.
To compile the code, you can use the
make
command:
develop@ion:~# make inv_test_std
cc inv_test_std.c -lcaenrfid -o inv_test_std
When the compile operation is finished you can test the program from your virtual machine:
develop@ion:~# ./inv_test_std <ion reader_address>
cae000000000000000000002 Source_0 Ant0 3
cae000000000000000000003 Source_0 Ant0 3
cae000000000000000000007 Source_0 Ant0 3
cae00000000000000000000a Source_0 Ant0 3
Where
<ion reader address>
is the address of your ion reader (by default is 192.168.0.1).
To run the same program directly on the RFID reader, first transfer it to the Ion:
develop@ion:~# scp ./inv_test_std <ion reader_address>:
and then execute it with the following command:
root@ion:~# ./inv_test_std 127.0.0.1
cae000000000000000000002 Source_0 Ant0 3
cae000000000000000000003 Source_0 Ant0 3
cae000000000000000000007 Source_0 Ant0 3
cae00000000000000000000a Source_0 Ant0 3