BBC BASIC for Windows
« Identifying non-existent COM ports? »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:15pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Identifying non-existent COM ports?  (Read 1375 times)
g3nrw
Junior Member
ImageImage


member is offline

Avatar




PM


Posts: 74
xx Re: Identifying non-existent COM ports?
« Reply #4 on: Oct 4th, 2014, 12:55pm »

Using GetLastError:

Code:
      FOR p% = 1 TO 255
        port% = OPENIN("COM" + STR$(p%)  + ": 115200,N,8,1")
        SYS "GetLastError" TO winerr%
  
        CASE winerr% OF
          WHEN 0:
            PRINT "COM" + STR$(p%) + "  Free"
            CLOSE# port%
      
          WHEN 1:
            PRINT "COM" + STR$(p%) + "  In Use"
      
        ENDCASE
  
      NEXT
 

This works OK, but only for port name values "COMn" (this includes VSPE ports).

If com0com is in use, you have no idea how the port name values are defined -- the user can specify any value -- so the above code won't work.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Re WMI, http://bb4w.wikispaces.com/Enumerating+serial+ports , I tried that. Strangely, it only enumerates the com0com ports (but doesn't do this properly), and ignores COM ports altogether! (This is under Windows 7/32).


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

So the only accurate source of port name values that I can find is in the registry. Problem now is discovering the names, so I can then retrieve the values.

--
Ian

User IP Logged

rtr2
Guest
xx Re: Identifying non-existent COM ports?
« Reply #5 on: Oct 4th, 2014, 2:06pm »

on Oct 4th, 2014, 12:55pm, g3nrw wrote:
Strangely, it only enumerates the com0com ports (but doesn't do this properly), and ignores COM ports altogether! (This is under Windows 7/32).

To reiterate, that is the official method for enumerating serial ports in Windows. If it is not returning the port(s) in which you are interested your system is broken and you cannot expect anything to work correctly.

Quote:
So the only accurate source of port name values that I can find is in the registry.

It isn't legitimate to read the registry directly - it is a hack which is not guaranteed to work on different versions of Windows. You should fix the cause of the WMI problem, not attempt to work around it.

My guess would be that COM0COM is broken; I would suggest that you try using Virtual Null Modem instead. That's the utility I use and I have not noticed it causing any unexpected behaviour:

http://www.virtual-null-modem.com/

Richard.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls