1

我正在尝试将旧的 RFSpace SDR-IQ 无线电集成到现有的 C# 程序中。SDR-IQ 信息: http ://www.rfspace.com/RFSPACE/SDR-IQ.html

SDR-IQ 通过 USB 连接到 PC。

我发现了一个非常旧的 ActiveX 控件,它成功地放到了 C# 对话框中(在手动注册 DLL 之后)。ActiveX 控件: http ://www.moetronix.com/files/sdr14xsdk127.zip

这是控件的 C# 元数据:

namespace AxSDR14XLib
{
    [DefaultEvent("StatusChange")]
    [DesignTimeVisible(true)]
    public class AxSDR14X : AxHost
    {
        public AxSDR14X();

        [DispId(12)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual short BootRevision { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(1)]
        public virtual int ClockFrequency { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(2)]
        public virtual string DeviceName { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(3)]
        public virtual int FirmwareRevision { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(4)]
        public virtual int HFgain { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(5)]
        public virtual int IFfilter { get; set; }
        [DispId(10)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual int IFgain { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(6)]
        public virtual int InputSource { get; set; }
        [DispId(7)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual int InterfaceVersion { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(13)]
        public virtual double IQOffset { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(8)]
        public virtual int NCOfrequency { get; set; }
        [DispId(11)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual int SampleRate { get; set; }
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [DispId(9)]
        public virtual string SerialNumber { get; set; }

        public event _DSDR14XEvents_DataRdyEventHandler DataRdy;
        public event _DSDR14XEvents_StatusChangeEventHandler StatusChange;
        public event EventHandler UartDataRdy;

        public virtual void AboutBox();
        protected override void AttachInterfaces();
        public virtual void CloseI2CPort();
        public virtual void CloseSpiPort();
        public virtual void CloseUartPort();
        protected override void CreateSink();
        protected override void DetachSink();
        public virtual int GetDoubleData(ref double dataArray);
        public virtual bool GetFftDoubleData(ref double dataArray);
        public virtual bool GetFftScreendata(int plotHeght, int plotWidth, double maxdB, double mindB, int startFreq, int endFreq, ref int plotBuf);
        public virtual int GetIntegerData(ref short dataArray);
        public virtual int GetLongData(ref int dataArray);
        public virtual short GetUartData(ref short uartRxArray);
        public virtual void InitControl();
        public virtual void OpenI2CPort(short adrWidth);
        public virtual void OpenSpiPort(short clkPolarity);
        public virtual void OpenUartPort(int baudRate, short parity, bool flowControl);
        public virtual void ResetFftAverage();
        public virtual void Send6620RawCmd(short address, short d0, short d1, short d2, short d3, short d4);
        public virtual void SendI2CData(ref short txDataArray, short numDataItems);
        public virtual void SendSpiData(int data32High, int data32Low, short numberBits);
        public virtual void SendUartData(ref short uartTxArray, short numDataItems);
        public virtual void SetupFFT(int fftPoints, short fftaverages, bool fftInverted);
        public virtual void Start(short blocks, short mode);
        public virtual void Stop();
    }

控件.InitControl().Start()方法正常工作。和事件也有效StatusChangeDataRdy因此,控制器与无线电成功通信。

当我尝试DataRdy通过.GetLongData().

尽管进行了数小时的谷歌搜索,但无论我尝试什么,我的代码都会因错误而崩溃:

程序“[9036] sdriq.vshost.exe: Managed (v4.0.30319)”已退出,代码为 -1073741819 (0xc0000005)。

Exception 对象中没有关于崩溃的更多详细信息。

这是一个调用.GetLongData()失败的例子:

private int[] m_SdrData = new int[40000];

private void axSDR14X1_DataRdy(object sender, AxSDR14XLib._DSDR14XEvents_DataRdyEvent e)
{
    unsafe
    {
        var unmanagedArray = (int*)Marshal.AllocHGlobal(m_SdrData.Length * sizeof(int));
        int samples = axSDR14X1.GetLongData(ref unmanagedArray[0]);
        for (int i = 0; i < m_SdrData.Length; i++) m_SdrData[i] = unmanagedArray[i];
        Marshal.FreeHGlobal((IntPtr)unmanagedArray);
    }
}

当我写到控件自述文件中的地址时,控件的原作者确实回复了:“是的,我之前写的 dll 是一个 activex dll,我认为 uSoft 不再允许传递内存指针。我不知道C#,但我怀疑它也不允许直接内存指针。”

因此,尽管没有明确说明,但我 99% 确信该控件是用 C++ 编写的。

从 C# 调用 C++ 时,我不是很精明。鉴于.GetLongData上面显示的签名,我正在寻找帮助以找到、 、 等的神奇组合unsafe,以将无线电数据从非托管 C++ ActiveX 控件获取到我的托管 C# 代码中。IntPtrMarshal.AllocHGlobal

非常感谢您的任何帮助。

4

0 回答 0