#include <bluesense.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char **argv) {
char *progname = *argv++; argc--;
if(argc < 3) {
fprintf(stderr, "\n");
fprintf(stderr,
"Please re-run this example with:\n");
fprintf(stderr,
" identifier: identifier of the module\n");
fprintf(stderr,
" port: output pin (1..6)\n");
fprintf(stderr,
" value: out (0..255)\n");
fprintf(stderr, "\n");
fprintf(stderr,
"Usage: %s <identifier> <port> <out 0..255>\n", progname);
fprintf(stderr,
" eg: %s 10 1 200\n", progname);
fprintf(stderr, "\n");
fprintf(stderr,
"To find out what devices are connected try the 'list_devices' example.\n");
fprintf(stderr, "\n");
return(1);
}
identifier_t id = atoi(argv[0]);
uint8_t port = atoi(argv[1]);
uint8_t outvalue = atoi(argv[2]);
bsDeviceInterface_registeredDeviceInterfaces_t registered =
bsDeviceInterface_allocInterfaceTable();
bsDeviceTable_table_t devices = bsDeviceTable_allocDeviceTable();
bsMaster_device_t master = bsMaster_allocMaster(registered,devices,0);
#if 1
bsMaster_addIPAddress(master, "1623", "admin", "admin");
#endif
printf("Detecting device %d...\n", id);
fflush(stdout);
bsDeviceTable_deviceInfo_t dev =
bsMaster_detectDevice(master, id, 5 * 1000 * 1000);
if(!dev) {
fprintf(stderr, "Device %d not found!\n", id);
bsMaster_freeMaster(master);
bsDeviceTable_freeDeviceTable(devices);
bsDeviceInterface_freeInterfaceTable(registered);
return(0);
}
bsDacOutputDevice_specifics_t specDev = bsDacOutputDevice_getDeviceSpecifics(dev);
fflush(stdout);
uint8_t i = 0;
uint32_t autoYieldParam =0;
autoYieldParam = bsMaster_autoYield(master,200000,2000,autoYieldParam);
bsDacOutputDevice_requestSetOutput(specDev,(port-1),outvalue);
autoYieldParam = bsMaster_autoYield(master,200000,2000,autoYieldParam);
printf("Device %d current outputs \n", id);
for (i=0; i<6; i++) {
printf(" port %d has a value of %d\n",
i+1,
bsDacOutputDevice_getCurrentOutput(specDev,i));
}
bsMaster_freeMaster(master);
bsDeviceTable_freeDeviceTable(devices);
bsDeviceInterface_freeInterfaceTable(registered);
return(0);
}