Connectivity States (Wireless, Ethernet, & USB)

G

Guest

I have a pretty basic question about the state of connectivity. My
application will be a mostly disconnected application that (when available)
needs to send & receive data from the enterprise server. The question I have
is that how can I monitor (from the device) for a good Wireless connection,
an ethernet connection, or a USB connection? The customer will be using all
three situations to load & unload data from the device. Both the USB &
Ethernet would be a cradle situation but the wireless would be a here & there
situation. Thusly, my second question is how I can monitor for a wireless
connection with an acceptable level of strength (30%). The users will be
walking through areas all the time that have wireless access points.
Sometimes these areas will be open for minutes & sometimes they'll only pass
by them for a few seconds. I need to be able to monitor for any of the above
3 situations and begin my transfers when certain criteria are met. I've seem
several posts on where to find more information on this subject but no posts
on exactly how to write it in & implement it onto the handheld. I want this
to happen automatically, behind the scenes without any user interaction. Any
help would be greatly appreciated. Thanks!!
 
P

Paul G. Tobey [eMVP]

In that situation, you're basically describing how Microsoft Message Queue
works. You drop messages in a queue and, when you are connected, the OS
detects that, automatically connects and sends the message. I don't think
that there are any finished libraries with MSMQ wrapped for .NET CF, but I
think that you'll find that having the OS handle the forwarding of messages
is worth having to do that wrapping yourself, rather than having to handle
all of the connect/disconnect/signal quality issues yourself. Does the
device have MSMQ on it?

Paul T.
 
S

Sergey Bogdanov

Also you can periodically call RasEnumConnection P/Invoke in a separate
thread. It will return list of all active RAS connections and its names
that can be used to distinguish between one another. For example, for an
active USB connection it will return connection with the name "`USB" or
something.

Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
 
G

Guest

First, Thank you both...both responses are helpful. However, I'm pretty
green to smart device development & need to get a little more detail before
diving into these issues. With regards to the MSMQ, it is on the device but
all I need to do is monitor for connection states & then submit some T-SQL to
the enterprise server. It seems that the MSMQ would be overkill for this.
With regards to calling "RasEnumConnection P/Invoke"...I haven't gotten into
Multithreading yet and perhaps this would be a good start. My question for
this is how do I periodically call it?

Isn't there a way that I can set the device up so that when the wireless
connection is available it runs my sync procedure or application every 15
minutes in the background? I've read some posts on how to kick things off
when the device is cradled but where do I put this coding on the device & how
do I get it to run as a system service?
 
P

Paul G. Tobey [eMVP]

OK, it might be true that MSMQ is overkill. You could use a timer to
trigger calling the enumeration periodically, or you could create a thread
in which there is a wait on an event. If the wait times out, it's time to
enumerate the connections. If the event fires, that means that the thread
should exit. Pretty standard stuff. OpenNETCF has lots of support for
threading, events, etc.

The OpenNETCF.Net namespace has a lot of stuff for receiving notifications
of change of state for adapters. That's probably your best bet for doing
something when wireless becomes connected. Look at AdapterStatusMonitor.
It's based on unmanaged code that I use on our devices to turn on an
indicator when wireless networking is connected.

Paul T.
 
G

Guest

While I can appreciate that the OpenNETCF has lots of valuable tools, its
adapter monitoring class is horrific. I've been attempting to accomplish
using this for several weeks now & have since turned to posting questions
here.

I'm still convinced that monitoring for two events (wireless availability &
cradling) cannot be that difficult. I know the device itself reacts to these
actions so I simply need to include or append my logic into the devices
already present event handlers.

I'm looking for a solution outside of the OpenNETCF.NET namespace. While v.
1.1 did improve the adapter status area, It is still far from where many
other of the namespaces currently are. I'm sure they'll iron out all of the
wrinkles in time...but unfortunately I don't have the flexibility to wait on
this project.

Basically what I am looking for is a way to install some sort of
application, class, system monitor, something onto the device that will
monitor for the two connection states & when available automatically act
accordingly.
 
P

Paul G. Tobey [eMVP]

Thanks for the notes, since this caused me to find a bug in the library.
There's no easy, ten-line solution to being notified of network events like
connect and disconnect, no. I tried four or five different schemes in
unmanaged code for our devices before settling on one that uses
point-to-point message queues and NDISUIO notifications. The
AdapterStatusMonitor class in OpenNETCF is a direct port from that unmanaged
code.

What you should do is, when a notification occurs, check the adapters which
are of interest to you and see if there's been a status change that you care
about. Ideally, just the notification messages should be enough to tell you
if an adapter has reestablished connection or lost it, but each adapter
sends messages to NDIS a bit differently and, depending on the
adapter/driver, you may get an unbalanced number of connect and disconnect
messages, or something along those lines, making it difficult to use the
information by itself to decide what the connection state is.

The latest source in the Vault for OpenNETCF includes the bug fix and
there's also a new Sample of using the status monitor.

Paul T.
 
G

Guest

Hi Salim,

The solution of the link don't work correctly because don't detect the
disconnected state when wireless is out of range. Any easy solution for this?

Ramón Somorrostro.
 
P

Paul G. Tobey [eMVP]

What does the WZC dialog show in that situation? Obviously, your .NET CF
code isn't going to know more about the state of things than the OS itself.
If it doesn't know that it's out of range, you don't know, either.

Paul T.
 
E

Elmer Miller

I can't find the AdapterStatusMonitor class at OpenNETCF. Is it supposed to
be in the OpenNETCF.Net namespace? Where can I get this? I would like to be
able to programmatically connect and disconnect to the Internet on a CE.NET
device. I know that the ConnectionManager class doesn't really work on
CE.NET devices, which is a bummer, because that seems to be the best way to
connect.
 
P

Paul G. Tobey [eMVP]

Yes, it is there. Get the latest source from the Vault. It should be in
1.3, too, but haven't actually checked that.

Paul T.
 
G

Guest

Namespace= System.Net.NetworkInformation
Event = NetworkAdressChangedEvent

You subscribe programmatically to this event
Then when the event is thwron, instantiate an enumerator on it
All modified network interface are monitored
 

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