int main(int argc, char **argv) { int ch; uint8_t bIReg, bOReg; float temperature; int flag; char type; int ret; hid_device *hid = 0x0; // Composite device with 1 interface. wchar_t serial[64]; wchar_t wstr[MAX_STR]; ret = hid_init(); if (ret < 0) { fprintf(stderr, "hid_init failed with return code %d\n", ret); return -1; } if ((hid = hid_open(MCC_VID, USB_TC_PID, NULL)) > 0) { printf("USB-TC Device is found!\n"); } else { fprintf(stderr, "USB-TC not found.\n"); exit(1); } /* config mask 0x01 means all inputs */ usbDConfigPort_USBTC(hid, DIO_DIR_OUT); usbDOut_USBTC(hid, 0x0); while(1) { printf("\nUSB TC Testing\n"); printf("----------------\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 'i' for information\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"); while((ch = getchar()) == '\0' || ch == '\n'); switch(tolower(ch)) { case 'b': /* test to see if led blinks */ usbBlink_USBTC(hid); break; case 'c': /* calibration */ usbCalibrate_USBTC(hid); break; case 'f': /* Get status of thermocouple burnout detection */ printf("Burnout status = %#x\n", usbGetBurnoutStatus_USBTC(hid, 0xf)); break; case 'g': hid_get_serial_number_string(hid, serial, 64); printf("Serial Number = %ls\n", serial); break; case 'i': // Read the Manufacuter String ret = hid_get_manufacturer_string(hid, wstr, MAX_STR); printf("Manufacturer String: %ls\n", wstr); // Read the Product String ret = hid_get_product_string(hid, wstr, MAX_STR); printf("Product String: %ls\n", wstr); // Read the Serial Number String ret = hid_get_serial_number_string(hid, wstr, MAX_STR); printf("Serial Number String: %ls\n", wstr); break; case 'p': /* read the CJC */ usbTin_USBTC(hid, CJC0, 0, &temperature); printf("CJC 0 = %.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature, celsius2fahr(temperature)); usbTin_USBTC(hid, 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(hid, 0, DIO_DIR_OUT); usbDConfigBit_USBTC(hid, 1, DIO_DIR_OUT); usbDConfigBit_USBTC(hid, 2, DIO_DIR_OUT); usbDConfigBit_USBTC(hid, 3, DIO_DIR_OUT); usbDConfigBit_USBTC(hid, 4, DIO_DIR_IN); usbDConfigBit_USBTC(hid, 5, DIO_DIR_IN); usbDConfigBit_USBTC(hid, 6, DIO_DIR_IN); usbDConfigBit_USBTC(hid, 7, DIO_DIR_IN); do { printf("Enter value [0-f]: "); scanf("%hhx", &bIReg); bIReg &= 0xf; usbDOut_USBTC(hid, bIReg); usbDIn_USBTC(hid, &bOReg); printf("value = %#hhx\n", bOReg); } while (toContinue()); break; case 's': printf("Status = %#x\n", usbGetStatus_USBTC(hid)); break; case 'r': usbReset_USBTC(hid); return 0; break; case 'e': hid_close(hid); hid_exit(); return 0; break; case 't': printf("Connect thermocouple to channel 0\n"); printf(" Select Thermocouple Type [JKSRBETN]: "); scanf("%s", &type); switch(type) { 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(hid, ADC_0, CH_0_TC, bIReg); flag = fcntl(fileno(stdin), F_GETFL); fcntl(0, F_SETFL, flag | O_NONBLOCK); do { usbTin_USBTC(hid, CH0, 0, &temperature); printf("%.2f degress Celsius or %.2f degrees Fahrenheit.\n", temperature, celsius2fahr(temperature)); 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; } } }