1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

fixed reading serial number from USB device on mac platform

This commit is contained in:
Voha 2012-12-24 01:57:48 +02:00 committed by a*morale
parent 5b8b38ad7b
commit 427bbd0a80

View File

@ -274,11 +274,21 @@ QString pjrc_rawhid::getserial(int num) {
CFTypeRef serialnum = IOHIDDeviceGetProperty(dev, CFSTR(kIOHIDSerialNumberKey));
if(serialnum && CFGetTypeID(serialnum) == CFStringGetTypeID())
{
//Note: I'm not sure it will always succeed if encoded as MacRoman but that
//is a superset of UTF8 so I think this is fine
CFStringRef str = (CFStringRef)serialnum;
const char * buf = CFStringGetCStringPtr(str, kCFStringEncodingMacRoman);
return QString(buf);
//Note: I'm not sure it will always succeed if encoded as MacRoman but that
//is a superset of UTF8 so I think this is fine
CFStringRef str = (CFStringRef)serialnum;
// const char * buf = CFStringGetCStringPtr(str, kCFStringEncodingMacRoman);
//return QString(buf);
int length = CFStringGetLength(str);
if( length == 0 )
return "";
char* ptr = (char*)malloc( length+1 );
Boolean ret = CFStringGetCString( str, ptr, length+1, kCFStringEncodingMacRoman );
QString strResult;
if( ret == true )
strResult = ptr;
free( ptr );
return strResult;
}
return QString("Error");