473,795 Members | 2,861 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OpenNETcf Serial port question

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.comRThresho ld
.Settings.BaudR ate = cpi.comBaud
.Settings.ByteS ize = cpi.comByte
.Settings.Parit y = cpi.comParity
.Settings.StopB its = cpi.comStopbits
End With
Try
ac = SerialPort.Open
err = ""
SerialPort.Clos e()
Catch ex As Exception
err = ex.Message.ToSt ring
MsgBox(err + vbCrLf + "com" + ab.ToString)
SerialPort = Nothing
End Try
If ac = True And Not SerialPort Is Nothing Then
Me.cbCom.Items. Add(Mid(SerialP ort.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
Nov 21 '05 #1
5 2704
EMW
it actualy doesn't work for any other port except com4.
I must be doing something wrong...but what....
"EMW" <so*****@MikroZ oft.com> schreef in bericht
news:42******** ************@dr eader2.news.tis cali.nl...
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.comRThresho ld
.Settings.BaudR ate = cpi.comBaud
.Settings.ByteS ize = cpi.comByte
.Settings.Parit y = cpi.comParity
.Settings.StopB its = cpi.comStopbits
End With
Try
ac = SerialPort.Open
err = ""
SerialPort.Clos e()
Catch ex As Exception
err = ex.Message.ToSt ring
MsgBox(err + vbCrLf + "com" + ab.ToString)
SerialPort = Nothing
End Try
If ac = True And Not SerialPort Is Nothing Then
Me.cbCom.Items. Add(Mid(SerialP ort.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

Nov 21 '05 #2
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

With SerialPort

For I As Integer = 1 To 255

Try

SerialPort.Comm Port = 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.
Nov 21 '05 #3
EMW
thanks, Dick, I'll take look at your homepage immidiately!
"Dick Grier" <di************ **@msn.com> schreef in bericht
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
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(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

With SerialPort

For I As Integer = 1 To 255

Try

SerialPort.Comm Port = 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.

Nov 21 '05 #4
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.
Nov 21 '05 #5
EMW
that makes sense....

Eric.
"Dick Grier" <di************ **@msn.com> schreef in bericht
news:uD******** ******@TK2MSFTN GP09.phx.gbl...
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.

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
9094
by: ^CeFoS^ | last post by:
Hello to everybody, I've done an application that draws in a frame the trajectory of a robot. The robot position is readed through the serial port, and several commands are wrote through the same port to change the direction of the robot. The trajectory frame is managed by an applet, and the project works good when the applet is called by a html document allocated in the same local machine under W98 where the classes and the serial port...
3
4590
by: rusttree | last post by:
Many moons ago, I took a class in embedded control at school. The course focused on a micro-controller mounted on a small electric car that was programmed using simple C code. The micro-controller chip had several pins, some of which were for output and some were for input. The crux of the project was to make the program set the ouput pins to high or low to drive the servos and motors and read the input pins that were attached to various...
2
2992
by: salsipius | last post by:
I can't figure this out, Please Help!!!! I would appreciate any remarks or opinions or help about the code below. A you can see I am writing and reading from the serial port, that is going OK MOST of the time. My big problem is when I want to break the while loop. I am expecting a message in HEX to come in from the serial port. for instance "0004 600A", which I get most of the time, sometimes I just get random ASCII chars, anyway to the...
21
2995
by: The Man With The Harmonica | last post by:
Hi All, What kind of commands can I use to control the serial and parallel port of my pc. I want to use my laptop instead of microcontrollers and write my software in ANSI C to be used for control purposes of sensors and other electronic devices. I haven't done any C for a while now so I would assume my knowledge is that of a beginner now.
1
3633
by: Mike | last post by:
Sorry, don't know if this is the correct board for my question. I'm a novice so I guess I have a valid excuse My question : I'm using Visual C++ and I need to collect data from a serial port. Specifically, I have a piece of equipment that outputs ASCII data to my computer through the serial port. Is there some way I can call the serial port from within Vis C++ and then save the data I'd much rather do this than buy some sort of software,...
4
11207
by: joe bloggs | last post by:
I am writing a mobile application to interface with a legacy system and I am planning to use web services to communicate with this system. The legacy system receives data through a serial port. What I would like to do is make the serial port accessible via a web service. The web service and the legacy application would be running on the same machine. The mobile application would access the web service via a network connection. It...
38
9671
by: shussai2 | last post by:
Hi, I am trying to access Serial Port in XP. I am using Dev-C++ IDE that uses Mingw as a compiler. I just want to know how I can open up serial port on COM1 and write some data. I have searched quite a bit over the web and could not find anything useful. I don't want to use Visual C++ or Cygwin, linux, etc. If any of you guys have some little tid bit of code that would be great to look at.
13
6211
by: Rob | last post by:
Hi all, I am fairly new to python, but not programming and embedded. I am having an issue which I believe is related to the hardware, triggered by the software read I am doing in pySerial. I am sending a short message to a group of embedded boxes daisy chained via the serial port. When I send a 'global' message, all the connected units should reply with their Id and Ack in this format '0 Ack' To be certain that I didn't miss a...
9
14402
by: Hal Vaughan | last post by:
I've done a fair amount of Googling for information on reading the serial port in C++ (and in Linux). Unfortunately, out of every 4 hits, 1 seems to be an unanswered question, 1 is someone saying, "That's easy, there's a lot out there, Google it,", 1 is a discussion on it without examples and the other is who knows what. I did find some info on it and have been experimenting. The one example that I liked the best in terms of...
0
10216
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7543
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2921
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.