OpenNETcf Serial port question

E

EMW

Hi,

For my windows application I'm using OpenNetCF's serialport stuff but I'm
having a small problem.
In my program I want to list a range of available ports to select.
This works fine for the first 16 ports, but not for the higher ports.

I do this as folowed:

For ab = 1 To 32
commport = "COM" + ab.ToString
SerialPort = New Port(commport)
With SerialPort
.PortName = commport + ":"
.RThreshold = cpi.comRThreshold
.Settings.BaudRate = cpi.comBaud
.Settings.ByteSize = cpi.comByte
.Settings.Parity = cpi.comParity
.Settings.StopBits = cpi.comStopbits
End With
Try
ac = SerialPort.Open
err = ""
SerialPort.Close()
Catch ex As Exception
err = ex.Message.ToString
MsgBox(err + vbCrLf + "com" + ab.ToString)
SerialPort = Nothing
End Try
If ac = True And Not SerialPort Is Nothing Then
Me.cbCom.Items.Add(Mid(SerialPort.PortName, 1,
Len(SerialPort.PortName) - 1))
End If
SerialPort = Nothing
Next ab

If have a bluetooth usb stick connected to virtual port 24 but this port
cannot be opened.
Is there a limitation for the amount of ports that can be opened like this?

please help.
Eric
 
E

EMW

it actualy doesn't work for any other port except com4.
I must be doing something wrong...but what....
 
D

Dick Grier

Hi,

I haven't looked at the CreateFile call in OpenNETCF for more than a year.
However, I suspect that it doesn't handle ports greater than 16. The port
should be specified thusly:

CreateFile("\\.\COM" & m_Port.ToString 'etc. (or the equivalent)

If the \\.\ is omitted, the result will be what you are seeing.

However, if you want the quick work-around, just download DesktopSerialIO
from my homepage. I handles port1 1-255 -- and also is free. The code that
you implement will be "almost" the same. With my implementation, all that
you need to do is to set the port number. It tests to see if it is valid
for you (if it isn't valid, the dll resets the port number to the last valid
number).

So, code like this will work:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

With SerialPort

For I As Integer = 1 To 255

Try

SerialPort.CommPort = I

Catch ex As Exception

Debug.WriteLine("port " & I.ToString & " not available.")

End Try

Next

End With

End Sub


Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
 
D

Dick Grier

The design goal of the Opennetcf.org serial code was to support Smart
Devices, where the number of serial ports is limited. Its use on the
desktop was so that you could have a common codebase for both devices and
PCs. I handled this by providing two different DLLs that have an identical
API. Opennetcf handled it by conditional compile; this may have resulted in
the comport number limitation.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 4th
Edition ISBN 1-890422-28-2 (391 pages) published July 2004. See
www.mabry.com/vbpgser4 to order.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top