int main(int argc, char **argv) { int ch; int i; int nchan; __u8 bIReg, bOReg; __u8 in_options, out_options; float temperature; float volts; float temperature_array[8]; float value_1, value_2; int flag; char type[10]; HIDInterface* hid = 0x0; // Composite device with 1 interface. hid_return ret; int interface; char serial[9]; // Debug information. Delete when not needed // hid_set_debug(HID_DEBUG_ALL); // hid_set_debug_stream(stderr); // hid_set_usb_debug(2); ret = hid_init(); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_init failed with return code %d\n", ret); return -1; } if ((interface = PMD_Find_Interface(&hid, 0, USBTC_AI_PID)) < 0) { fprintf(stderr, "USB TC-AI not found.\n"); exit(1); } else { printf("USB TC-AI Device is found! Interface = %d\n", interface); } /* config mask 0x01 means all inputs */ usbDConfigPort_USBTC_AI(hid, DIO_DIR_OUT); usbDOut_USBTC_AI(hid, 0x0); while(1) { printf("\nUSB TC-AI Testing\n"); printf("----------------\n"); printf("Hit 'a' to get alarm status\n"); printf("Hit 'b' to blink LED\n"); printf("Hit 'c' to calibrate\n"); printf("Hit 'd' to test DIO\n"); printf("Hit 'e' to exit\n"); printf("Hit 'f' for burnout status\n"); printf("Hit 'g' to get serial number\n"); printf("Hit 'h' to run the counter\n"); printf("Hit 'r' to reset\n"); printf("Hit 'p' read the CJC\n"); printf("Hit 's' to get status\n"); printf("Hit 't' to measure temperature\n"); printf("Hit 'x' to measure temperature (Thermocouple) multiple channels\n"); printf("Hit 'v' to measure voltage (channels 4-7)\n"); while((ch = getchar()) == '\0' || ch == '\n'); switch(tolower(ch)) { case 'a': for ( i = 0; i < 8; i++ ) { value_1 = 1.0 + i; value_2 = 0.0; in_options = 0x40 | i; out_options = 0x0; // disable alarm usleep(10000); usbConfigAlarm_USBTC_AI(hid, i, in_options, out_options, value_1, value_2); usleep(10000); usbGetAlarmConfig_USBTC_AI(hid, i, &in_options, &out_options, &value_1, &value_2); printf("Alarm %d: input options = %#x output options = %#x value_1 = %f value_2 = %f\n", i, in_options, out_options, value_1, value_2); } printf("\n"); break; case 'b': /* test to see if led blinks */ usbBlink_USBTC_AI(hid); break; case 'c': /* calibration */ usbCalibrate_USBTC_AI(hid, 0); usbCalibrate_USBTC_AI(hid, 1); break; case 'f': /* Get status of thermocouple burnout detection */ printf("Burnout status = %#x\n", usbGetBurnoutStatus_USBTC_AI(hid, 0xf)); break; case 'g': strncpy(serial, PMD_GetSerialNumber(hid), 9); printf("Serial Number = %s\n", serial); break; case 'p': /* read the CJC */ usbAin_USBTC_AI(hid, CJC0, 0, &temperature); printf("CJC 0 = %.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature, celsius2fahr(temperature)); break; case 'd': /* test to see if led blinks */ printf("conect DIO0 - DIO4\n"); printf("conect DIO1 - DIO5\n"); printf("conect DIO2 - DIO6\n"); printf("conect DIO3 - DIO7\n"); usbDConfigBit_USBTC_AI(hid, 0, DIO_DIR_OUT); usbDConfigBit_USBTC_AI(hid, 1, DIO_DIR_OUT); usbDConfigBit_USBTC_AI(hid, 2, DIO_DIR_OUT); usbDConfigBit_USBTC_AI(hid, 3, DIO_DIR_OUT); usbDConfigBit_USBTC_AI(hid, 4, DIO_DIR_IN); usbDConfigBit_USBTC_AI(hid, 5, DIO_DIR_IN); usbDConfigBit_USBTC_AI(hid, 6, DIO_DIR_IN); usbDConfigBit_USBTC_AI(hid, 7, DIO_DIR_IN); do { printf("Enter value [0-f]: "); scanf("%hhx", &bIReg); bIReg &= 0xf; usbDOut_USBTC_AI(hid, bIReg); usbDIn_USBTC_AI(hid, &bOReg); printf("value = %#hhx\n", bOReg); } while (toContinue()); break; case 'h': printf("connect CTR to DIO0.\n"); usbDConfigBit_USBTC_AI(hid, 0, DIO_DIR_OUT); usbInitCounter_USBTC_AI(hid); sleep(1); flag = fcntl(fileno(stdin), F_GETFL); fcntl(0, F_SETFL, flag | O_NONBLOCK); do { usbDOutBit_USBTC_AI(hid, 0, 1); usleep(200000); usbDOutBit_USBTC_AI(hid, 0, 0); printf("Counter = %d\n",usbReadCounter_USBTC_AI(hid)); } while (!isalpha(getchar())); fcntl(fileno(stdin), F_SETFL, flag); break; case 's': printf("Status = %#x\n", usbGetStatus_USBTC_AI(hid)); break; case 'r': usbReset_USBTC_AI(hid); return 0; break; case 'e': ret = hid_close(hid); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_close failed with return code %d\n", ret); return 1; } hid_delete_HIDInterface(&hid); ret = hid_cleanup(); if (ret != HID_RET_SUCCESS) { fprintf(stderr, "hid_cleanup failed with return code %d\n", ret); return 1; } return 0; break; case 't': printf("Select Channel [0-3]: "); scanf("%d", &i); if ( i > 3 ) { printf("Channel must be between 0-3.\n"); i = 0; } printf("Connect thermocouple to channel %d\n", i); printf(" Select Thermocouple Type [JKSRBETN]: "); scanf("%s", type); switch(type[0]) { case 'J': bIReg = TYPE_J; printf("Type J Thermocouple Selected: \n"); break; case 'K': bIReg = TYPE_K; printf("Type K Thermocouple Selected: \n"); break; case 'T': bIReg = TYPE_T; printf("Type T Thermocouple Selected: \n"); break; case 'E': bIReg = TYPE_E; printf("Type E Thermocouple Selected: \n"); break; case 'R': bIReg = TYPE_R; printf("Type R Thermocouple Selected: \n"); break; case 'S': bIReg = TYPE_S; printf("Type S Thermocouple Selected: \n"); break; case 'B': bIReg = TYPE_B; printf("Type B Thermocouple Selected: \n"); break; case 'N': bIReg = TYPE_N; printf("Type N Thermocouple Selected: \n"); break; default: printf("Unknown or unsupported thermocopule type.\n"); break; } usbSetItem_USBTC_AI(hid, i, i%2+CH_0_TC, bIReg); flag = fcntl(fileno(stdin), F_GETFL); fcntl(0, F_SETFL, flag | O_NONBLOCK); do { usbAin_USBTC_AI(hid, i, 0, &temperature); printf("Channel: %d %.2f degress Celsius or %.2f degrees Fahrenheit.\n", i, temperature, celsius2fahr(temperature)); sleep(1); } while (!isalpha(getchar())); fcntl(fileno(stdin), F_SETFL, flag); break; case 'x': printf("Enter number of Channels (1-4): "); scanf("%d", &nchan); if (nchan > 4) nchan = 4; for ( i = 0; i < nchan; i++ ) { printf("Connect thermocouple to channel %d\n", i); printf(" Select Thermocouple Type [JKSRBETN]: "); scanf("%s", type); switch(type[0]) { case 'J': bIReg = TYPE_J; printf("Type J Thermocouple Selected: \n"); break; case 'K': bIReg = TYPE_K; printf("Type K Thermocouple Selected: \n"); break; case 'T': bIReg = TYPE_T; printf("Type T Thermocouple Selected: \n"); break; case 'E': bIReg = TYPE_E; printf("Type E Thermocouple Selected: \n"); break; case 'R': bIReg = TYPE_R; printf("Type R Thermocouple Selected: \n"); break; case 'S': bIReg = TYPE_S; printf("Type S Thermocouple Selected: \n"); break; case 'B': bIReg = TYPE_B; printf("Type B Thermocouple Selected: \n"); break; case 'N': bIReg = TYPE_N; printf("Type N Thermocouple Selected: \n"); break; default: printf("Unknown or unsupported thermocopule type.\n"); break; } usbSetItem_USBTC_AI(hid, i/2, i%2+CH_0_TC, bIReg); } flag = fcntl(fileno(stdin), F_GETFL); fcntl(0, F_SETFL, flag | O_NONBLOCK); do { usbAinScan_USBTC_AI(hid, CH0, nchan-1, 0, temperature_array); for ( i = 0; i < nchan; i++ ) { printf("Channel %d: %.2f degress Celsius or %.2f degrees Fahrenheit.\n", i, temperature_array[i], celsius2fahr(temperature_array[i])); } printf("\n"); sleep(1); } while (!isalpha(getchar())); fcntl(fileno(stdin), F_SETFL, flag); break; case 'v': printf("Select Channel [4-7]: "); scanf("%d", &i); if ( i < 4 || i > 7 ) { printf("Channel must be between 4-7 inclusive. Setting to 4\n"); i = 4; } //usbSetItem_USBTC_AI(hid, i/2, SENSOR_TYPE, VOLTAGE); usbSetItem_USBTC_AI(hid, i/2, i%2+CH_0_VOLT_CONN, DIFFERENTIAL); usbSetItem_USBTC_AI(hid, i/2, i%2+CH_0_GAIN, GAIN_4X); // +/- 10V. flag = fcntl(fileno(stdin), F_GETFL); fcntl(0, F_SETFL, flag | O_NONBLOCK); do { usbAin_USBTC_AI(hid, i, 0, &volts); printf("Channel: %d %.2f Volts.\n", i, volts); sleep(1); } while (!isalpha(getchar())); fcntl(fileno(stdin), F_SETFL, flag); break; default: break; } } }
int main (int argc, char **argv) { int fd[1]; int ch; int numInterfaces = 0; __u8 bIReg, bOReg; float temperature; float temperature_array[8]; int nchan; int flag; char type[80]; int i; char serial[9]; numInterfaces = PMD_Find(MCC_VID, USBTC_PID, fd); if ( numInterfaces <= 0 ) { fprintf(stderr, "USB TC not found.\n"); exit(1); } else printf("USB TC Device is found! Number of interfaces = %d\n", numInterfaces); /* config mask 0x01 means all inputs */ usbDConfigPort_USBTC(fd[0], DIO_DIR_OUT); usbDOut_USBTC(fd[0], 0); while(1) { printf("\nUSB TC Testing\n"); printf("----------------\n"); printf("Hit 'b' to blink\n"); printf("Hit 'c' to calibrate\n"); printf("Hit 'd' to test DIO\n"); printf("Hit 'e' to exit\n"); printf("Hit 'f' for burnout status\n"); printf("Hit 'g' to get serial number\n"); printf("Hit 'r' to reset\n"); printf("Hit 'p' read the CJC\n"); printf("Hit 's' to get status\n"); printf("Hit 't' to measure temperature\n"); printf("Hit 'x' to measure temperature (Thermocouple) multiple channels\n"); while((ch = getchar()) == '\0' || ch == '\n'); switch(ch) { case 'b': /* test to see if led blinks */ usbBlink_USBTC(fd[0]); break; case 'c': /* calibration */ usbCalibrate_USBTC(fd[0]); break; case 'f': /* Get status of thermocouple burnout detection */ printf("Burnout status = %#x\n", usbGetBurnoutStatus_USBTC(fd[0], 0xf)); break; case 'g': strncpy(serial, PMD_GetSerialNumber(fd[0]), 9); printf("Serial Number = %s\n", serial); break; case 'p': /* read the CJC */ usbTin_USBTC(fd[0], CJC0, 0, &temperature); printf("CJC 0 = %.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature, celsius2fahr(temperature)); usbTin_USBTC(fd[0], CJC1, 0, &temperature); printf("CJC 1 = %.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature, celsius2fahr(temperature)); break; case 'd': /* test to see if led blinks */ printf("conect DIO0 - DIO4\n"); printf("conect DIO1 - DIO5\n"); printf("conect DIO2 - DIO6\n"); printf("conect DIO3 - DIO7\n"); usbDConfigBit_USBTC(fd[0], 0, DIO_DIR_OUT); usbDConfigBit_USBTC(fd[0], 1, DIO_DIR_OUT); usbDConfigBit_USBTC(fd[0], 2, DIO_DIR_OUT); usbDConfigBit_USBTC(fd[0], 3, DIO_DIR_OUT); usbDConfigBit_USBTC(fd[0], 4, DIO_DIR_IN); usbDConfigBit_USBTC(fd[0], 5, DIO_DIR_IN); usbDConfigBit_USBTC(fd[0], 6, DIO_DIR_IN); usbDConfigBit_USBTC(fd[0], 7, DIO_DIR_IN); do { printf("Enter value [0-f]: "); scanf("%hhx", &bIReg); bIReg &= 0xf; usbDOut_USBTC(fd[0], bIReg); usbDIn_USBTC(fd[0], &bOReg); printf("value = %#x\n", bOReg); } while (toContinue()); break; case 's': printf("Status = %#x\n", usbGetStatus_USBTC(fd[0])); break; case 'r': usbReset_USBTC(fd[0]); return 0; break; case 'e': close(fd[0]); return 0; break; case 't': printf("Select Channel [0-7]: "); scanf("%d", &i); printf("Connect thermocouple to channel 0\n"); printf(" Select Thermocouple Type [JKSRBETN]: "); scanf("%s", type); switch(type[0]) { case 'J': bIReg = TYPE_J; printf("Type J Thermocouple Selected: \n"); break; case 'K': bIReg = TYPE_K; printf("Type K Thermocouple Selected: \n"); break; case 'T': bIReg = TYPE_T; printf("Type T Thermocouple Selected: \n"); break; case 'E': bIReg = TYPE_E; printf("Type E Thermocouple Selected: \n"); break; case 'R': bIReg = TYPE_R; printf("Type R Thermocouple Selected: \n"); break; case 'S': bIReg = TYPE_S; printf("Type S Thermocouple Selected: \n"); break; case 'B': bIReg = TYPE_B; printf("Type B Thermocouple Selected: \n"); break; case 'N': bIReg = TYPE_N; printf("Type N Thermocouple Selected: \n"); break; default: printf("Unknown or unsupported thermocopule type.\n"); break; } usbSetItem_USBTC(fd[0], i/2, i%2+CH_0_TC, bIReg); flag = fcntl(fileno(stdin), F_GETFL); fcntl(0, F_SETFL, flag | O_NONBLOCK); do { usbTin_USBTC(fd[0], i, 0, &temperature); printf("Channel: %d %.2f degress Celsius or %.2f degrees Fahrenheit.\n", i, temperature, celsius2fahr(temperature)); sleep(1); } while (!isalpha(getchar())); fcntl(fileno(stdin), F_SETFL, flag); break; case 'x': printf("Enter number of Channels (1-8): "); scanf("%d", &nchan); for ( i = 0; i < nchan; i++ ) { printf("Connect thermocouple to channel %d\n", i); printf(" Select Thermocouple Type [JKSRBETN]: "); scanf("%s", type); switch(type[0]) { case 'J': bIReg = TYPE_J; printf("Type J Thermocouple Selected: \n"); break; case 'K': bIReg = TYPE_K; printf("Type K Thermocouple Selected: \n"); break; case 'T': bIReg = TYPE_T; printf("Type T Thermocouple Selected: \n"); break; case 'E': bIReg = TYPE_E; printf("Type E Thermocouple Selected: \n"); break; case 'R': bIReg = TYPE_R; printf("Type R Thermocouple Selected: \n"); break; case 'S': bIReg = TYPE_S; printf("Type S Thermocouple Selected: \n"); break; case 'B': bIReg = TYPE_B; printf("Type B Thermocouple Selected: \n"); break; case 'N': bIReg = TYPE_N; printf("Type N Thermocouple Selected: \n"); break; default: printf("Unknown or unsupported thermocopule type.\n"); break; } usbSetItem_USBTC(fd[0], i/2, i%2+CH_0_TC, bIReg); } flag = fcntl(fileno(stdin), F_GETFL); fcntl(0, F_SETFL, flag | O_NONBLOCK); do { usbTinScan_USBTC(fd[0], CH0, nchan-1, 0, temperature_array); for ( i = 0; i < nchan; i++ ) { printf("Channel %d: %.2f degress Celsius or %.2f degrees Fahrenheit.\n", i, temperature_array[i], celsius2fahr(temperature_array[i])); } printf("\n"); sleep(1); } while (!isalpha(getchar())); fcntl(fileno(stdin), F_SETFL, flag); break; default: break; } } }
int main (int argc, char **argv) { int fd = -1; int ch; int nInterfaces; int temp; int device = 0; // either USBERB24 or USBERB08 __u16 status; char serial[9]; __u8 input; __u8 port; __u8 pin = 0; __u8 bit_value; if ((nInterfaces = PMD_Find(MCC_VID, USBERB24_PID, &fd)) > 0) { printf("USB ERB-24 Device is found! Number of Interfaces = %d\n", nInterfaces); device = USBERB24_PID; } else if ((nInterfaces = PMD_Find(MCC_VID, USBERB08_PID, &fd)) > 0) { printf("USB ERB-08 Device is found! Number of Interfaces = %d\n", nInterfaces); device = USBERB08_PID; } else { fprintf(stderr, "USB ERB 24 & 08 not found.\n"); exit(1); } while(1) { printf("\nUSB ERB24 and ERB08 Testing\n"); printf("----------------\n"); printf("Hit 'b' to blink LED\n"); printf("Hit 'd' to test digital I/O \n"); printf("Hit 'e' to exit\n"); printf("Hit 'g' to get serial number\n"); printf("Hit 's' to get status\n"); printf("Hit 'r' to reset\n"); printf("Hit 't' to test digital bit I/O\n"); printf("Hit 'l' to get temperature\n"); while((ch = getchar()) == '\0' || ch == '\n'); switch(ch) { case 'b': /* test to see if led blinks */ usbBlink_USBERB(fd); break; case 'd': printf("\nTesting Digital I/O \n"); do { if (device == USBERB24_PID) { printf("Enter a port number [0-3]: "); scanf("%hhd", &port); if (port > 3) break; printf("Enter a byte number [0-0xff] : " ); scanf("%x", &temp); usbDOut_USBERB(fd, port, (__u8)temp); } else { printf("Enter a port number [2-3]: "); // only CL and CH on ERB08 scanf("%hhd", &port); printf("port = %d\n", port); if (port != 2 && port != 3) continue; printf("Enter a nibble number [0-0xf] : " ); scanf("%x", &temp); usbDOut_USBERB(fd, port, (__u8)temp); } status = usbGetStatus_USBERB(fd); input = usbDIn_USBERB(fd, port); switch (port) { case 0: /* Port A */ printf(" Port A = %#x\n", input); if (status & 0x1<<0) { printf(" Port A polarity = normal\n"); } else { printf(" Port A polarity = inverted\n"); } if (status & 0x1<<4) { printf(" Port A = pull up\n"); } else { printf(" Port A = pull down\n"); } break; case 1: /* Port B */ printf(" Port B = %#x\n", input); if (status & 0x1<<1) { printf(" Port B polarity = normal\n"); } else { printf(" Port B polarity = inverted\n"); } if (status & 0x1<<5) { printf(" Port B = pull up\n"); } else { printf(" Port B = pull down\n"); } break; case 2: /* Port C Low */ printf(" Port C Low = %#x\n", input); if (status & 0x1<<2) { printf(" Port C Low polarity = normal\n"); } else { printf(" Port C Low polarity = inverted\n"); } if (status & 0x1<<6) { printf(" Port C Low = pull up\n"); } else { printf(" Port C Low = pull down\n"); } break; case 3: /* Port C High */ printf(" Port C High = %#x\n", input); if (status & 0x1<<3) { printf(" Port C High polarity = normal\n"); } else { printf(" Port C High polarity = inverted\n"); } if (status & 0x1<<7) { printf(" Port C High = pull up\n"); } else { printf(" Port C High = pull down\n"); } break; } } while (toContinue()); break; case 'g': strncpy(serial, PMD_GetSerialNumber(fd), 9); printf("Serial Number = %s\n", serial); break; case 't': printf("\nTesting Digital Bit I/O....\n"); do { if (device == USBERB24_PID) { printf("Enter a port number [0-3]: "); scanf("%hhd", &port); if (port > 3) break; } else { printf("Enter a port number [2-3]: "); // only CL and CH on ERB08 scanf("%hhd", &port); printf("port = %d\n", port); if (port != 2 && port != 3) continue; } printf("Select the Pin in port %d [0-7] :", port); scanf("%hhd", &pin); printf("Enter a bit value for output (0 | 1) : "); scanf("%hhd", &bit_value); usbDBitOut_USBERB(fd, port, pin, bit_value); status = usbGetStatus_USBERB(fd); input = usbDBitIn_USBERB(fd, port, pin); printf(" Port %d Pin %d = %#x\n", port, pin, input); switch (port) { case 0: /* Port A */ if (status & 0x1<<0) { printf(" Port A polarity = normal\n"); } else { printf(" Port A polarity = inverted\n"); } if (status & 0x1<<4) { printf(" Port A = pull up\n"); } else { printf(" Port A = pull down\n"); } break; case 1: /* Port B */ if (status & 0x1<<1) { printf(" Port B polarity = normal\n"); } else { printf(" Port B polarity = inverted\n"); } if (status & 0x1<<1) { printf(" Port B = pull up\n"); } else { printf(" Port B = pull down\n"); } break; case 2: /* Port C Low */ if (status & 0x1<<2) { printf(" Port C Low polarity = normal\n"); } else { printf(" Port C Low polarity = inverted\n"); } if (status & 0x1<<6) { printf(" Port C Low = pull up\n"); } else { printf(" Port C Low = pull down\n"); } break; case 3: /* Port C High */ if (status & 0x1<<3) { printf(" Port C High polarity = normal\n"); } else { printf(" Port C High polarity = inverted\n"); } if (status & 0x1<<7) { printf(" Port C High = pull up\n"); } else { printf(" Port C High = pull down\n"); } break; } } while (toContinue()); break; case 's': status = usbGetStatus_USBERB(fd); printf("Status = %#x\n", status); if (device == USBERB24_PID) { if (status & 0x1<<1) { printf(" Port A polarity = normal\n"); } else { printf(" Port A polarity = inverted\n"); } if (status & 0x1<<4) { printf(" Port A = pull up\n"); } else { printf(" Port A = pull down\n"); } /* Port B */ if (status & 0x1<<2) { printf(" Port B polarity = normal\n"); } else { printf(" Port B polarity = inverted\n"); } if (status & 0x1<<4) { printf(" Port B = pull up\n"); } else { printf(" Port B = pull down\n"); } } /* Port C Low */ if (status & 0x1<<3) { printf(" Port C Low polarity = normal\n"); } else { printf(" Port C Low polarity = inverted\n"); } if (status & 0x1<<6) { printf(" Port C Low = pull up\n"); } else { printf(" Port C Low = pull down\n"); } /* Port C High */ if (status & 0x1<<4) { printf(" Port C High polarity = normal\n"); } else { printf(" Port C High polarity = inverted\n"); } if (status & 0x1<<7) { printf(" Port C High = pull up\n"); } else { printf(" Port C High = pull down\n"); } break; case 'l': if (device == USBERB24_PID) { printf("Temperature = %f C\n", usbGetTemp_USBERB(fd)); } else { printf("N/A on ERB08\n"); } break; case 'r': usbReset_USBERB(fd); return 0; break; case 'e': close(fd); return 0; default: break; } } }