mirror of
https://github.com/siemens-mobile-hacks/node-serialport-bindings-cpp.git
synced 2026-11-26 02:47:17 +00:00
added manufacturer and serialNumber in mac for 108#issuecomment-15285753
This commit is contained in:
parent
07ca55b210
commit
0cb7070150
3 changed files with 61 additions and 1 deletions
|
|
@ -231,6 +231,7 @@ void EIO_AfterList(uv_work_t* req) {
|
|||
v8::Local<v8::Object> item = v8::Object::New();
|
||||
item->Set(v8::String::New("comName"), v8::String::New((*it)->comName.c_str()));
|
||||
item->Set(v8::String::New("manufacturer"), v8::String::New((*it)->manufacturer.c_str()));
|
||||
item->Set(v8::String::New("serialNumber"), v8::String::New((*it)->serialNumber.c_str()));
|
||||
item->Set(v8::String::New("pnpId"), v8::String::New((*it)->pnpId.c_str()));
|
||||
item->Set(v8::String::New("locationId"), v8::String::New((*it)->locationId.c_str()));
|
||||
item->Set(v8::String::New("vendorId"), v8::String::New((*it)->vendorId.c_str()));
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ struct ListResultItem {
|
|||
public:
|
||||
std::string comName;
|
||||
std::string manufacturer;
|
||||
std::string serialNumber;
|
||||
std::string pnpId;
|
||||
std::string locationId;
|
||||
std::string vendorId;
|
||||
|
|
|
|||
|
|
@ -77,6 +77,8 @@ typedef struct SerialDevice {
|
|||
char locationId[MAXPATHLEN];
|
||||
char vendorId[MAXPATHLEN];
|
||||
char productId[MAXPATHLEN];
|
||||
char manufacturer[MAXPATHLEN];
|
||||
char serialNumber[MAXPATHLEN];
|
||||
} stSerialDevice;
|
||||
|
||||
typedef struct DeviceListItem {
|
||||
|
|
@ -387,6 +389,8 @@ static stDeviceListItem* GetSerialDevices()
|
|||
memset(serialDevice->locationId, 0, sizeof(serialDevice->locationId));
|
||||
memset(serialDevice->vendorId, 0, sizeof(serialDevice->vendorId));
|
||||
memset(serialDevice->productId, 0, sizeof(serialDevice->productId));
|
||||
serialDevice->manufacturer[0] = '\0';
|
||||
serialDevice->serialNumber[0] = '\0';
|
||||
deviceListItem->next = NULL;
|
||||
deviceListItem->length = &length;
|
||||
|
||||
|
|
@ -408,6 +412,54 @@ static stDeviceListItem* GetSerialDevices()
|
|||
io_registry_entry_t device = GetUsbDevice(bsdPath);
|
||||
|
||||
if (device) {
|
||||
CFStringRef manufacturerAsCFString = (CFStringRef) IORegistryEntrySearchCFProperty(device,
|
||||
kIOServicePlane,
|
||||
CFSTR(kUSBVendorString),
|
||||
kCFAllocatorDefault,
|
||||
kIORegistryIterateRecursively);
|
||||
|
||||
if (manufacturerAsCFString)
|
||||
{
|
||||
Boolean result;
|
||||
char manufacturer[MAXPATHLEN];
|
||||
|
||||
// Convert from a CFString to a C (NUL-terminated)
|
||||
result = CFStringGetCString(manufacturerAsCFString,
|
||||
manufacturer,
|
||||
sizeof(manufacturer),
|
||||
kCFStringEncodingUTF8);
|
||||
|
||||
if (result) {
|
||||
strcpy(serialDevice->manufacturer, manufacturer);
|
||||
}
|
||||
|
||||
CFRelease(manufacturerAsCFString);
|
||||
}
|
||||
|
||||
CFStringRef serialNumberAsCFString = (CFStringRef) IORegistryEntrySearchCFProperty(device,
|
||||
kIOServicePlane,
|
||||
CFSTR(kUSBSerialNumberString),
|
||||
kCFAllocatorDefault,
|
||||
kIORegistryIterateRecursively);
|
||||
|
||||
if (serialNumberAsCFString)
|
||||
{
|
||||
Boolean result;
|
||||
char serialNumber[MAXPATHLEN];
|
||||
|
||||
// Convert from a CFString to a C (NUL-terminated)
|
||||
result = CFStringGetCString(serialNumberAsCFString,
|
||||
serialNumber,
|
||||
sizeof(serialNumber),
|
||||
kCFStringEncodingUTF8);
|
||||
|
||||
if (result) {
|
||||
strcpy(serialDevice->serialNumber, serialNumber);
|
||||
}
|
||||
|
||||
CFRelease(serialNumberAsCFString);
|
||||
}
|
||||
|
||||
IOCFPlugInInterface **plugInInterface = NULL;
|
||||
SInt32 score;
|
||||
HRESULT res;
|
||||
|
|
@ -490,6 +542,12 @@ void EIO_List(uv_work_t* req) {
|
|||
if (device.productId != NULL) {
|
||||
resultItem->productId = device.productId;
|
||||
}
|
||||
if (device.manufacturer != NULL) {
|
||||
resultItem->manufacturer = device.manufacturer;
|
||||
}
|
||||
if (device.serialNumber != NULL) {
|
||||
resultItem->serialNumber = device.serialNumber;
|
||||
}
|
||||
data->results.push_back(resultItem);
|
||||
|
||||
stDeviceListItem* current = next;
|
||||
|
|
@ -513,4 +571,4 @@ void EIO_Flush(uv_work_t* req) {
|
|||
data->result = tcflush(data->fd, TCIFLUSH);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
Loading…
Add table
Reference in a new issue