/* reads digital port */ void usbDIn_USBTEMP(int fd, __u8* value) { PMD_SendOutputReport(fd, DIN, 0, 0, FS_DELAY); PMD_GetInputReport(fd, DIN, value, 1, FS_DELAY); PMD_GetInputReport(fd, DIN, value, 1, FS_DELAY); return; }
void usbWriteSerial_USBTEMP(int fd, __u8 serial[8]) { // Note: The new serial number will be programmed but not used until hardware reset. PMD_SendOutputReport(fd, WRITE_SERIAL, serial, 8, FS_DELAY); }
void usbTinScan_USBTEMP(HIDInterface* hid, __u8 start_chan, __u8 end_chan, __u8 units, float value[]) { int nchan; struct t_tinScan { __u8 reportID; __u8 start_chan; // the first channel to return 0-7 __u8 end_chan; // the last channel to return 0-7 __u8 units; // 0 - temperature, 1 - raw measurement } tinScan; struct t_tinScan_val { __u8 reportID; __u8 value[32]; // maximum number of measurements } tinScan_val; tinScan.reportID = TIN_SCAN; tinScan.start_chan = start_chan; tinScan.end_chan = end_chan; tinScan.units = units; nchan = (end_chan - start_chan + 1); PMD_SendOutputReport(hid, 0, (__u8*) &tinScan, sizeof(tinScan), FS_DELAY); PMD_GetInputReport(hid, 0, (__u8*) &tinScan_val, nchan*sizeof(float)+1, FS_DELAY); memcpy(value, tinScan_val.value, nchan*sizeof(float)); }
void usbWriteCode_USBTEMP(int fd, __u32 address, __u8 count, __u8 data[]) { /* This command writes to the program memory in the device. This command is not accepted unless the device is in update mode. This command will normally be used when downloading a new hex file, so it supports memory ranges that may be found in the hex file. The microcontroller that is being written to is selected with the "Prepare Download" command. The address ranges are: 0x000000 - 0x0075FF: Microcontroller FLASH program memory 0x200000 - 0x200007: ID memory (serial number is stored here on main micro) 0x300000 - 0x30000F: CONFIG memory (processor configuration data) 0xF00000 - 0xF03FFF: EEPROM memory FLASH program memory: The device must receive data in 64-byte segments that begin on a 64-byte boundary. The data is sent in messages containing 32 bytes. count must always equal 32. Other memory: Any number of bytes up to the maximum (32) may be sent. */ struct t_arg { __u8 address[3]; __u8 count; __u8 data[32]; } arg; memcpy(&arg.address[0], &address, 3); // 24 bit address arg.count = count; memcpy(&arg.data[0], data, count); // 24 bit address PMD_SendOutputReport(fd, WRITE_CODE, (__u8 *) &arg, count+4, FS_DELAY); }
int usbWriteMemory_USBPDISO8(HIDInterface* hid, __u16 address, __u8 count, __u8* data) { // Locations 0x00-0xF are reserved for firmware and my not be written. int i; struct t_mem_write_report { __u8 reportID; __u8 address[2]; __u8 count; __u8 data[count]; } arg; if ( address <= 0xf ) return -1; if ( count > 4 ) count = 4; arg.reportID = MEM_WRITE; arg.address[0] = address & 0xff; // low byte arg.address[1] = (address >> 8) & 0xff; // high byte arg.count = count; for ( i = 0; i < count; i++ ) { arg.data[i] = data[i]; } PMD_SendOutputReport(hid, MEM_WRITE, (__u8 *) &arg, sizeof(arg), FS_DELAY); return 0; }
void usbReadMemory_USBTEMP(HIDInterface* hid, __u16 address, __u8 type, __u8 count, __u8 *memory) { struct t_readMemory { __u8 reportID; __u16 address; __u8 type; // 0 = main microcontroller 1 = isolated microcontroller __u8 count; } readMemory; struct t_readMemoryI { __u8 reportID; __u8 memory[62]; } readMemoryI; if ( count > 62 && type == 0) count = 62; // 62 bytes max for main microcontroller if ( count > 60 && type == 1) count = 60; // 60 bytes max for isolated microcontroller readMemory.reportID = MEM_READ; readMemory.type = type; readMemory.address = address; readMemory.count = count; PMD_SendOutputReport(hid, 0, (__u8 *) &readMemory, sizeof(readMemory), FS_DELAY); PMD_GetInputReport(hid, 0, (__u8 *) &readMemoryI, count+1, FS_DELAY); memcpy(memory, readMemoryI.memory, count); }
int usbWriteMemory_USBTEMP(HIDInterface* hid, __u16 address, __u8 type, __u8 count, __u8* data) { // Locations 0x00-0xFF are available on the main microcontroller int i; struct t_writeMemory { __u8 reportID; __u16 address; // start address for the write (0x00-0xFF) __u8 type; // 0 = main microcontroller 1 = isolated microcontroller __u8 count; // number of bytes to write (59 max) __u8 data[count]; } writeMemory; if ( address > 0xff ) return -1; if ( count > 59 ) count = 59; writeMemory.reportID = MEM_WRITE; writeMemory.address = address; writeMemory.count = count; writeMemory.type = type; for ( i = 0; i < count; i++ ) { writeMemory.data[i] = data[i]; } PMD_SendOutputReport(hid, 0, (__u8 *) &writeMemory, sizeof(writeMemory), FS_DELAY); return 0; }
int usbReadCode_USBTEMP(HIDInterface* hid, __u32 address, __u8 count, __u8 data[]) { struct t_readCode { __u8 reportID; __u8 address[3]; __u8 count; } readCode; struct t_readCodeI { __u8 reportID; __u8 data[62]; } readCodeI; int bRead; // bytes read if ( count > 62 ) count = 62; readCode.reportID = READ_CODE; memcpy(readCode.address, &address, 3); // 24 bit address readCode.count = count; PMD_SendOutputReport(hid, 0, (__u8 *) &readCode, sizeof(readCode), FS_DELAY); bRead = PMD_GetInputReport(hid, 0, (__u8 *) &readCodeI, count+1, FS_DELAY); memcpy(data, readCodeI.data, count); return bRead; }
int usbReadCode_USBDIO96H(HIDInterface* hid, __u32 address, __u8 count, __u8 data[]) { struct t_readCode { __u8 reportID; __u8 address[3]; __u8 count; } readCode; struct t_readCodeI { __u8 reportID; __u8 data[62]; } readCodeI; int bRead; // bytes read if ( count > 62 ) count = 62; readCode.reportID = READ_CODE; memcpy(readCode.address, &address, 3); // 24 bit address readCode.count = count; PMD_SendOutputReport(hid, READ_CODE, (__u8 *) &readCode, sizeof(readCode), FS_DELAY); do { readCode.reportID = 0x0; bRead = usb_interrupt_read(hid->dev_handle, USB_ENDPOINT_IN | 1, (char *) &readCodeI, count+1, FS_DELAY); } while (readCodeI.reportID != READ_CODE && (bRead != count+1)); memcpy(data, readCodeI.data, count); return bRead; }
void usbWriteCode_USBDIO96H(HIDInterface* hid, __u32 address, __u8 count, __u8 data[]) { /* This command writes to the program memory in the device. This command is not accepted unless the device is in update mode. This command will normally be used when downloading a new hex file, so it supports memory ranges that may be found in the hex file. The address ranges are: 0x000000 - 0x007AFF: Microcontroller FLASH program memory 0x200000 - 0x200007: ID memory (serial number is stored here on main micro) 0x300000 - 0x30000F: CONFIG memory (processor configuration data) 0xF00000 - 0xF03FFF: EEPROM memory FLASH program memory: The device must receive data in 64-byte segments that begin on a 64-byte boundary. The data is sent in messages containing 32 bytes. count must always equal 32. Other memory: Any number of bytes up to the maximum (32) may be sent. */ struct t_writecode { __u8 reportID; __u8 address[3]; __u8 count; __u8 data[32]; } writecode; if (count > 32) count = 32; // 32 byte max writecode.reportID = WRITE_CODE; memcpy(writecode.address, &address, 3); // 24 bit address writecode.count = count; memcpy(writecode.data, data, count); PMD_SendOutputReport(hid, WRITE_CODE, (__u8 *) &writecode, count+5, FS_DELAY); }
void usbTin_USBTEMP(HIDInterface* hid, __u8 channel, __u8 units, float *value) { /* This command reads the value from the specified input channel. The return value is a 32-bit floating point value in the units configured fro the channel. CJC readings will always be in Celsius. */ struct t_tin { __u8 reportID; __u8 channel; // 0 - 7 __u8 units; // 0 - temperature, 1 - raw measurement } tin; struct t_tin_val { __u8 reportID; __u8 value[4]; } tin_val; tin.reportID = TIN; tin.channel = channel; tin.units = units; PMD_SendOutputReport(hid, 0, (__u8*) &tin, sizeof(tin), FS_DELAY); PMD_GetInputReport(hid, 0, (__u8*) &tin_val, sizeof(tin_val), FS_DELAY); memcpy(value, tin_val.value, 4); }
/* configures digital port */ void usbDConfigPort_USBTEMP(int fd, __u8 direction) { __u8 cmd[1]; cmd[0] = direction; PMD_SendOutputReport(fd, DCONFIG, cmd, sizeof(cmd), FS_DELAY); }
__u8 usbGetStatus_USBTEMP(int fd) { __u8 status; PMD_SendOutputReport(fd, GET_STATUS, 0, 0, FS_DELAY); PMD_GetInputReport(fd, GET_STATUS, (__u8 *) &status, sizeof(status), FS_DELAY); return status; }
/* writes digital port */ void usbDOut_USBTEMP(int fd, __u8 value) { __u8 cmd[1]; cmd[0] = value; PMD_SendOutputReport(fd, DOUT, cmd, sizeof(cmd), FS_DELAY); }
/* Initialize the counter */ void usbInitCounter_USBDIO96H(HIDInterface* hid) { __u8 cmd[1]; cmd[0] = CINIT; PMD_SendOutputReport(hid, CINIT, cmd, sizeof(cmd), FS_DELAY); }
int usbGetItem_USBTEMP(HIDInterface* hid, __u8 item, __u8 subitem, void* value) { __u8 cmd[5]; // The returning data could be one byte or a 4 byte float. struct t_getItem { __u8 reportID; __u8 item; __u8 subitem; } getItem; if ( item > 3 ) { printf("Error: usbGetItem_USBTEMP Item = %d too large.\n", item); } getItem.reportID = GET_ITEM; getItem.item = item; getItem.subitem = subitem; PMD_SendOutputReport(hid, 0, (__u8 *) &getItem, sizeof(getItem), FS_DELAY); switch (subitem) { case SENSOR_TYPE: case CONNECTION_TYPE: case FILTER_RATE: case EXCITATION: case CH_0_TC: case CH_1_TC: case CH_0_GAIN: case CH_1_GAIN: PMD_GetInputReport(hid, 0, cmd, 2, FS_DELAY); memcpy(value, &cmd[1], 1); // one byte value return 1; break; case VREF: case I_value_0: case I_value_1: case I_value_2: case V_value_0: case V_value_1: case V_value_2: case CH_0_COEF_0: case CH_1_COEF_0: case CH_0_COEF_1: case CH_1_COEF_1: case CH_0_COEF_2: case CH_1_COEF_2: case CH_0_COEF_3: case CH_1_COEF_3: PMD_GetInputReport(hid, 0, cmd, 5, FS_DELAY); memcpy(value, &cmd[1], 4); return 4; break; default: printf("Error usbGetItem_USBTEMP: subitem = %#x unknown\n", subitem); return -1; } return 0; }
/* configures digital bit */ void usbDConfigBit_USBTEMP(int fd, __u8 bit_num, __u8 direction) { __u8 cmd[2]; cmd[0] = bit_num; cmd[1] = direction; PMD_SendOutputReport(fd, DCONFIG_BIT, cmd, sizeof(cmd), FS_DELAY); }
/* writes digital bit */ void usbDOutBit_USBTEMP(int fd, __u8 bit_num, __u8 value) { __u8 cmd[2]; cmd[0] = bit_num; cmd[1] = value; PMD_SendOutputReport(fd, DBIT_OUT, cmd, sizeof(cmd), FS_DELAY); return; }
/* reads digital bit */ void usbDInBit_USBTEMP(int fd, __u8 bit_num, __u8* value) { __u8 cmd[1]; cmd[0] = bit_num; PMD_SendOutputReport(fd, DBIT_IN, cmd, sizeof(cmd), FS_DELAY); PMD_GetInputReport(fd, DBIT_IN, value, sizeof(*value), FS_DELAY); return; }
void usbWriteSerial_USBDIO96H(HIDInterface* hid, __u8 serial[8]) { // Note: The new serial number will be programmed but not used until hardware reset. struct t_writeSerialNumber { __u8 serial[8]; } writeSerialNumber; memcpy(writeSerialNumber.serial, serial, 8); PMD_SendOutputReport(hid, WRITE_SERIAL, (__u8*) &writeSerialNumber, sizeof(writeSerialNumber), FS_DELAY); }
/* configures digital port */ void usbDConfigPort_USBTEMP(HIDInterface* hid, __u8 direction) { struct t_config_port { __u8 reportID; __u8 direction; } config_port; config_port.reportID = DCONFIG; config_port.direction = direction; PMD_SendOutputReport(hid, 0, (__u8*) &config_port, sizeof(config_port), FS_DELAY); }
__u8 usbGetStatus_USBTEMP(HIDInterface* hid) { struct t_statusReport { __u8 reportID; __u8 status; } statusReport; statusReport.reportID = GET_STATUS; PMD_SendOutputReport(hid, 0, &statusReport.reportID, 1, FS_DELAY); PMD_GetInputReport(hid, 0, (__u8*) &statusReport, sizeof(statusReport), FS_DELAY); return statusReport.status; }
/* writes digital port */ void usbDOut_USBTEMP(HIDInterface* hid, __u8 value) { struct t_write_port { __u8 reportID; __u8 value; } write_port; write_port.reportID = DOUT; write_port.value = value; PMD_SendOutputReport(hid, 0, (__u8*) &write_port, sizeof(write_port), FS_DELAY); }
/* reads digital port */ void usbDIn_USBTEMP(HIDInterface* hid, __u8* value) { __u8 reportID = DIN; struct t_read_port { __u8 reportID; __u8 value; } read_port; PMD_SendOutputReport(hid, 0, &reportID, 1, FS_DELAY); usb_interrupt_read(hid->dev_handle, USB_ENDPOINT_IN | 1, (char *) &read_port, sizeof(read_port), FS_DELAY); *value = read_port.value; return; }
/* configures digital bit */ void usbDConfigBit_USBTEMP(HIDInterface* hid, __u8 bit_num, __u8 direction) { struct t_config_bit { __u8 reportID; __u8 bit_num; __u8 direction; } config_bit; config_bit.reportID = DCONFIG_BIT; config_bit.bit_num = bit_num; config_bit.direction = direction; PMD_SendOutputReport(hid, 0, (__u8*) &config_bit, sizeof(config_bit), FS_DELAY); }
void usbTinScan_USBTEMP(int fd, __u8 start_chan, __u8 end_chan, __u8 units, float value[]) { int nchan; __u8 cmd[3]; nchan = (end_chan - start_chan + 1); cmd[0] = start_chan; // the first channel to return 0-7 cmd[1] = end_chan; // the last channel to return 0-7 cmd[2] = units; // 0 - temperature, 1 - raw measurement PMD_SendOutputReport(fd, TIN_SCAN, cmd, sizeof(cmd), FS_DELAY); PMD_GetInputReport(fd, TIN_SCAN, (__u8*) value, nchan*sizeof(float), FS_DELAY); }
void usbGetAll_USBDIO96H(HIDInterface* hid, __u8 data[]) { __u8 reportID = GET_ALL; struct t_get_all { __u8 reportID; __u8 values[19]; } get_all; PMD_SendOutputReport(hid, GET_ALL, &reportID, sizeof(reportID), FS_DELAY); usb_interrupt_read(hid->dev_handle, USB_ENDPOINT_IN | 1, (char *) &get_all, sizeof(get_all), FS_DELAY); memcpy(data, get_all.values, 19); return; }
void usbSetItem_USBTEMP(int fd, __u8 item, __u8 subitem, float fValue) { int size; __u8 cmd[6]; if ( item > 3 ) { printf("Error: usbSetItem_USBTEMP Item = %d too large.\n", item); } switch (subitem) { case SENSOR_TYPE: case CONNECTION_TYPE: case FILTER_RATE: case EXCITATION: case CH_0_TC: case CH_1_TC: case CH_0_GAIN: case CH_1_GAIN: size = 1; cmd[2] = (__u8) fValue; break; case VREF: case I_value_0: case I_value_1: case I_value_2: case V_value_0: case V_value_1: case V_value_2: case CH_0_COEF_0: case CH_1_COEF_0: case CH_0_COEF_1: case CH_1_COEF_1: case CH_0_COEF_2: case CH_1_COEF_2: case CH_0_COEF_3: case CH_1_COEF_3: size = 4; memcpy(&cmd[2], &fValue, size); break; default: printf("Error usbSetItem_USBTEMP: subitem = %#x unknown\n", subitem); return; break; } cmd[0] = item; cmd[1] = subitem; PMD_SendOutputReport(fd, SET_ITEM, cmd, size+2, FS_DELAY); }
/* writes digital bit */ void usbDOutBit_USBTEMP(HIDInterface* hid, __u8 bit_num, __u8 value) { struct t_write_bit { __u8 reportID; __u8 bit_num; __u8 value; } write_bit; write_bit.reportID = DBIT_OUT; write_bit.bit_num = bit_num; write_bit.value = value; PMD_SendOutputReport(hid, 0, (__u8*) &write_bit, sizeof(write_bit), FS_DELAY); return; }
/* reads digital bit */ void usbDInBit_USBTEMP(HIDInterface* hid, __u8 bit_num, __u8* value) { struct t_read_bit { __u8 reportID; __u8 value; } read_bit; read_bit.reportID = DBIT_IN; read_bit.value = bit_num; PMD_SendOutputReport(hid, 0, (__u8*) &read_bit, 2, FS_DELAY); usb_interrupt_read(hid->dev_handle, USB_ENDPOINT_IN | 1, (char *) &read_bit, sizeof(read_bit), FS_DELAY); *value = read_bit.value; return; }