Click here to Skip to main content
15,908,906 members
Articles / Desktop Programming / MFC
Article

Add Radio support to your desktop

Rate me:
Please Sign up or sign in to vote.
4.94/5 (20 votes)
25 Jan 20038 min read 146.7K   1.8K   35   39
Use WiNRADiO card to add radio support to your desktop computer

Sample Image - WiNRADiO.jpg

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.

WiNRADiO 1500 series ISA 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); //Open 1st Radio Device
m_Radio.SetPower(TRUE); //Turn on Radio
m_Radio.SetMute(FALSE);
m_Radio.SetMode(RMD_FMW); //Wide FM
m_Radio.SetFrequency(104700000); //104.7 MHz 

if (m_Radio.GetSignalStrength() < 70)    //Level of Singal is low
{
    m_Radio.SetFrequency(102600000); //102.6 MHz
}

m_Radio.CloseRadioDevice(); //Close

Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
CEO Solaris Electronics LLC
United Arab Emirates United Arab Emirates
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from Iran University of Science & Technology in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acquisition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competition, my articles are:


You can see list of my articles, by clicking here


Comments and Discussions

 
AnswerRe: Problems regarding WinRadio Pin
marius_romanus14-Aug-06 12:30
marius_romanus14-Aug-06 12:30 
Hi t4urean

Instead of discussing via private email I would prefer discussing this topic here on the board, as there is very little about the WiNRADIO api on the net, and so anyone interested in the api could also find some pieces of information. (Never mind the different alias marius_romanus. It's still me. Have two aliases so I can get the newsletter and stuff automatically at work AND at home Smile | :) ).

>second thing is regarding the listening to the radio. In G303e there is only 1 function for >codec streaming it gives IF signal centred @ 12kHz freq... as PCM data.... (I am not sure >whether it is audio or not )

No! Very basically speaking the tuned signal is downconverted to some "fixed" frequency. This frequency is the IF (Intermediate Frequency). Thus, the IF signal that is delivered to your callback is the raw signal received by the radio. To get the required audio Signal you have to demodulate this signal with respect to the mode the Signal represents. AM, USB, LSB, etc... There are various descriptions of demodulation algorithms on the web.

The WiNRADiO Digital Bridge™ Virtual Sound Card will be of no use for your project. It is intended for the WiNRADIO control software as an alternative output for audio or IF data. So, you do not need a second soundcard but can connect to the virtual soundcard from any application as if it were a real soundcard. (But only if the radio control program that is delivered by WiNRADIO is used).

Now for the api wrapper. As I said, it is nearly complete, but it is COMPLETELY UNTESTED, and furthermore it is for the G313e api ! But it might give you some ideas.

The prototype for the G313e callback is:
public delegate void streamingCallBack([In]IntPtr targetHandle,[In]IntPtr buffer, uint bufSize, uint samplingRate);

The api wrap to set up the G313e streams is this one:
[DllImport("wrg3130api.dll")] private static extern int SetupStreams(int hRadio,streamingCallBack iFHandler,IntPtr iFT, streamingCallBack aSHandler, IntPtr aST);

And the Method with which one can actually set up the streams from the application via the wrapper is:
public bool wrSetupStreams(int hRadio, streamingCallBack iCB, object ifStreamWriter, streamingCallBack aCB, object audioStreamWriter)

Here is the complete wrapper. Good luck and have fun ! Smile | :)


using System;
using System.Runtime.InteropServices;

/*
* This is the Interface to the Radio G313e hardware driver dll that is available only in unmanaged code. It is based on the
* C interfaces given in the WiNRADIO api documentation.
*
*/
namespace HardwareController
{
#region The radio modes
// These are the radio modes that can be used with the Method SetMode.Given by WiNRADIO in repply to a request.
public enum RadioModes {CW=0, AM, FMN, FMW, LSB, USB, FMM, FSK, SAM, DAB, FM3, FM6, AMN, DSB, ISB, DRM=128, None, NumberOfDemodulators};
#endregion

#region The structure definitions given in the WiNRADIO api documentation.

// The OLD_RADIO_INFO structure as given in the api documentation.

[ StructLayout( LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi )]
public struct OLD_RADIO_INFO
{
public int bLength; // Specifies the size of the structure, in bytes; it must be filled before calling G3GetInfo

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=9 )]
public char[] szSerNum; // 8 characters long serial number ended by zero - this string may be directly passed to the G3Open function.

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=9 )]
public char[] szProdName; // 8 characters long product name ended by zero

public uint dwMinFreq; // Minimum frequency supported by the receiver
public uint dwMaxFreq; // Maximum frequency supported by the receiver
public byte bNumBands; // Number of band filters on RF input of the receiver; also, number of valid entries in dwBandFreq array

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=16 )]
public uint[] dwBandFreq; // Crossover frequencies between band filters
public uint dwLOfreq; // Local oscillator offset
public byte bNumVcos; // Number of VCOs on PLL board; also, number of valid entries in dwVcoFreq, wVcoDiv and bVcoBits arrays

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=8 )]
public uint[] dwVcoFreq; // Highest frequency for each VCO

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=8 )]
public ushort[] wVcoDiv; // VCO dividers

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=8 )]
public byte[] bVcoBits; // VCO select bits
public uint dwRefClk1; // Reference Clock1 frequency [Hz]
public uint dwRefClk2; // Reference Clock2 frequency [Hz], 0 if not fitted

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=8 )]
public byte[] IF1DAC; // DACs on IF1 module

public void allocateArrays()
{
this.szSerNum=new char[9];
this.szProdName=new char[9];
this.dwBandFreq=new uint[16];
this.dwVcoFreq=new uint[8];
this.wVcoDiv=new ushort[8];
this.bVcoBits=new byte[8];
this.IF1DAC=new byte[8];
}
}


// The RADIO_INFO structure as given in the api documentation

[ StructLayout( LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi )]
public struct RADIO_INFO
{
public int bLength; // Specifies the size of the structure, in bytes; it must be filled before calling G3GetInfo

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=9 )]
public char[] szSerNum; // 8 characters long serial number ended by zero - this string may be directly passed to the G3Open function.

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=9 )]
public char[] szProdName; // 8 characters long product name ended by zero
public uint dwMinFreq; // Minimum frequency supported by the receiver
public uint dwMaxFreq; // Maximum freuqnecy supported by the receiver
public byte bNumBands; // Number of band filters on RF input of the receiver; also, number of valid entries in dwBandFreq array

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=16 )]
public uint[] dwBandFreq; // Crossover frequencies between band filters

public uint dwLOfreq; // Local oscillator offset
public byte bNumVcos; // Number of VCOs on PLL board; also, number of valid entries in dwVcoFreq, wVcoDiv and bVcoBits arrays

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=8 )]
public uint[] dwVcoFreq; // Highest frequency for each VCO

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=8 )]
public ushort[] wVcoDiv; // VCO dividers

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=8 )]
public byte[] bVcoBits; // VCO select bits

public uint dwRefClk1; // Reference Clock1 frequency [Hz]
public uint dwRefClk2; // Reference Clock2 frequency [Hz], 0 if not fitted

[ MarshalAs( UnmanagedType.ByValArray, SizeConst=8 )]
public byte[] IF1DAC; // DACs on IF1 module
public int iAGCstart; // Raw AGC level at low power (-97dBm)
public int iAGCmid; // Raw AGC value 5dB above AGC start
public int iAGCend; // raw AGC value at -30dBm
public int iDropLevel; // The level where AGC starts *10dBm
public int iRSSItop; // The level where raw RSSI value is 0x03FF *10dBm
public int iRSSIref; // Raw RSSI value at -97dBm

public void allocateArrays()
{
this.szSerNum=new char[9];
this.szProdName=new char[9];
this.dwBandFreq=new uint[16];
this.dwVcoFreq=new uint[8];
this.wVcoDiv=new ushort[8];
this.bVcoBits=new byte[8];
this.IF1DAC=new byte[8];
}
}


// The SOFT_AGC structure as given in the api documentation.

[ StructLayout( LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi )]
public struct SOFTAGC_DATA
{
public int bLength; // Length of structure in bytes
public int iRefLevel; // AGC reference level in dB
public uint dwAttackTime; // AGC attack time in ms
public uint dwDecayTime; // AGC decay time in ms
};

#endregion

// The streaming callback "prototypes" for the audio and intermediate frequency data delivery callbacks.
// Target is a GC - Handle to the object to which the data should be written. Via the handle the Object can be retrieved
// in the corresponding C# callback.
public delegate void streamingCallBack([In]IntPtr targetHandle,[In]IntPtr buffer, uint bufSize, uint samplingRate);

///
/// This class encapsulates the WiNRADIO api for the WR-G313i and WR-G313e receivers.
/// Written by Roland Wöhry 2006
///

public class WinradioInterface
{
// All the managed prototypes for the unmanaged winradio api functions. (For description of functions see the WiNRADIO
// api documentation for the WiNRADIO WR-G313i and WR-G313e receivers).
[DllImport("wrg3130api.dll")] private static extern int SetupStreams(int hRadio,streamingCallBack iFHandler,IntPtr iFT, streamingCallBack aSHandler, IntPtr aST);
[DllImport("wrg3130api.dll")] private static extern int G3Open([MarshalAs(UnmanagedType.LPStr)] string ID);
[DllImport("wrg3130api.dll")] private static extern int OpenRadioDevice(int deviceNum);
[DllImport("wrg3130api.dll")] private static extern int CloseRadioDevice(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int G3GetRadioList([In,Out] OLD_RADIO_INFO[] radioInfos, int bufferSize);
// G3GetRadioList2 --> Not yet implemented
[DllImport("wrg3130api.dll")] private static extern int GetSignalStrengthdBm(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetRawSignalStrength(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int G3GetLastSSdBm(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int G3GetLastRawSS(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint G3GetInternalRSSI(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int SetFrequency(int hRadio, uint dwFreq);
[DllImport("wrg3130api.dll")] private static extern int G3SetFreqAsync(int hRadio, uint dwFreq);
[DllImport("wrg3130api.dll")] private static extern int G3WaitFreqAsync(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int SetIF2Frequency(int hRadio, int iFreq);
[DllImport("wrg3130api.dll")] private static extern int SetAtten(int hRadio, int fAtten);
[DllImport("wrg3130api.dll")] private static extern int SetPower(int hRadio, int fPower);
[DllImport("wrg3130api.dll")] private static extern int SetAGC(int hRadio, int iAGC);
[DllImport("wrg3130api.dll")] private static extern int SetIFGain(int hRadio, int iIFGain);
[DllImport("wrg3130api.dll")] private static extern int G3SetRefClock(int hRadio, uint RefClock);
[DllImport("wrg3130api.dll")] private static extern uint GetFrequency(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetIF2Frequency(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetAtten(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetPower(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetAGC(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetIFGain(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint G3GetLock(int hRadio, int GetType);
[DllImport("wrg3130api.dll")] private static extern uint G3GetRefClock(int hRadio);
// The following methods are not implemented because they will not be used by the system. The system will implement
// it's own mode of block scanning.
// G3BlockScan --> Not yet implemented
// G3StopBlockScan --> Not yet implemented
// G3PauseBlockScan --> Not yet implemented
// G3ResumeBlockScan --> Not yet implemented
[DllImport("wrg3130api.dll")] private static extern int G3GetInfo(int hRadio, ref RADIO_INFO info);
[DllImport("wrg3130api.dll")] private static extern int G3IsBusy(int hRadio);
// G3GetPath --> Not yet implemented
// G3GetPath2 --> Not yet implemented
[DllImport("wrg3130api.dll")] private static extern int IsDeviceConnected(int hRadio);
// dsp commands are not used by the system, so the corresponding functions are not wrapped.
// dspOpen --> Not yet implemented
// dspClose --> Not yet implemented
// dspReset --> Not yet implemented
// dspBoot --> Not yet implemented
// dspRead --> Not yet implemented
// dspWrite --> Not yet implemented
[DllImport("wrg3130api.dll")] private static extern int SetAdvancedMode(int hRadio,int Advanced,[MarshalAs(UnmanagedType.LPStr)] string CalFilePath);
[DllImport("wrg3130api.dll")] private static extern int SetNotchFilter(int hRadio,int Active,int Freq,uint BW);
[DllImport("wrg3130api.dll")] private static extern int SetNoiseBlanker(int hRadio,int Active,uint Thres);
[DllImport("wrg3130api.dll")] private static extern int SetIFShift(int hRadio,int Shift);
[DllImport("wrg3130api.dll")] private static extern int SetIFBandwidth(int hRadio,uint BW);
[DllImport("wrg3130api.dll")] private static extern int SetPassbandOffset(int hRadio,int PBO);
[DllImport("wrg3130api.dll")] private static extern int SetSoftAGC(int hRadio,ref SOFTAGC_DATA Data);
[DllImport("wrg3130api.dll")] private static extern int SetMode(int hRadio,int Mode);
// Important Should be set together with the IF-Bandwidth.
[DllImport("wrg3130api.dll")] private static extern int SetAudioBandwidth(int hRadio,uint BW);
// Should be set with no AGC
[DllImport("wrg3130api.dll")] private static extern int SetAudioGain(int hRadio,uint Gain);
[DllImport("wrg3130api.dll")] private static extern int SetVolume(int hRadio,uint Volume);
[DllImport("wrg3130api.dll")] private static extern int SetFMAFSquelchLevel(int hRadio,uint Level);
[DllImport("wrg3130api.dll")] private static extern int SetISBAudioChannel(int hRadio,uint Channel);
[DllImport("wrg3130api.dll")] private static extern int SetCWTone(int hRadio,uint Freq);
[DllImport("wrg3130api.dll")] private static extern int GetAdvancedMode(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetNotchFilter(int hRadio,ref int Freq,ref uint BW);
[DllImport("wrg3130api.dll")] private static extern int GetNoiseBlanker(int hRadio,ref uint Thres);
[DllImport("wrg3130api.dll")] private static extern int GetIFShift(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetIFBandwidth(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetPassbandOffset(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetSoftAGC(int hRadio,ref SOFTAGC_DATA Data);
[DllImport("wrg3130api.dll")] private static extern int GetMode(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint GetAudioBandwidth(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint GetAudioGain(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint GetVolume(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint GetFMAFSquelchLevel(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint GetISBAudioChannel(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint GetCWTone(int hRadio);
[DllImport("wrg3130api.dll")] private static extern int GetTuneError(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint GetFrequencyDeviation(int hRadio);
[DllImport("wrg3130api.dll")] private static extern uint GetAMDepth(int hRadio);


// The callback handles for the data given to the if and audio streams. In the callbacks they can be converted into
// the corresponding Objects again. Garbage Collector isn't an issue here as the objects are tunneled through the
// unmanaged code by means of these handles.
GCHandle audioStreamTargetHandle; // The handle to the audio stream target object used in the callback.
GCHandle ifStreamTargetHandle; // The handle to the if stream target object used in the callback.


// This is the only instance of this radio interface in the system.
private static WinradioInterface onlyInstance=null;

// The RadioInterface singleton access
public static WinradioInterface Instance{get{if(onlyInstance==null)onlyInstance=new WinradioInterface(); return onlyInstance;}}

#region The wrapper methods to the WiNRADIO interface

// Function for getting the AM depth for the current transmission. The 0..1 range normal for
// this parameter is returned scaled to 0..1000
public uint wrGetAMDepth(int hRadio)
{
return GetAMDepth(hRadio);
}

// Function for getting the frequency deviation (in Hz) of the currently received transmission.
public uint wrGetFrequencyDeviation(int hRadio)
{
return GetFrequencyDeviation(hRadio);
}

// Function for getting the tuning error while in advanced mode. The resulting value is valid only if the receiver is tuned
// to a transmissions. The returned value must be substracted from the frequency to which the receiver is currently tuned.
public int wrGetTuneError(int hRadio)
{
return GetTuneError(hRadio);
}

// Function for getting the CW tone frequency.
public uint wrGetCWTone(int hRadio)
{
return GetCWTone(hRadio);
}

// Function for getting the currently selected ISB audio channel.
public uint wrGetISBAudioChannel(int hRadio)
{
return GetISBAudioChannel(hRadio);
}

// Function for getting the current FM AF squelch level.
public uint wrGetFMAFSquelchLevel(int hRadio)
{
return GetFMAFSquelchLevel(hRadio);
}

// Function for getting the current audition volume.
public uint wrGetVolume(int hRadio)
{
return GetVolume(hRadio);
}

// Function for getting the current fixed audio gain.
public uint wrGetAudioGain(int hRadio)
{
return GetAudioGain(hRadio);
}

// Function for getting the current audio bandwidth.
public uint wrGetAudioBandwidth(int hRadio)
{
return GetAudioBandwidth(hRadio);
}

// Function for getting the current demodulation mode.
public RadioModes wrGetMode(int hRadio)
{
return (RadioModes)GetMode(hRadio);
}

// Function for retrieving the software AGC parameters.
public bool wrGetSoftAGC(int hRadio,ref SOFTAGC_DATA Data)
{
return intToBool(GetSoftAGC(hRadio, ref Data));
}

// Function for retrieving the pass-band offset value.
public int wrGetPassbandOffset(int hRadio)
{
return GetPassbandOffset(hRadio);
}

// Function for retrieving the IF bandwidth value.
public int wrGetIFBandwidth(int hRadio)
{
return GetIFBandwidth(hRadio);
}

// Function for retrieving the IF shift value
public int wrGetIFShift(int hRadio)
{
return GetIFShift(hRadio);
}

// Function for retrieving the noise blanker settings.
public bool wrGetNoiseBlanker(int hRadio,ref uint Thres)
{
return intToBool(GetNoiseBlanker(hRadio, ref Thres));
}

// Function for retrieving the IF notch filter settings.
public bool wrGetNotchFilter(int hRadio,ref int Freq,ref uint BW)
{
return intToBool(GetNotchFilter(hRadio, ref Freq, ref BW));
}

// Function checking the current status of the advanced mode.
public bool wrGetAdvancedMode(int hRadio)
{
return intToBool(GetAdvancedMode(hRadio));
}

// Function for setting the frequency of the audible tone when receving CW transmissions.
public bool wrSetCWTone(int hRadio,uint Freq)
{
return intToBool(SetCWTone(hRadio, Freq));
}

// Function for specifying the audio channel that should be sent to the audio output when demodulating ISB transmissions.
// 0 stands for Left (LSB) and 1 for Right (USB).
public bool wrSetISBAudioChannel(int hRadio,uint Channel)
{
return intToBool(SetISBAudioChannel(hRadio, Channel));
}

// Function for setting the AF squelch while demodulating FM transmissions. The level corresponds to the minimum noise
// level that will mute the audio output. By specifying a value of 0 the AF squelch is disabled.
public bool wrSetFMAFSquelchLevel(int hRadio,uint Level)
{
return intToBool(SetFMAFSquelchLevel(hRadio, Level));
}

// Function for setting the audition volume. It can be any value between 0 and 31.
public bool wrSetVolume(int hRadio,uint Volume)
{
return intToBool(SetVolume(hRadio, Volume));
}

// Function for setting the fixed audio gain. This value is used to provide a fixed audio amplification when the
// software AGC is disabled.
public bool wrSetAudioGain(int hRadio,uint Gain)
{
return intToBool(SetAudioGain(hRadio, Gain));
}

// Function for setting the final audio bandwidth. For linear modulation types it should be equal to IF bandwidth (LSB, USB)
// or half the IF bandwidth (AM, AMS, DSB, ISB). For exponential modulations (FM) it is transmission dependant. For CW
// there is a special condition as the audio bandwidth should be the minimum between half IF bandwidth and the CW tone
// frequency.
public bool wrSetAudioBandwidth(int hRadio,uint BW)
{
return intToBool(SetAudioBandwidth(hRadio, BW));
}

// Function for selecting the desired demodulation mode. All demodulation modes available in the G313 demodulator
// can be selected here.
public bool wrSetMode(int hRadio,RadioModes Mode)
{
return intToBool(SetMode(hRadio, (int)Mode));
}

// Function for setting the desired AGC behaviour. The AGC is active for as long as the reference level is below 0. The
// attack and decay times are automatically set to 1 if the values passed to the API are 0.
public bool wrSetSoftAGC(int hRadio,ref SOFTAGC_DATA Data)
{
Data.bLength=Marshal.SizeOf(Data);
return intToBool(SetSoftAGC(hRadio, ref Data));
}

// Function for setting the pass-band offset value. Normally it is 0. Accepted values are from -8kHz...+8kHz. It controls
// the amount that the spectrum is shifted before actual demodulation.
public bool wrSetPassbandOffset(int hRadio,int PBO)
{
return intToBool(SetPassbandOffset(hRadio, PBO));
}


// Function for setting the IF bandwidth. Values in the 1Hz...15kHz range are accepted. Through this API call the filters
//that come after the I and Q multipliers are controlled.
public bool wrSetIFBandwidth(int hRadio,uint BW)
{
return intToBool(SetIFBandwidth(hRadio, BW));
}

// Function for setting the IF shift. The specified value is added to the IF2 frequency and provides the actual receiving
// frequency. The resulting value must not exceed the IF hardware filter bandwidth (15kHz for G313), thus the accepted
// values are in the range -7500...+7500.
public bool wrSetIFShift(int hRadio,int Shift)
{
return intToBool(SetIFShift(hRadio, Shift));
}

// Function for configuring the noise blanker. The treshold is given as percentage of the maximum acceptable input signal.
public bool wrSetNoiseBlanker(int hRadio,bool Active,uint Thres)
{
return intToBool(SetNoiseBlanker(hRadio, boolToInt(Active), Thres));
}

// Function for configuring the IF notch filter. The frequency is specified relatively to the IF frequency and is limited to
// the IF hardware filter bandwidth, meaning from -7500 to +7500.
public bool wrSetNotchFilter(int hRadio,bool Active,int Freq,uint BW)
{
return intToBool(SetNotchFilter(hRadio, boolToInt(Active), Freq, BW));
}

// Function for entering/leaving advanced mode. The advanced mode must be activated before any other advanced mode
// function. When the advanced mode is nolonger needed it should be disabled. When activating the advanced mode the
// full path to a calibration data file may be provided if signal strength measurement must be calibrated. If not so,
// the passed pointer should be NULL.
public bool wrSetAdvancedMode(int hRadio,bool Advanced,string CalFilePath)
{
return intToBool(SetAdvancedMode(hRadio, boolToInt(Advanced), CalFilePath));
}

// Checks if the receiver is still connected to the computer. It is significant only for external receivers while the internal ones will always be reported as connected.
public bool wrIsDeviceConnected(int hRadio)
{
return intToBool(IsDeviceConnected(hRadio));
}

// Checks the receiver whether it is ready to accept commands.
public bool wrG3IsBusy(int hRadio)
{
return intToBool(G3IsBusy(hRadio));
}

// Retrieves the RADIO_INFO structure of the receiver.
public bool wrG3GetInfo(int hRadio, ref RADIO_INFO info)
{
info.bLength=Marshal.SizeOf(info);

return intToBool(G3GetInfo(hRadio,ref info));
}

// Retrieves the current reference clock frequency.
public uint wrG3GetRefClock(int hRadio)
{
return G3GetRefClock(hRadio);
}

// Retrieves the PLLs lock status.
public uint wrG3GetLock(int hRadio, int GetType)
{
return G3GetLock(hRadio, GetType);
}

// Retrieves the IFGain value of the receiver.
public int wrGetIFGain(int hRadio)
{
return GetIFGain(hRadio);
}

// The GetAGC function returns current AGC value of radio device.
public int wrGetAGC(int hRadio)
{
return GetAGC(hRadio);
}

// The GetPower function returns whether the receiver's power is on or off.
public bool wrGetPower(int hRadio)
{
return intToBool(GetPower(hRadio));
}

// The GetAtten function returns the RF input attenuator setting.
public bool wrGetAtten(int hRadio)
{
return intToBool(GetAtten(hRadio));
}

// The GetIF2Frequency function retrieves the current IF2 frequency.
public int wrGetIF2Frequency(int hRadio)
{
return GetIF2Frequency(hRadio);
}

// The GetFrequency function retrieves the frequency the receiver is tuned to.
public uint wrGetFrequency(int hRadio)
{
return GetFrequency(hRadio);
}

// Specifies the reference clock frequency and allows switching between internal and external references.
public bool wrG3SetRefClock(int hRadio, uint RefClock)
{
return intToBool(G3SetRefClock(hRadio, RefClock));
}

// Sets IFGain value for the specified receiver.
public bool wrSetIFGain(int hRadio, int iIFGain)
{
return intToBool(SetIFGain(hRadio, iIFGain));
}

// The SetAGC function sets the AGC value for given receiver.
public bool wrSetAGC(int hRadio, int iAGC)
{
return intToBool(SetAGC(hRadio, iAGC));
}

// The SetPower function switches the device's power on or off. This function can be used to power down the receiver
// in portable applications to conserve battery power.
public bool wrSetPower(int hRadio, bool fPower)
{
return intToBool(SetPower(hRadio, boolToInt(fPower)));
}

// The SetAtten function activates or deactivates the RF input attenuator. It is used to prevent overloading of the
// receiver with strong signals.
public bool wrSetAtten(int hRadio, bool fAtten)
{
return intToBool(SetAtten(hRadio, boolToInt(fAtten)));
}

// The SetIF2Frequency function sets the center frequency of the last IF signal.
public bool wrSetIF2Frequency(int hRadio, int iFreq)
{
return intToBool(SetIF2Frequency(hRadio, iFreq));
}

// The G3WaitFreqAsync function waits for the end of a receiver tunning started by a G3SetFreqAsync call.
public bool wrG3WaitFreqAsync(int hRadio)
{
return intToBool(G3WaitFreqAsync(hRadio));
}

//The G3SetFreqAsync function starts the sequence of hardware commands that sets the frequency the device is to be
// tuned to. In order to insure the sequence has been executed and that the hardware is properly tuned,
// G3WaitFreqAsync function must be called.
public bool wrG3SetFreqAsync(int hRadio, uint dwFreq)
{
return intToBool(G3SetFreqAsync(hRadio,dwFreq));
}

// The SetFrequency function sets the frequency the device is to be tuned to.
public bool wrSetFrequency(int hRadio, uint dwFreq)
{
return intToBool(SetFrequency(hRadio, dwFreq));
}

// The G3GetInternalRSSI function returns a combination of the RSSI and AGC values read from the receiver hardware.
public uint wrG3GetInternalRSSI(int hRadio)
{
return G3GetInternalRSSI(hRadio);
}

// The G3GetLastRawSS function returns last measured RAW signal strength value. Useful during block scanning.
public int wrG3GetLastRawSS(int hRadio)
{
return G3GetLastRawSS(hRadio);
}

// The G3GetLastSSdBm function returns the last measured strength of the radio signal in dBm. Useful during block scanning.
public int wrG3GetLastSSdBm(int hRadio)
{
return G3GetLastSSdBm(hRadio);
}

// The GetRawSignalStrength function returns the "raw" signal strength value. This is made available for compatibility with applications which expect the signal strength value to be from 0 (min signal level) to 255 (max signal level). The formula for this is:
// SignalStrength_RAW = 255*(SignalStrength_dBm + 1300)/1000
// This means that -130dBm corresponds to 0 and -30dBm corresponds to 255 of "raw" value.
public int wrGetRadSignalStrength(int hRadio)
{
return GetRawSignalStrength(hRadio);
}

// The GetSignalStrengthdBm function returns the strength of the radio signal in dBm received by the radio device.
public int wrGetSignalStrengthdBm(int hRadio)
{
return GetSignalStrengthdBm(hRadio);
}

// The G3GetRadioList function returns information about all G313 devices that can be opened.
// Do not allocate the arrays within the structs yourself. G3GetRadioList will do the allocation.
public int wrG3GetRadioList(OLD_RADIO_INFO[] radioInfos)
{
int ret=0;

if(radioInfos!=null)
{
for(int i=0; i
QuestionRe: Problems regarding WinRadio [modified] Pin
t4ure4n15-Aug-06 1:04
t4ure4n15-Aug-06 1:04 
AnswerRe: Problems regarding WinRadio Pin
marius_romanus15-Aug-06 2:33
marius_romanus15-Aug-06 2:33 
QuestionRe: Problems regarding WinRadio Pin
t4ure4n16-Aug-06 11:09
t4ure4n16-Aug-06 11:09 
AnswerRe: Problems regarding WinRadio Pin
marius_romanus17-Aug-06 11:15
marius_romanus17-Aug-06 11:15 
AnswerRe: Problems regarding WinRadio Pin
t4ure4n18-Aug-06 0:30
t4ure4n18-Aug-06 0:30 
QuestionAbout WinRadio API Pin
t4ure4n4-Apr-06 5:26
t4ure4n4-Apr-06 5:26 
AnswerRe: About WinRadio API Pin
Abbas_Riazi4-Apr-06 7:00
professionalAbbas_Riazi4-Apr-06 7:00 
QuestionWinradio WR1550i Pin
t4ure4n8-Mar-06 1:23
t4ure4n8-Mar-06 1:23 
AnswerRe: Winradio WR1550i Pin
Abbas_Riazi8-Mar-06 23:02
professionalAbbas_Riazi8-Mar-06 23:02 
Generalmeeting with you Pin
niamanesh1-May-04 21:19
niamanesh1-May-04 21:19 
GeneralAdd extra functionality Pin
Abbas Riazi29-Jan-03 2:14
Abbas Riazi29-Jan-03 2:14 
GeneralRe: Add extra functionality Pin
bkerr2-Mar-09 16:05
bkerr2-Mar-09 16:05 
GeneralTrunk Radio Pin
Abbas Riazi27-Jan-03 8:37
Abbas Riazi27-Jan-03 8:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.