Categorized | Code

Creating a Cellular Line (GPRS) Modem from code

Here’s a code snippet i just found really usefull. I was getting 20 MC75 pda’s ready for a customer pilot project and we’ve developed a solution but hadn’t design any deployment system for getting the devices ready, so it was all manual work.

The solution uses the network through GPRS/Edge and each of the devices needed to have a cellular (GPRS) Line modem connection defined. Doing this on 20 devices by browsing to Settings -> Connections -> Add new modem connection, then add the same data for APN, username, password was just to much of a pain.

An easier way of doing this is to use the ConfigurationManager, found in the Microsoft.WindowsMobile.Configuration namespace. My purpose was to just make sure there was a cellular modem connection defined  with a working configuration. I wanted this to be the first to be done, and i wanted this to be re-run at application launch each time to reset any “mis”-configuration done by end users thorough the pilot period.

Firstly i defined a method that would give me a string with xml data. – This could also have been done a bit more elegantly or smooth, but it works for me this way.

private static string XmlConnectionString()
{
     string connectionName = "GPRS";
     string username = "";
     string password = "";
     string apnName = "Telenor";
     string myString =

     "<wap-provisioningdoc>" +
     "<characteristic type=\"CM_GPRSEntries\">" +
     "<characteristic type=\"" + connectionName+ "\">" +
     "<parm name=\"DestId\"" +
     " value=\"{ADB0B001-10B5-3F39-27C6-9742E785FCD4}\" />" +
     "<parm name=\"UserName\" value=\" "+ username +"\" />" +
     "<parm name=\"Password\" value=\"" + password +"\" />" +
     "<parm name=\"Domain\" value=\"\" />" +
     "<characteristic type=\"DevSpecificCellular\">" +
     "<parm name=\"GPRSInfoValid\" value=\"1\" />" +
     "<parm name=\"GPRSInfoAccessPointName\" value=\"" + 
     apnName +"\" />" +
     "</characteristic>" +
     "</characteristic>" +
     "</characteristic>" +
     "</wap-provisioningdoc>";
     
     return myString;
}

Secondly I create my modem connection as the very first thing in the application Main method.

[MTAThread]
static void Main()
{
     try
     {
          XmlDocument configDoc = new XmlDocument();
          configDoc.LoadXml(XmlConnectionString());
          ConfigurationManager.ProcessConfiguration(configDoc, false);
     catch (Exception ex)
     {
          // Error Handling.....
     }
}

This was a quick and “dirty” way of doing it, and it saved me some time.

Use Facebook to Comment on this Post

Leave a Reply

Google Translate

EnglishFrenchGermanItalianPortugueseRussianSpanish

Blog Traffic

Hits

Pages|Hits |Unique

  • Last 24 hours: 4,797
  • Last 7 days: 22,188
  • Last 30 days: 57,167
  • Online now: 12

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

%d bloggers like this: