Modified MS/TP capture utility to emit the list of available COM ports on Windows when no command line argument is given.

This commit is contained in:
skarg
2013-10-07 17:35:44 +00:00
parent db1236d870
commit 35a8ef1ba2
3 changed files with 61 additions and 0 deletions
+35
View File
@@ -125,6 +125,41 @@ void RS485_Set_Interface(
}
}
/****************************************************************************
* DESCRIPTION: Check the serial port to see if port exists
* RETURN: true if port exists
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
bool RS485_Interface_Valid(unsigned port_number)
{
HANDLE h = 0;
DWORD err = 0;
bool status = false;
char ifname[255] = "";
sprintf(ifname, "\\\\.\\COM%u", port_number);
h = CreateFile(
ifname,
GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, 0,
NULL);
if (h == INVALID_HANDLE_VALUE) {
err = GetLastError();
if ((err == ERROR_ACCESS_DENIED) ||
(err == ERROR_GEN_FAILURE) ||
(err == ERROR_SHARING_VIOLATION) ||
(err == ERROR_SEM_TIMEOUT)) {
status = true;
}
} else {
status = true;
CloseHandle(h);
}
return status;
}
const char *RS485_Interface(
void)
{
+3
View File
@@ -68,6 +68,9 @@ extern "C" {
void RS485_Print_Error(
void);
bool RS485_Interface_Valid(unsigned port_number);
#ifdef __cplusplus
}
#endif /* __cplusplus */