Using USB serial port in Windows programs

10 Jun 2010 . Edited: 10 Jun 2010

Hi all,

So far I've used TeraTerm and HyperTerminal with my mbed project. Now I want to write a Windows program that talks to the mbed system but have no idea how a Windows program can find the mbed 'COM' port. Can anyone point me in the right direction, does the mbed Windows driver have a DLL that can be used for this?

Thanks in advance,

Sophie x

10 Jun 2010

What's your language? Here's a couple of examples for C++/Win32: 1, 2.

10 Jun 2010

Hi Sophie,

If you are into Java you could try:

http://mbed.org/users/andersrundgren/notebook/driving-mbed-from-java

This actually runs on Windows, Linux and Mac without modifications although the port setup procedures are quite different.

I also have used the serialcomm object in VB.NET which I can send to you if you want.

Beware that flow-control is missing in mbed so you must be careful, otherwise you may lose characters.

Anders

06 Jul 2010

Hi all,

Thank you Igor and Anders for the links you provided. I had found something similar already but every little helps :-)

Unfortunately the guides I've seen all start once a COM port has been selected, maybe I've missed something but it seems that you have to know which COM port to use in the first place. Does anyone know how to automatically select the COM port that the mbed is connected to in the first place? When I use TeraTerm on my laptop I select COM4 - TeraTerm helpfully tells you that mbed is connected on COM4. On a friends PC using HyperTerminal there was no COM4, a little trial and error revealed that mbed was conected on COM3! It would be nice to automatically connect to mbed or do I need to have a COM port configuration option for my Windows program?

Thanks in advance,

Sophie x

06 Jul 2010

Here's source code that enumerates available com ports:

http://www.naughter.com/enumser.html

UsingSetupAPI functions from it return an array of "friendly names", so you can check for a string "mbed" in them.

06 Jul 2010

Sophie,

 

Not sure if this is going to be much help, but the following is a bit of code (VB.NET) from a program I've written. It works out the COM port number of a device by looking for a keyword/phrase in the devices name. Fortunately, when installed correctly the mbed appears as 'mbed Serial Port' so I was able to modify the code to simple look for the phrase 'mbed' in my devices.

 

        Dim moReturn As Management.ManagementObjectCollection
        Dim moSearch As Management.ManagementObjectSearcher
        Dim mo As Management.ManagementObject
        Dim intNameLength As Integer
        Dim strNameHold, strComPort As String

        moSearch = New Management.ManagementObjectSearcher("Select * from Win32_PnPEntity")
        moReturn = moSearch.Get

        strComPort = ""

        For Each mo In moReturn
            If CStr(mo.Properties.Item("Name").Value).Contains("mbed") Then
                intNameLength = Len(mo.Properties.Item("Name").Value)
                strNameHold = mo.Properties.Item("Name").Value
                strNameHold = strNameHold.Substring(intNameLength - 7, 7)
                For intBracketSearch = 0 To 6
                    If strNameHold.Substring(intBracketSearch, 1) = "(" Then
                        If strNameHold.Substring(intBracketSearch + 5, 1) = ")" Then
                            strComPort = strNameHold.Substring(intBracketSearch + 4, 1)
                            sptCaliper.PortName = "COM" & strComPort
                        Else
                            strComPort = strNameHold.Substring(intBracketSearch + 4, 2)
                            sptCaliper.PortName = "COM" & strComPort
                        End If
                    End If
                Next
            End If
         Next   
sptCaliper is a VB SerialPort control.

I've tried this out to see if it's recognised correctly and it all seems to work fine with the mbed.

 

Hope this helps.

 

Joe