From 6def035410e2d132885069c85f1b53602976d6fd Mon Sep 17 00:00:00 2001 From: Martin Peach Date: Sun, 24 Sep 2006 21:18:43 +0000 Subject: Added comport_enum for Windows version svn path=/trunk/externals/iem/comport/; revision=6011 --- comport/comport.c | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'comport') diff --git a/comport/comport.c b/comport/comport.c index 51f9a5c..463e981 100644 --- a/comport/comport.c +++ b/comport/comport.c @@ -11,6 +11,7 @@ MP 20060620 Add DTR and RTS control, add outputs to reflect CTS and DSR states. MP 20060621 Do all the above for Windows too. MP 20060709 All status goes out the status outlet when an info message is received MP 20060824 added clock_delay call in comport_devicename +MP 20060924 added comport_enum to list available ports in Windows */ #include "m_pd.h" @@ -198,6 +199,7 @@ int comport_get_cts(t_comport *x); #ifdef _WIN32 static HANDLE open_serial(unsigned int com_num, t_comport *x); static HANDLE close_serial(t_comport *x); +static void comport_enum(void); #else static int open_serial(unsigned int com_num, t_comport *x); static int close_serial(t_comport *x); @@ -1237,18 +1239,42 @@ static void comport_print(t_comport *x, t_symbol *s, int argc, t_atom *argv) } } +#ifdef _WIN32 +static void comport_enum(void) +{ + HANDLE fd; + char device_name[10]; + unsigned int i; + DWORD dw; + + for(i = 1; i < COMPORT_MAX; i++) + { + sprintf(device_name, "\\\\.\\COM%d", i);/* the recommended way to specify COMs above 9 */ + fd = CreateFile( device_name, + GENERIC_READ | GENERIC_WRITE, + 0, + 0, + OPEN_EXISTING, + FILE_FLAG_OVERLAPPED, + 0); + dw = 0L; + if(fd == INVALID_HANDLE_VALUE) + dw = GetLastError(); + else + CloseHandle(fd); + if (dw == 0)post("\t%d - COM%d (free)", i, i); + else if (dw == ERROR_ACCESS_DENIED)post("\t%d - COM%d (in use)", i, i); + } +} +#endif // WIN32 + static void comport_output_print(t_comport *x) { unsigned int i; post("[comport]: available serial ports:"); #ifdef _WIN32 - post("\t0 - COM1"); - for(i=1; iserial_device_name, 0, NULL, &glob_buffer ) ) -- cgit v1.2.1