Introduction
WiNRADiO WR-1000i is a wide-band communication reciever on a PC card. I use it for monitoring various amature radio channels and sometimes record it for further usage. Assume that you can control a reciever, set your desired channel by giving it's frequency to reciever and if you want record it. By using WiNRADiO capabilities, you can determine when level of signal (signal strength) is more than a constant value. On the other hand you can search (sweep) a frequency bandwidth and report active channels.
Because of this sophisticated features, I wrote a simple program to show how you can control a radio receiver. Before you compile this demo, you must install WiNRADiO driver. After installing the driver, compile and run demo program.
Note: You must have WiNRADiO card to see exact results. For further information about WiNRADiO, click here. Figure 2, shows WiNRADiO 1500 series card.
Figure 2
How the program works
For simplicity, I created a class to call WiNRADiO APIs. Everything is handled by this class: CWiNRADiO.
To start, add WiNRADiO.h and WiNRADiO.cpp to your project. Then include WiNRADiO.h header file at top of your dialog definition or main header file. Define a member variable with variable type: CWiNRADiO
For example:
CWiNRADiO m_Radio;
By using CWiNRADiO
class, you can control your receiver.
A closer look at CWiNRADiO
Note: Most of the function documentation is taken from WiNRADiO SDK document.
Below are the member functions of CWiNRADiO
class:
int OpenRadioDevice(int iDeviceNum);
Description: Opens a radio device to allow you to control the device using the other functions
Parameters
iDeviceNum
: Radio device number that you would like to open from 1 to 255. If zero is specified, it will open the next available device. Serial devices (WR-xx00e) cannot be explicitly specified, but can only be opened with zero.
Return Value: Returns a handle to a device that has to be used to call all the other functions (hRadio
). If zero is returned, no devices were available to open or the specified device doesn't exist.
Remarks: If you would like to have more than one application use the same device, you will have to close the device when you have finished using it to allow other applications to access the device. For Win32 applications, multiple threads can access the same device at any time.
BOOL CloseRadioDevice();
Description: Closes a radio device that was previously opened, and allows another program to access the radio device.
Return Value: If the function succeeds, the return value is TRUE
, otherwise the return value is FALSE
.
LPSTR GetModeString(int iMode, LPSTR lpBuffer, int cbMaxLen);
Description: The GetModeString
function retrieves a text string describing a mode (and optionally bandwidth).
Parameters
iMode
: The mode and optional bandwidth to get the string for. See SetMode
for valid values.
lpBuffer
: Points to a buffer that will receive the mode string.
cbMaxLen
: Specifies the maximum number of characters to copy to the buffer. The mode string is truncated if it is longer than the number of characters specified in cbMaxLen
.
Return Value: Returns a pointer to lpBuffer
if the function is successful. Otherwise, it is NULL
.
BOOL GetPower();
Description: The GetPower
function returns whether the receiver's power is on or off.
Return Value: Returns TRUE
if the receiver's power is on, otherwise it returns FALSE
if it is off.
BOOL SetPower(BOOL bPower=TRUE);
Description: The SetPower
function switches the device's power on or off. This function can be used to power down WiNRADiO in portable applications to conserve battery power.
Parameters
bPower
: If TRUE
, the radio's power is on, otherwise if FALSE
, the radio's power is off.
Return Value: If the function succeeds, the return value is TRUE
. If the function fails, the return value is FALSE
.
BOOL GetMute();
Description: The GetMute
function returns the status of the mute control on the audio output.
Return Value: GetMute
returns TRUE
if audio muting is on, otherwise it returns FALSE
if it is off.
BOOL SetMute(BOOL bMute);
Description: The SetMute
function controls whether the audio output is muted or not.
Parameters
bMute
: If TRUE
, the audio mute is on, otherwise if FALSE
, the audio mute is off.
Return Value: If the function succeeds, the return value is TRUE
. If the function fails, the return value is FALSE
.
int GetMode();
Description: The GetMode
function retrieves the reception mode the receiver is in.
Return Value: The current receiver mode if successful, otherwise, -1 is returned. See SetMode
for the possible mode return values.
BOOL SetMode(int iMode);
Descrition: The SetMode
function sets the reception mode of the radio device.
Parameters
iMode
: Specifies the reception mode to set the device to. Use one of these constants:
RMD_CW, RMD_AM, RMD_FMN, RMD_FMW, RMD_LSB, RMD_USB, RMD_FMM
Return Value: If the function succeeds, the return value is TRUE
. If the function fails, the return value is FALSE
.
Remarks: To set a mode, a RMD_xxx
mode must be specified and ORed with an optional RBW_xxx
bandwidth value. If the bandwidth is not specified it will default to the bandwidth used for the mode. The constant is an approximate bandwidth indication, calling GetModeString
will return the actual bandwidth.
The number of modes that the device supports is specified by the iNumModes
field of the RADIOINFO
structure that can be obtained from the GetRadioDeviceInfo
function. The actual modes supported can be read from the lpSupportedModes
array, the number of elements specified by iNumModes
. The array specifies both the mode and bandwidths.
BOOL GetScanMode();
Description: Get scan mode of radio.
Return Value: Returns TRUE
if the receiver has been set to scan mode, otherwise returns FALSE
if not.
BOOL SetScanMode(BOOL bScan);
Description: The SetScanMode
function controls the signal strength response of the radio receiver to a change in frequency.
Parameters
bScan
: TRUE
to enable scan mode, FALSE
to disable it.
Return Value: If the function succeeds, the return value is TRUE
, otherwise the return value is FALSE
.
Remarks: If the scan mode is enabled, the value returned from GetSignalStrength
may be less accurate but will respond to a change in frequency a lot quicker.
The iMaxAMScanRate
and iMaxFMScanRate
fields of the RADIOINFO
structure specify how fast the radio can scan in either mode in the number of stations per second. So a delay of 1000/iMaxXXScanRate milliseconds should be inserted between a call to SetFrequency
and GetSignalStrength
while scanning.
BOOL GetAttenuator();
Description: The GetAttenuator
function returns the RF input attenuator setting.
Return Value: GetAttenuator
returns TRUE
if the RF attenuator is on, otherwise it returns FALSE
if it is off.
BOOL SetAttenuator(BOOL bAtten=TRUE);
Description: The SetAttenuator
function activates or deactivates the RF input attenuator. It is used to prevent overloading of the receiver with strong signals.
Parameters
bAtten
: If TRUE
, the RF attenuator is on, otherwise if FALSE
, the RF attenuator is off (more sensitive).
Return Value: If the function succeeds, the return value is TRUE
. If the function fails, the return value is FALSE
.
int GetVolume();
Description: The GetVolume
function returns the audio output volume of the radio device.
Return Value: The current audio output volume if successful, otherwise, -1 is returned
BOOL SetVolume(int iVolume);
Description: The SetVolume
function sets the audio output volume level.
Parameters
iVolume
: Specifies the output audio volume from the receiver.
Return Value: If the function succeeds, the return value is TRUE
. If the function fails, the return value is FALSE
.
Remarks: The highest volume level is specified in the iMaxVolume
field of the RADIOINFO
structure that can be retrieved with the GetRadioDeviceInfo
function. No audio will be heard while the mute is on.
DWORD GetFrequency();
Description: The GetFrequency
function retrieves the frequency the receiver is tuned to.
Return Value: The current receiver frequency in Hz.
BOOL SetFrequency(DWORD dwFreq);
Description: The SetFrequency
function sets the frequency the device is to be tuned to.
Parameters
dwFreq
: Specifies the frequency to tune to receiver to. The first 31 bits is used to specify the frequency in Hz from 0 to 2.147 GHz. If bit 31 is set (MSB), the value in the first 31 bits is multiplied by ten, allowing the tunable frequency range to be from 0 to 21.47 GHz with a minimum resolution of 10 Hz.
Return Value: If the function succeeds, the return value is TRUE
. If the function fails, the return value is FALSE
.
Remarks: The lower and upper limits are specified in the dwMinFreq
and dwMaxFreq
fields respectively in the RADIOINFO
structure that can be retrieved with the GetRadioDeviceInfo
function.
DWORD GetSignalStrength();
Description: The GetSignalStrength
function returns the strength of the radio signal received by the radio device.
Return Value: The low order word ranges from 0 (very weak signal) to 120 (very strong signal). This is the value used by WiNRADiO, and is approximately equal to the signal strength in dB relative to the noise floor of the receiver. The high order word is reserved for future use and should be masked out.
int GetRadioDeviceInfo(LPRADIOINFO lpInfo);
Description: The GetRadioDeviceInfo
function retrieves hardware information about a radio device.
Parameters
lpInfo
: Address to a RADIOINFO
structure that will be filled with the capabilities and other information about the radio device. This can be NULL
.
Return Value: Bit field containing the current status of the controller on the radio device (unspecified bits are reserved):
Bit Function
0 IBF: High if Read-MCU port is full
1 OBF: High if Write-MCU port is full
2 -XLD: Inverse of LD (Lock Detect) signal from radio card
5 -DSPPPRES: Low if DSP option is present
7 MCUSTAT: Low when MCU is idling (waiting for a command), high if busy or in the process of transferring data to/from PC.
Sample usage
Using this class is very simple. First include WiNRADiO.h header file then declare a member variable with variable type CWiNRADiO
. Below is an example for it:
CWiNRADiO m_Radio;
m_Radio.OpenRadioDevice(1);
m_Radio.SetPower(TRUE);
m_Radio.SetMute(FALSE);
m_Radio.SetMode(RMD_FMW);
m_Radio.SetFrequency(104700000);
if (m_Radio.GetSignalStrength() < 70)
{
m_Radio.SetFrequency(102600000);
}
m_Radio.CloseRadioDevice();
Enjoy!