Compact Flash radio card - how to turn on and off in VB code

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
Hi all. I have some handheld CE terminals with radio network cards built in, which are 'On' all the time. This interferes with their daily operation (ticket collecting on a boat). Is there a function call or API for turning the radio network card off and on?

The radio network is only used at the day's end to 'unload' all the day's ticket data.

Thank you.
 
Search for

VB.NET:
98C5250D-C29A-4985-AE5F-AFE5367E5006
 
So far, I have the following code (see below). The MsgBox ret1 and ret2 both return 2. The variable gstrComputerName is set to the computer name as found by GetMacAddress(). There is a radio card installed but not connected to a network (it says, 'Searching for networks').

Does the radio card need to be connected before the functions work correctly? Have I missed something in the code? No error messages are returned, just the '2 2' from the temporary message boxes.

Thank you.

VB.NET:
    Public Enum DevicePowerState As Integer
        Unspecified = -1
        FullPower = 0       'Full On: full power, full functionality
        LowPower = 1           'Low Power On: fully functional at low power/performance
        Standby = 2            'Standby: partially powered with automatic wake
        Sleep = 3             'Sleep: partially powered with device initiated wake
        Off = 4               'Off: unpowered
    End Enum

    Private Declare Function SetDevicePower Lib "coredll.dll" (ByVal deviceId As String, ByVal flags As Integer, ByVal state As DevicePowerState) As Integer
    Private Declare Function DevicePowerNotify Lib "coredll.dll" (ByVal deviceId As String, ByVal state As DevicePowerState, ByVal flags As Integer) As Integer

    Public Sub TurnRadioCardOn()
        Dim ret1 As Integer
        Dim ret2 As Integer

        Try

            ret1 = DevicePowerNotify("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\" & gstrComputerName, DevicePowerState.FullPower, 1)
            ret2 = SetDevicePower("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\" & gstrComputerName, 1, DevicePowerState.FullPower)

            MsgBox(ret1 & " " & ret2)

            Application.DoEvents()

        Catch f As Exception
            MsgBox("TurnRadioCardOn " & Err.Number & ": " & Err.Description)

        End Try

    End Sub

    Public Sub TurnRadioCardOff()
        Dim ret1 As Integer
        Dim ret2 As Integer

        Try

            ret1 = DevicePowerNotify("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\" & gstrComputerName, DevicePowerState.Off, 1)
            ret2 = SetDevicePower("{98C5250D-C29A-4985-AE5F-AFE5367E5006}\" & gstrComputerName, 1, DevicePowerState.Off)

            MsgBox(ret1 & " " & ret2)

            Application.DoEvents()

        Catch f As Exception
            MsgBox("TurnRadioCardOff " & Err.Number & ": " & Err.Description)

        End Try

    End Sub
Of course, TurnRadioCardOn and TurnRadioCardOff are called from command buttons.
 
Never actually tried it, but will try and let you know.
 
Back
Top