- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
January 29 2009 04:50 PM
How can I turn the 802.11 radio on and off as needed via code?
Solved! Go to Solution.
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
January 30 2009 05:32 AM
Using the Communications resource kit you can call the Load / UnloadNetworkDevice method
int result = -1;
int Device = Intermec.Communication.LAN.NetworkTools.ITC_NETWOR
byte[] buffer1 = new byte[512];
buffer1 = new byte[513];
result = Intermec.Communication.LAN.NetworkTools.UnloadNetw
result = Intermec.Communication.LAN.NetworkTools.LoadNetwor
I hope this helps,
John
Development Support
Cedar Rapids Iowa
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
January 30 2009 06:21 AM
One way to do it is to use the "Set" method in the Device Management Resource kit. I have attached a zip file containing a fully-functioning C# VS2005 project to demonstrate this on a CN3 WM5 device. The meat of the application is shown below.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Intermec.DeviceManagement.SmartSystem; namespace CN3WLANRadioOnOff { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void buttonExit_Click(object sender, EventArgs e) { Application.Exit(); } private void buttonRadioOn_Click(object sender, EventArgs e) { //Use Device Management Resource Kit method "Set" to enable the radio ITCSSApi ss; string sSet802dot11RadioStateXml; uint uiRet = 0; string sXML; int iLen = 1024; ss = new ITCSSApi(); // XML to turn on the 802.11 WLAN radio. sSet802dot11RadioStateXml = "<Subsystem Name=\"Communications\">\r\n"; sSet802dot11RadioStateXml += "<Group Name=\"802.11 Radio\">\r\n"; sSet802dot11RadioStateXml += "<Field Name=\"Radio Enabled\">"; sSet802dot11RadioStateXml += "1"; //1 = Enabled, 0 = disabled sSet802dot11RadioStateXml += "</Field>\r\n"; sSet802dot11RadioStateXml += "</Group></Subsystem>\r\n"; //Actual work begins here StringBuilder sbRetData = new StringBuilder(iLen); sXML = sSet802dot11RadioStateXml; uiRet = ss.Set(sXML, sbRetData, ref iLen, 0); if (uiRet != ITCSSErrors.E_SS_SUCCESS) { MessageBox.Show("Error changing settings"); } } private void buttonRadioOff_Click(object sender, EventArgs e) { //Use Device Management Resource Kit method "Set" to disable the radio ITCSSApi ss; string sSet802dot11RadioStateXml; uint uiRet = 0; string sXML; int iLen = 1024; ss = new ITCSSApi(); // XML to turn on the 802.11 WLAN radio. sSet802dot11RadioStateXml = "<Subsystem Name=\"Communications\">\r\n"; sSet802dot11RadioStateXml += "<Group Name=\"802.11 Radio\">\r\n"; sSet802dot11RadioStateXml += "<Field Name=\"Radio Enabled\">"; sSet802dot11RadioStateXml += "0"; //1 = Enabled, 0 = disabled sSet802dot11RadioStateXml += "</Field>\r\n"; sSet802dot11RadioStateXml += "</Group></Subsystem>\r\n"; //Actual work begins here StringBuilder sbRetData = new StringBuilder(iLen); sXML = sSet802dot11RadioStateXml; uiRet = ss.Set(sXML, sbRetData, ref iLen, 0); if (uiRet != ITCSSErrors.E_SS_SUCCESS) { MessageBox.Show("Error changing settings"); } } } }
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
January 30 2009 12:12 PM
You can also use functions exposed by Microsoft's ossvcs.dll. Here is the code to enable and disable all wireless radios in C#.
-Tim
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace ToggleMobileRadiosCS { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } [DllImport("ossvcs.dll", EntryPoint = "#276", CharSet = CharSet.Unicode)] private static extern uint GetWirelessDevice(ref IntPtr pDevice, int pDevVal); [DllImport("ossvcs.dll", EntryPoint = "#273", CharSet = CharSet.Unicode)] private static extern uint ChangeRadioState(ref RDD pDevice, int dwState, int saveAction); [DllImport("ossvcs.dll", EntryPoint = "#280", CharSet = CharSet.Unicode)] private static extern uint FreeDeviceList(IntPtr pDevice); [StructLayout(LayoutKind.Auto)] struct RADIODEVSTATE { public const int RADIODEVICES_ON = 1; public const int RADIODEVICES_OFF = 0; } /* typedef enum _RADIODEVTYPE { RADIODEVICES_MANAGED = 1, RADIODEVICES_PHONE, RADIODEVICES_BLUETOOTH, } RADIODEVTYPE; */ [StructLayout(LayoutKind.Auto, CharSet = CharSet.Unicode)] struct RADIODEVTYPE { public const int RADIODEVICES_MANAGED = 1; public const int RADIODEVICES_PHONE = 2; public const int RADIODEVICES_BLUETOOTH = 3; } /* typedef enum _SAVEACTION { RADIODEVICES_DONT_SAVE = 0, RADIODEVICES_PRE_SAVE, RADIODEVICES_POST_SAVE, } SAVEACTION; */ [StructLayout(LayoutKind.Auto, CharSet = CharSet.Unicode)] struct SAVEACTION { public const int RADIODEVICES_DONT_SAVE = 0; public const int RADIODEVICES_PRE_SAVE = 1; public const int RADIODEVICES_POST_SAVE = 2; } /* struct RDD { RDD() : pszDeviceName(NULL), pNext(NULL), pszDisplayName(NULL) {} ~RDD() { LocalFree(pszDeviceName); LocalFree(pszDisplayName); } LPTSTR pszDeviceName; // Device name for registry setting. LPTSTR pszDisplayName; // Name to show the world DWORD dwState; // ON/off/[Discoverable for BT] DWORD dwDesired; // desired state - used for setting registry etc. RADIODEVTYPE DeviceType; // Managed, phone, BT etc. RDD * pNext; // Next device in list }; //radio device details */ [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] struct RDD { [MarshalAs(UnmanagedType.LPTStr)] public string pszDeviceName; [MarshalAs(UnmanagedType.LPTStr)] public string pszDisplayName; public uint dwState; public uint dwDesired; public int DeviceType; public IntPtr pNext; } private bool SetDeviceState(int dwDevice, int dwState) { IntPtr pDevice = new IntPtr(0); RDD device; uint result; //Get the first wireless device result = GetWirelessDevice(ref pDevice, 0); if (result != 0) return false; //If the first device has been found if (pDevice != null) { //While we're still looking at wireless devices while (pDevice != IntPtr.Zero) { //Marshall the pointer into a C# structure device = (RDD)System.Runtime.InteropServices.Marshal.PtrToS
tructure(pDevice, typeof(RDD)); //If this device is the device we're looking for if (device.DeviceType == dwDevice) { //Change the state of the radio result = ChangeRadioState(ref device, dwState, SAVEACTION.RADIODEVICES_PRE_SAVE); } //Set the pointer to the next device in the linked list pDevice = device.pNext; } //Free the list of devices FreeDeviceList(pDevice); } //Turning off radios doesn't correctly report the status, so return true anyway. if (result == 0 || dwState == RADIODEVSTATE.RADIODEVICES_OFF) return true; return false; } /// <summary> /// Turn on all wireless radios /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void allOnButton_Click(object sender, EventArgs e) { //WIFI if (SetDeviceState(RADIODEVTYPE.RADIODEVICES_MANAGED, RADIODEVSTATE.RADIODEVICES_ON) && //Bluetooth SetDeviceState(RADIODEVTYPE.RADIODEVICES_BLUETOOTH , RADIODEVSTATE.RADIODEVICES_ON) && //Phone SetDeviceState(RADIODEVTYPE.RADIODEVICES_PHONE, RADIODEVSTATE.RADIODEVICES_ON)) { MessageBox.Show("Enabled all radios successfully"); } else MessageBox.Show("Enable all radios not successful"); } /// <summary> /// Turn off all wireless radios /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void allOffButton_Click(object sender, EventArgs e) { //WIFI if (SetDeviceState(RADIODEVTYPE.RADIODEVICES_MANAGED, RADIODEVSTATE.RADIODEVICES_OFF) && //Bluetooth SetDeviceState(RADIODEVTYPE.RADIODEVICES_BLUETOOTH , RADIODEVSTATE.RADIODEVICES_OFF) && //Phone SetDeviceState(RADIODEVTYPE.RADIODEVICES_PHONE, RADIODEVSTATE.RADIODEVICES_OFF)) { MessageBox.Show("Disabled all radios successfully"); } else MessageBox.Show("Disable all radios not successful"); } } }
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
February 5 2009 06:29 AM
Here's an updated version of the C# .NET application to toggle the CN3 WLAN radio on/off. I've included some user feedback on the screen to let him know the application is doing something because the "Set" method can take several seconds to execute.
The attached zip file also contains a Deploy folder. In there you'll find a zip file containing all the files you'll need to deploy the application onto a CN3 device. There is also a read-me file in there with instructions.
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
February 13 2009 12:37 AM
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
February 13 2009 04:50 AM
CervenR wrote:
I used CITCNetworkTools::LoadNetworkDevice many years without a problem. After one of the last IDL updates I realized it stopped to work on CK61. The function returns 0 (success) but it doesn't turn on/off either Ethernet or WiFi.
This seems to work on the CN3. Maybe it will help.
Its written with version 3.20 of the Communications resource kit.
Development Support
Cedar Rapids Iowa
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
February 13 2009 05:43 AM
CervenR wrote:
I used CITCNetworkTools::LoadNetworkDevice many years without a problem. After one of the last IDL updates I realized it stopped to work on CK61. The function returns 0 (success) but it doesn't turn on/off either Ethernet or WiFi.
I believe this works by unloading the network card driver, rather than turning off the radio. Just thought I'd add this bit of information if you'd rather turn the radio on and off.
-Tim
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
February 13 2009 06:52 AM
I usually call load network device before calling the turning the radio on. The only difference between the sample and my code is the value of the parameter bBypassDeviceCheck. In my code is set the default value FALSE. When this parameter is set to TRUE it works.
Thanks.
Roman
Re: Turn radio on and off as needed
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
February 23 2009 11:45 AM
Couple of notes:
1) Tim is correct - the ITCNetworkTools work by loading/unloading the device driver. The result is that the device is enable/disabled, which translates to on/off in some cases.
2) The likely reason that it works if you bBypassDeviceCheck is TRUE is because you are telling the API to unload\load the device driver without first checking to see if it is loaded or not. Most likely, the check to see if it is loaded has broken with an update at some point. By bypassing that check you are "forcing" the load/unload to occur.

