Development Samples
From OptiWiki
This page lists some development samples (either C++ or C#) for commonly faced programming challenges. Most of these samples are not dependent on one of the Opticon devices.
All samples have been found on the Internet, and remain intellectual property of their respective owners. The samples are provided as is.
Related pages
Windows Mobile Development
H 16 - H 19 SDK
Enable WLAN, GSM or Bluetooth from source
With the C++ or C# code from the attached forum, it is possible to enable or disable one of the radio devices from source on Windows Mobile 6 devices.
Windows Mobile 6
Security settings
On Windows Mobile 6, you can turn off security settings, which then will allow you to install and run unsigned applications without questions.
You can alternate these setings by using a CPF file, which is a "compiled XML" file.
The result of this CPF file will be available in the Messaging application of the PDA.
Windows Mobile 6
Using basic functionalities of Windows Mobile
This sample uses the P/Invoke method to use standard API calls from the CoreDLL.dll. This includes samples to retrieve the battery status, controlling the software keyboard (SIP), preform a soft reset, making phone calls from source, capturing hardware buttons, and much more.
Windows Mobile 5
Windows Mobile 6
Capturing phonebuttons
To capture phonebuttons, the following code can be used.
public enum KeysHardware : int { Answer = 0x72, Hangup = 0x73 } public enum KeyModifiers { None = 0, Alt = 1, Control = 2, Shift = 4, Windows = 8, Modkeyup = 0x1000, } [DllImport("coredll.dll", SetLastError = true)] private static extern bool RegisterHotKey( IntPtr hWnd, // handle to window int id, // hot key identifier KeyModifiers Modifiers, // key-modifier options int key //virtual-key code ); [DllImport("coredll.dll")] private static extern uint UnregisterFunc1(KeyModifiers modifiers, int keyID); public static void RegisterRecordKey(IntPtr hWnd) //handle to MessageWindow { UnregisterFunc1(KeyModifiers.None, (int)KeysHardware.Answer); RegisterHotKey(hWnd, (int)KeysHardware.Answer, KeyModifiers.None, (int)KeysHardware.Answer); UnregisterFunc1(KeyModifiers.None, (int)KeysHardware.Hangup); RegisterHotKey(hWnd, (int)KeysHardware.Hangup, KeyModifiers.None, (int)KeysHardware.Hangup); }
Windows Mobile 5
Windows Mobile 6
Create a GPRS connection and connect with it
This sample shows how to set-up a GPRS connection from source using C#, and connect to it.
Windows Mobile 5
Windows Mobile 6
Discover Bluetooth devices from source
Using the Bluetooth discovery sample, you can discover Bluetooth devices from source.
Make sure that the Bluetooth hardware is turned ON before discovering!
Windows Mobile 5
Windows Mobile 6
Signature Capturing
This sample will allow you to capture a customers signature.
Windows Mobile 5
Windows Mobile 6
Integrating GPS
There are 2 ways to integrate GPS in your application.
1. You can open a serial port (serial port info H19), and do the calculations yourself in your application (or use a component like OpenNetCF.IO.Serial to do this)
2. You can use the GPSApi.dll to do this. Microsoft provides a sample application together with the Compact Framework which shows you how to do that. This demo is most likely located in Windows Mobile 6 SDK on your Windowx XP system.
Please note that the "External GPS" utility should be configured, or at least, the Hardware tab of this utility should be configured.
OpenNetCF.IO.Serial
C:\Program Files\Windows Mobile 6 SDK\Samples\Smartphone\CS\GPS
Windows Mobile 5
Windows Mobile 6
Sending an SMS message
An SMS message can be sent from source using the SmsMessage class from Microsoft.
This class can be used in the following way:
public void SendSMS(string _to, string _msg) { Microsoft.WindowsMobile.PocketOutlook.SmsMessage _message = new Microsoft.WindowsMobile.PocketOutlook.SmsMessage(); try { _message.To.Add(new Microsoft.WindowsMobile.PocketOutlook.Recipient(”+31612345678”);//phone nbr _message.Body = “Your message body“; _message.Send(); } catch (SmsException) { MessageBox.Show("SMS SEND FAILED", "SMS FAIL"); return; } MessageBox.Show("SMS SENT", "SMS SUCCESS"); }
Windows Mobile 5
Windows Mobile 6
Handling connections from source
This should be done using the Connection Manager. This is a standard part of the Windows Mobile OS, and can handle GPRS and WLAN connections according to cost effectiveness.
The Microsoft API can be used with C++, but a C# wrapper is created by OpenNETCF, available in the Connectionmanager.cs file.
Pages explaining the Connection manager
Smart Device Framework
Windows Mobile 5
Windows Mobile 6
GSM signal strength
This can be done using the TAPI of Microsoft. In particular the LINEDEVSTATUS is important.
Windows Mobile 5
Windows Mobile 6
Retrieve a Unique ID of the PDA
Please check on the MSDN site for a way to do this on Windows Mobile devices.
You will be able to determine the brand of the device, as well as a unique ID of it. The unique ID is determined by the hardware.
Unique ID example
Get device ID sample source
Windows Mobile 5
Windows Mobile 6
Kiosk mode
Using this sample application, you can see how to create a kiosk mode application of your own application. Everything is hidden, even the start button.
Note that you will need to put your application in a folder, which is executed upon booting yout device.
Windows Mobile 5
Windows Mobile 6
Windows CE 5.0
Retrieving the current installed Compact Framework
Using this source, you can retrieve the currently installed nd used Compact Framework on the PDA running this application.
Windows Mobile 5
Windows Mobile 6
Windows CE 5.0
P/Invoking
Using Visual Studio 2005 or beyond, interthread communication needs to be preformed using delegates.
For example, if you want to put text, retrieved in an eventhandler, in a textbox (2 seperate threads), you will need this.
This example uses the SerialPort class (Compact Framework 2 or beyond) to show this.
Windows Mobile 5
Windows Mobile 6
Windows CE 5.0
Enable GPRS on a PHL 7000
This sample shows you how to enable the GPRS radio on the PHL 7000
Windows CE 5.0
Capturing function keys on a PHL 7000
This code shows how to capture the Fx keys in source on a PHL 7000.
Note that the function keys should be disabled in Start > Settings > Control Center > Fn-Key Settings.
Windows CE 5.0
