// Create a aio device aio_t *aio_create(mainwnd_t *mainwnd, opt_t *opt, playerc_client_t *client, int index, const char *drivername, int subscribe) { char label[64]; char section[64]; aio_t *aio; aio = malloc(sizeof(aio_t)); aio->proxy = playerc_aio_create(client, index); aio->drivername = strdup(drivername); aio->datatime = 0; snprintf(section, sizeof(section), "aio:%d", index); // Construct the menu snprintf(label, sizeof(label), "aio:%d (%s)", index, aio->drivername); aio->menu = rtk_menu_create_sub(mainwnd->device_menu, label); aio->subscribe_item = rtk_menuitem_create(aio->menu, "Subscribe", 1); // Set the initial menu state rtk_menuitem_check(aio->subscribe_item, subscribe); // Construct figures aio->fig = rtk_fig_create(mainwnd->canvas, mainwnd->robot_fig, 50); return aio; }
// Just read from a aio device. int test_aio(playerc_client_t *client, int index) { int t; void *rdevice; playerc_aio_t *device; printf("device [aio] index [%d]\n", index); device = playerc_aio_create(client, index); TEST("subscribing (read/write)"); if (playerc_aio_subscribe(device, PLAYER_OPEN_MODE) < 0) { FAIL(); return -1; } PASS(); for (t = 0; t < 5; t++) { TEST1("reading data (attempt %d)", t); do rdevice = playerc_client_read(client); while (rdevice == client); if (rdevice == device) { PASS(); printf("aio: [%8.3f] AI0,...,AI7: [%5.3f] [%5.3f] [%5.3f] [%5.3f] [%5.3f] [%5.3f] [%5.3f] [%5.3f]\n", device->info.datatime, device->voltages[0], device->voltages[1],device->voltages[2],device->voltages[3],device->voltages[4],device->voltages[5],device->voltages[6],device->voltages[7]); } else { //printf("error: %s", playerc_error_str()); FAIL(); break; } } TEST("unsubscribing"); if (playerc_aio_unsubscribe(device) != 0) { FAIL(); return -1; } PASS(); playerc_aio_destroy(device); return 0; }