Monday, June 18, 2007

I've been working on a project where there was little point in synchronising data if the Mobile device was out of network range (for obvious reasons)

So rather than wait for an HTTP timeout type error thrown by the SQL Compact Merge replication, I needed a quick way to determine if the mobile device is connected to any sort of network.

This bit of code has been kicking about for a while and it simply returns if the mobile device has any IP address other than that of localhost -

 

 

 

public static bool OnNetwork()
        {
            IPHostEntry mydev = Dns.GetHostEntry(Dns.GetHostName());

            for (int nindex = 0; nindex < mydev.AddressList.Length; nindex++)
            {
                string aux = mydev.AddressList[nindex].ToString();
                if (aux != "127.0.0.1") return true;
            }
            return false;

        }
 
So putting the above bit of code in a background thread and calling it periodically is a nice simple way to detect if a device is in network range.  I then raise an event if the state changes.
Now I know what your thinking?   Windows Mobile 5/6 ships with the 'State and Notification Broker API'.   Given this I thought I ought to update my approach for newer devices.     Reading -
http://www.developer.com/ws/pc/article.php/3547381
I thought it would make sense to implement it this way as it is much less hassle than a background thread. So the code behind a simple form to achieve this, looks like this.
 
namespace DeviceApplication10
{
    public partial class Form1 : Form
    {
        SystemState foundnet = new SystemState(
                           SystemProperty.ConnectionsNetworkCount);

        private  bool onnetwork()
        {
            IPHostEntry mydev = Dns.GetHostEntry(Dns.GetHostName());

            for (int nindex = 0; nindex < mydev.AddressList.Length; nindex++)
            {
                string aux = mydev.AddressList[nindex].ToString();
                if (aux != "127.0.0.1") return true;
            }
            return false;

        }
        public Form1()
        {
            InitializeComponent();
            foundnet.Changed += new ChangeEventHandler(foundnet_Changed);
        }

        void foundnet_Changed(object sender, ChangeEventArgs args)
        {
            if (onnetwork())
            {
                // do some stuff as we are now on the network, like work out SSID of current wireless network etc.
            }
           
        }
    }
}

The above event fires when the number of network connections change.   I then do a quick call to my onnetwork() method when the event fires, just to be certain than we can talk to the outside world.

So, why is this post called Drive By?    Well the above allows my Windows Mobile device to automatically  detect when I park my car at home as it knows when I'm on my home wireless network.      Geeky but cool...

 

Technorati tags:
Monday, June 18, 2007 10:59:43 AM UTC  #    Comments [0]  | 
Wednesday, June 13, 2007

One of the most time consuming tasks, I find with building LOB apps,  is setting up columns on Datagrid.   You know the game run your application see that column one is truncating the text in a database column.   Widen the column and run again,  repeat until very bored.

A while back I took the step to programmatically adding a grid style to each class we build (using Anglia's meta build tool Datamaker).   This saves so much time as most of the display widths are always pretty close to perfect.    One of my colleagues and friends Michael Holland has further refined this process to counter for different DPI screens (cool).   Here's an example of what we produce automatically.

 

      public static DataGridTableStyle GridStyle
        {
            get
            {
                DataGridTableStyle gridstyle = new DataGridTableStyle();
                gridstyle.MappingName = "Output[]";
                DataGridColumnStyle tempcol = null;

                // Maps To Database Field - [100]
                tempcol = new DataGridTextBoxColumn();
                tempcol.MappingName = "Onezerozero_Label";
                tempcol.HeaderText = "100";
                tempcol.Width = 60;
                tempcol.NullText = "N/A";
                gridstyle.GridColumnStyles.Add(tempcol);

                // Maps To Database Field - [1000]
                tempcol = new DataGridTextBoxColumn();
                tempcol.MappingName = "Onezerozerozero_Label";
                tempcol.HeaderText = "1000";
                tempcol.Width = 60;
                tempcol.NullText = "N/A";
                gridstyle.GridColumnStyles.Add(tempcol);

            return (SqlParameter[])returnparams.ToArray(typeof(SqlParameter));
        }
}

This saves, Soooo much time particularly when having to deploy to the device emulator.     If we need to omit certain columns or swap the order around, its just a cut and paste job.

Technorati tags: ,
Wednesday, June 13, 2007 7:53:53 PM UTC  #    Comments [0]  | 
Thursday, June 07, 2007

So in the line of business application space,  I often need to acquire external inputs from real world devices,  such as weigh scales,   pressure and moisture sensors.

 

I've often use WebService calls directly from the mobile device to call services on P.C's hooked up to measuring equipment usually via a serial port.

However increasingly I use insert triggers on SQL tables to fire off requests to physical devices (using managed code) stored procedures.   So, the action of syncing SQL Compact causes results from devices to be captured.    This technique works really well and ensures that SQL Compact syncrhonisation is the only data exchange from the mobile device.   This keeps things simple (always good).     The only downside is that when standing next to a weigh scale etc. with a mobile device you have to be in range of the wireless network.   

So upshot of all of this,  is that our end user can wander around taking weight's and measurements almost 'magically' with no physical connection from the mobile device they are using...

 

Technorati tags:
Thursday, June 07, 2007 7:46:25 PM UTC  #    Comments [2]  | 
Tuesday, June 05, 2007

So Now I have my SPV e650, printing photo's direct to a Bluetooth connected printer.

I went for a totally crude solution, which just looks for black/white pixels in an image.   So with buffer being a stringbuilder we're going to send out to the printer go have a peek at...

 

  public void LoadImage(Bitmap _bmp, int x, int y)
        {

            buffer.Append("EG ");
            
            buffer.Append("4 ");
            buffer.Append(_bmp.Height + " ");
        
            buffer.Append(x + " ");
            buffer.Append(y + " ");
            for (int xcount = 0; xcount < _bmp.Width; xcount++)
            {
                for (int ycount = 0; ycount < _bmp.Height; ycount++)
                {
                   int gotcol= _bmp.GetPixel(xcount, ycount).ToArgb();
                    if (gotcol == -1)
                        buffer.Append("F");
                    else
                        buffer.Append("0");
                  
                }
               
            }
            buffer.Append(eol);
          

        }
Technorati tags: ,
Tuesday, June 05, 2007 10:31:46 PM UTC  #    Comments [0]  | 
Sunday, June 03, 2007

So I've been on a mission this weekend, getting a Zebra belt mounted Bluetooth printer to print photo's from a mobile application.

So I built a simple test program that outputs CPCL printing commands to a Zebra MZ220 Bluetooth printer.  

My helper library wraps the CPCL command set as follows -

CPCLPrinter prn = new CPCLPrinter("COM18");
            prn.StartLabel();
            prn.PageWidth(300);
            prn.Center();
            prn.Text(0,7,0,140,114,"Hello World");
            prn.EndLabel();
          
            prn.Print();
  prn.Dispose();

So far so good.   I'm simply using the System.IO.Ports namespace to talk to the Bluetooth mapped serial port.

So next question is how to print Bitmaps.     These printers are all about reliable repeated printouts.   So catering for on the fly generated images so dynamically generating images is something a little different.

The first challenge is that these printers are black and white,  so we need a way of reducing the colour depth of our inbound Bitmap.

Next will be to convert to PCX format.

Then we'll need to send this over to the printer.

Finally we need to wrap it into a simple app. that takes a photo and starts the whole process.

Will keep you posted on progress.

Technorati tags: ,
Sunday, June 03, 2007 2:31:33 PM UTC  #    Comments [1]  | 
Monday, February 26, 2007

I prepared a short screencast video, showing Anglia's Datamaker technology generating lots and lots of managed code automatically.

In the video, we select a Dynamics Nav table tell it we are writing a SQL Compact application and DataMaker does the rest.

The video concludes of the auto generated code being pasted into a Visual Studio solution and being complied successfully.

It sure save a lot of typing....

 

Video at -

http://private.angliabs.com/webextension/video/datamaker.avi

 

DataMaker details at -

http://www.angliabs.com

Monday, February 26, 2007 4:39:59 PM UTC  #    Comments [0]  | 
Monday, February 19, 2007

Just an FYI

I'm not sure if anyone else has see this behaviour.    Under SQL Compact and previous versions, the only way I have found to retrieve an image from the database is to use a - SqlCeCommand.ExecuteScalar

I cannot no matter how hard I've tried get SqlCeCommand.ExecuteResultSet to retrieve an image out of the database.

 

 

 

Monday, February 19, 2007 3:24:12 PM UTC  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: