QueryBus

QueryBus: QueryBus sends request to get complete information from the virtual serial bus installed by VSPD.

BOOL QueryBus(
  void* inBuffer, // pointer to buffer
  long sizeInBuffer, // size of buffer
  void* OutBuffer, // pointer to buffer
  long sizeOutBuffer, // size of buffer
);

Parameters:

  • InBuffer

A pointer to VSBUS_QUERY or VSBUS_QUERY_EX structures. If you want to get information about all current virtual serial ports then use VSBUS_QUERY structure and if you want to get extended information about single virtual serial pair then use VSBUS_QUERY_EX structure.

  • OutBuffer

A pointer to either PORT_INFORMATION or PORT_INFORMATION_EX structures list. If you have used VSBUS_QUERY than you should get PORT_INFORMATION list and if you used VSBUS_QUERY_EX then you should get PORT_INFORMATION_EX.

Return values:

CreatePair returns TRUE if virtual serial pair was created successfully and FALSE otherwise

Code example:

Getting information about all virtual serial ports

void		*Buffer;
long sizeBuffer;
Query.Size = sizeof (VSBUS_QUERY); Query.QueryType = QUERYTYPE_PORTS; Buffer = new char[sizeBuffer]; while (!QueryBus(&Query, Query.Size, Buffer, sizeBuffer)) { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
delete[] Buffer;
return;
}
else
{
delete[] Buffer;
sizeBuffer = sizeBuffer * 2;
Buffer = new char[sizeBuffer];
}
}
PPORT_INFORMATION portInfo = (PPORT_INFORMATION)Buffer; while (portInfo->NextOffset != 0) { if (portInfo->NameOffset != 0) { CString portName((PWCHAR)((ULONG)portInfo + portInfo->NameOffset)); printf ("%s\n", portName); } portInfo = (PPORT_INFORMATION)((ULONG)portInfo + portInfo->NextOffset); } delete[] Buffer;

Getting information about a single port

void		*Buffer;
int iSize = 1024; VSBUS_QUERY_EX Query; PPORT_INFORMATION_EX portInfo; Query.Size = sizeof (VSBUS_QUERY_EX); Query.QueryType = QUERYINFO_PAIR; mbstowcs (Query.PortName, "COM5", MAX_PORTNAME_LEN); Buffer = new char [iSize]; while (!QueryBus(&Query, Query.Size, Buffer, iSize)) { { if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { delete[] Buffer;
return;
} else { iSize *= 2; delete[] Buffer; Buffer = new char [iSize]; } } while (portInfo->NextOffset != 0) { if (portInfo->NameOffset != 0) { CString portName((PWCHAR)((ULONG)portInfo + portInfo->NameOffset)); printf ("%s send - %d recv - %d\n", portName, portInfo->TxCount, portInfo->RxCount); } portInfo = (PPORT_INFORMATION_EX)((ULONG)portInfo + portInfo->NextOffset); } portInfo = (PPORT_INFORMATION_EX)Buffer; delete[] Buffer;