diff --git a/sdk/HeliosDac.cpp b/sdk/HeliosDac.cpp index 0d752d9..b7d49d4 100644 --- a/sdk/HeliosDac.cpp +++ b/sdk/HeliosDac.cpp @@ -93,7 +93,7 @@ int HeliosDac::SendFrame(int devNum, uint8_t* bufferAddress, int bufferSize) //returns 1 if successful int HeliosDac::SendControl(int devNum, uint8_t* bufferAddress, int length) { - if ((bufferAddress == NULL) || (!inited) || (devNum >= numOfDevices)) + if ((bufferAddress == NULL) || (!inited) || (devNum >= numOfDevices) || (length > 32) || (length <= 0)) return 0; int actualLength = 0; @@ -107,21 +107,23 @@ int HeliosDac::SendControl(int devNum, uint8_t* bufferAddress, int length) //Attempts to receive a response to a previous control transfer. //Returns length of packet >0 , and populates bufferAddress on success -int HeliosDac::GetControlResponse(int devNum, uint8_t* bufferAddress) +int HeliosDac::GetControlResponse(int devNum, uint8_t* bufferAddress, int length) { - if ((bufferAddress == NULL) || (!inited) || (devNum >= numOfDevices)) + if ((bufferAddress == NULL) || (!inited) || (devNum >= numOfDevices) || (length > 32) || (length <= 0)) return 0; uint8_t data[32]; int actualLength = 0; - int transferResult = libusb_interrupt_transfer(deviceList[devNum], EP_INT_IN, &data[0], 32, &actualLength, 64); - + int transferResult = libusb_interrupt_transfer(deviceList[devNum], EP_INT_IN, &data[0], length, &actualLength, 32); + if (transferResult < 0) + { return transferResult; + } else { - memcpy(bufferAddress, &data[0], actualLength); - return actualLength; + memcpy(bufferAddress, &data[0], length); + return 1; } } diff --git a/sdk/HeliosDac.h b/sdk/HeliosDac.h index 0182491..74a2f29 100644 --- a/sdk/HeliosDac.h +++ b/sdk/HeliosDac.h @@ -27,7 +27,7 @@ class HeliosDac int OpenDevices(); int CloseDevices(); int SendControl(int devNum, uint8_t* bufferAddress, int length); - int GetControlResponse(int devNum, uint8_t* bufferAddress); + int GetControlResponse(int devNum, uint8_t* bufferAddress, int length); int SendFrame(int devNum, uint8_t* bufferAddress, int bufferSize); int numOfDevices = 0; diff --git a/sdk/HeliosDacAPI.cpp b/sdk/HeliosDacAPI.cpp index 7763684..5189b13 100644 --- a/sdk/HeliosDacAPI.cpp +++ b/sdk/HeliosDacAPI.cpp @@ -78,12 +78,12 @@ int GetName(int dacNum, char* name) if (!inited) return -1; - uint8_t ctrlBuffer[32] = { 0x05 }; - int tx = dacController->SendControl(dacNum, &ctrlBuffer[0], 1); + uint8_t ctrlBuffer[32] = { 0x05, 0 }; + int tx = dacController->SendControl(dacNum, &ctrlBuffer[0], 2); if (tx == 1) { - tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0]); - if (tx > 0) + tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0], 32); + if (tx == 1) { if ((ctrlBuffer[0]) == 0x85) //if received control byte is as expected { @@ -112,8 +112,8 @@ int GetStatus(int dacNum) if (tx != 1) return -1; - tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0]); - if (tx > 0) + tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0], 2); + if (tx == 1) { if ((ctrlBuffer[0]) == 0x83) //if received control byte is as expected { @@ -147,7 +147,7 @@ int GetFirmwareVersion(int dacNum) if (tx != 1) return -1; - tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0]); + tx = dacController->GetControlResponse(dacNum, &ctrlBuffer[0], 5); if (tx == 1) { if ((ctrlBuffer[0]) == 0x84) //if received control byte is as expected @@ -159,7 +159,7 @@ int GetFirmwareVersion(int dacNum) } } else - return -1; + return 0; } int CloseDevices() @@ -347,4 +347,4 @@ OLSC_API int __stdcall OLSC_ReadTTL(int device_number, DWORD& data) return OLSC_ERROR_NONE; } -#endif +#endif \ No newline at end of file