Anyone using the OpenNETCF CommunicationsManager successfully?

  • Thread starter Thread starter Jon Skeet [C# MVP]
  • Start date Start date
J

Jon Skeet [C# MVP]

I've been having significant trouble with the CommunicationsManager,
and I'd like to know whether or not it's just me. In particular, it
doesn't reflect the current connection state very well at all, often
claiming to be disconnected when in fact it's connected, etc.

I suspect this *may* be the PocketPC API itself being rubbish
(certainly there are difficulties here - turning the phone on
programatically ends up changing the phone icon to "coming on" but it
never shows any signal, even when it's blatantly got it due to a
connection working). I'd be interested to hear anyone else's
experiences with the connection manager.

The background here is that I have a permanently running app which
basically wants to control comms completely. I'm able to turn the phone
on and establish a connection (so long as I pick the right one :) but
if I turn the phone off, I get an unwanted dialog saying that the
connection can't be made. Understandable, but annoying. I'd like to
disconnect the connection first, to avoid the dialog - but as the
CommsManager doesn't know that it's connected to start with, it doesn't
disconnect properly...
 
Is this OpenNETCF.Net.ConnectionManager?

The ConnectionManager API can be a bit tricksy at times, also what
generation of Pocket PC are you using 2002/2003? There may be some
differences in behaviour between versions...

Peter
 
Peter Foot said:
Is this OpenNETCF.Net.ConnectionManager?

Apologies, yes.
The ConnectionManager API can be a bit tricksy at times, also what
generation of Pocket PC are you using 2002/2003? There may be some
differences in behaviour between versions...

Mainly 2003.

I'm really only trying pretty straightforward things. Direct calls (eg
connecting) seem fine - it's events which would trigger changes to
state which either seem flaky or non-existant.

Any ideas whether it's more likely to be a problem in the OpenNETCF
code or the underlying API? I'm happy to try to fix bugs in OpenNETCF
if they're likely to be there, but given the rest of the platform, I
think it's more likely to just be flaky at the PocketPC level.
 
Have you got a small test application that shows the problems. I don't have
any PPC devices, but I might be able to try it on another CE.NET 4.2 device.
My one foray into the ConnectionManager worked perfectly for me...

Paul T.
 
Paul G. Tobey said:
Have you got a small test application that shows the problems. I don't have
any PPC devices, but I might be able to try it on another CE.NET 4.2 device.
My one foray into the ConnectionManager worked perfectly for me...

I'll try to put my tester program into a more postable format and post
it tomorrow - thanks in advance for trying it.
 
Paul G. Tobey said:
Have you got a small test application that shows the problems. I don't have
any PPC devices, but I might be able to try it on another CE.NET 4.2 device.
My one foray into the ConnectionManager worked perfectly for me...

Okay, here's a test app. Connecting seems to be okay, but disconnecting
doesn't. The initial state detection seems slightly flaky too - it
claims it's disconnected to start with even if it's not. Similarly,
connecting or disconnecting with the phone icon on the PDA itself (or
with another app) doesn't seem to change the state on the program.

using System;
using System.Net;
using System.Net.Sockets;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;
using OpenNETCF.Net;

public class MainForm : Form
{
Label state;
ComboBox connections;

ConnectionManager manager = new ConnectionManager();

static void Main()
{
Application.Run(new MainForm());
}

public MainForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

manager.ConnectionStateChanged += new EventHandler
(ManagerStateChange);
manager.Connected += new EventHandler(ManagerStateChange);
manager.Disconnected += new EventHandler
(ManagerStateChange);
manager.ConnectionFailed += new EventHandler
(ManagerStateChange);

foreach (DestinationInfo info in
manager.EnumDestinations())
{
connections.Items.Add(info.description);
}

// Show the initial state
ManagerStateChange(null, null);
}

void InitializeComponent()
{

state = new Label();
state.Location = new Point(4, 4);
state.Size = new Size(200, 24);
state.Text = "State:";
Controls.Add(state);

connections = new ComboBox();
connections.Location = new Point (4, 32);
connections.Size = new Size(208, 24);
Controls.Add(connections);

Button connect = new Button();
connect.Size = new Size (100, 24);
connect.Location = new Point (4, 60);
connect.Text = "Connect";
connect.Click +=new EventHandler(ConnectHandler);
Controls.Add(connect);

Button disconnect = new Button();
disconnect.Size = new Size (100, 24);
disconnect.Location = new Point (4, 88);
disconnect.Text = "Disconnect";
disconnect.Click +=new EventHandler(DisconnectHandler);
Controls.Add(disconnect);

this.MinimizeBox = false;
this.Text = "Connection Test";
}

void ManagerStateChange(object sender, EventArgs e)
{
Invoke(new EventHandler(ManagerStateChangeUIThread));
}

private void ManagerStateChangeUIThread(object sender,
EventArgs e)
{
lock (this)
{
state.Text = "State: "+manager.State.ToString();
}
}

void ConnectHandler(object sender, System.EventArgs e)
{
lock (this)
{
guid=Guid.Empty;
object item = connections.SelectedItem;
if (item != null)
{

string name = item.ToString();
foreach (DestinationInfo info in
manager.EnumDestinations())
{
if (name.Equals(info.description))
{
guid = info.guid;
break;
}
}
}
}
new Thread (new ThreadStart(Connect)).Start();
}

/// <summary>
/// The GUID to connect to in a different thread
/// </summary>
Guid guid;

void Connect()
{
lock(this)
{
if (guid != Guid.Empty)
{
manager.Connect(guid);
}
else
{
manager.Connect();
}
}
}

void DisconnectHandler(object sender, System.EventArgs e)
{
new Thread (new ThreadStart(Disconnect)).Start();
}

void Disconnect()
{
manager.Disconnect();
}
}
 
Hmmm. I've embarrassed myself. My previous testing didn't include that
module and it doesn't exist on our hardware.

Does anyone with a PPC have a minute to try this?

Paul T.
 
Back
Top