コード例 #1
0
        public void StartCommunication(bool force = false)
        {
            if (Device != null)
            {
                if (Device.IsConnected)
                {
                    if (!Device.IsOpen || force)
                    {
                        Device.OpenDevice();
                        DeviceOpened?.Invoke();
                        Device.ReadReport(OnReport);
                    }
                }
            }
            else
            {
                if (HidDevices.IsConnected(devicePath))
                {
                    Device = HidDevices.GetDevice(devicePath);

                    if (!Device.IsOpen || force)
                    {
                        Device.OpenDevice();
                        DeviceOpened?.Invoke();
                        Device.ReadReport(OnReport);
                    }
                }
                else
                {
                    Observable.Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1)).TakeUntil(stopSubject).Subscribe(
                        l =>
                    {
                        var dev = HidDevices.GetDevice(devicePath);

                        if (Device == null && dev != null)
                        {
                            Device = dev;
                        }

                        if (Device == null)
                        {
                            return;
                        }

                        Device.OpenDevice();
                        DeviceOpened?.Invoke();
                        Device.ReadReport(OnReport);
                        stopSubject.OnNext(Unit.Default);
                    });
                }
            }
        }
コード例 #2
0
        void SetupConnection(eConnType type, IPAddress addr, int port)
        {
            CloseConnection();

            switch (type)
            {
            case eConnType.UdpClient:
                Endpoint      = new IPEndPoint(addr, port);
                ReceiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                ReceiveSocket.Bind(Endpoint);
                ReceiveSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5);
                break;

            case eConnType.TcpClient:
                Endpoint      = new IPEndPoint(addr, port);
                ReceiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                ReceiveSocket.Connect(Endpoint);
                break;

            case eConnType.RtsaClient:
                RtsaIO = new RtsaHttpIO();
                RtsaIO.FrequencyChanged    += (s, e) => { _Frequency = (long)RtsaIO.Frequency; FrequencyChanged?.Invoke(this, null); };
                RtsaIO.SamplingRateChanged += (s, e) => { NetShmemSink.Rate = (long)RtsaIO.SamplingRate; };
                RtsaIO.ConnectInput(addr, port);

                _SampleSource.DataFormat = RtsaIO.SampleFormat;
                break;

            case eConnType.TcpServer:
                Endpoint     = new IPEndPoint(addr, port);
                ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                ServerSocket.Bind(Endpoint);
                ServerSocket.Listen(1);
                ServerSocket.BeginAccept(new AsyncCallback(AcceptConnection), ServerSocket);
                break;
            }

            ConnectionType = type;
            StopTransfers  = false;
            TransferThread = new Thread(TransferThreadMain);
            TransferThread.Start();

            DeviceOpened?.Invoke(this, EventArgs.Empty);
        }
コード例 #3
0
 public bool OpenTuner()
 {
     Show();
     DeviceOpened?.Invoke(this, EventArgs.Empty);
     return(true);
 }
コード例 #4
0
ファイル: HiQSDRDeviceControl.cs プロジェクト: g3gg0/rx-fft
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (HiQControl == null)
            {
                SetStatus(eStatus.Connecting);

                Thread t = new Thread(() =>
                {
                    IPAddress host;

                    try
                    {
                        if (!IPAddress.TryParse(txtHost.Text, out host))
                        {
                            host = Dns.GetHostEntry(txtHost.Text).AddressList[0];
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Exception: " + ex.Message);
                        SetStatus(eStatus.Ready);
                        return;
                    }

                    try
                    {
                        lock (this)
                        {
                            HiQControl = new HiQSDRControl(host);
                            HiQControl.StopTransfer();
                        }

                        if (HiQControl.FirmwareVersion < 0)
                        {
                            HiQControl.Close();
                            HiQControl = null;

                            MessageBox.Show("Device does not respond");
                            SetStatus(eStatus.Ready);
                            return;
                        }

                        SetStatus(eStatus.Connected);
                        DeviceOpened?.Invoke(this, EventArgs.Empty);

                        if (FrequencyChanged != null)
                        {
                            FrequencyChanged(this, null);
                        }
                        ;

                        if (SamplingRateChanged != null)
                        {
                            SamplingRateChanged(this, null);
                        }

                        BeginInvoke(new Action(() =>
                        {
                            radioAcqStream.Checked = true;
                        }));
                        StartStreamRead();
                    }
                    catch (Exception ex)
                    {
                        HiQControl.Close();
                        HiQControl = null;

                        MessageBox.Show("Exception: " + ex.Message);
                        SetStatus(eStatus.Ready);
                        return;
                    }
                });

                t.Start();
            }
            else
            {
                SetStatus(eStatus.Disconnecting);

                lock (this)
                {
                    HiQControl.Close();
                    HiQControl = null;
                }

                SetStatus(eStatus.Ready);
            }
        }
コード例 #5
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (Spectran == null)
            {
                SetStatus(eStatus.Connecting);

                Thread t = new Thread(() =>
                {
                    try
                    {
                        lock (this)
                        {
                            Spectran = new SpectranDevice();
                            Spectran.TryOpen();
                        }

                        SetStatus(eStatus.Connected);
                        DeviceOpened?.Invoke(this, EventArgs.Empty);

                        if (FrequencyChanged != null)
                        {
                            FrequencyChanged(this, null);
                        }
                        ;

                        if (SamplingRateChanged != null)
                        {
                            SamplingRateChanged(this, null);
                        }

                        BeginInvoke(new Action(() =>
                        {
                            radioAcqStream.Checked = true;
                        }));
                        StartStreamRead();
                    }
                    catch (Exception ex)
                    {
                        Spectran.Stop();
                        Spectran = null;

                        MessageBox.Show("Exception: " + ex.Message);
                        SetStatus(eStatus.Ready);
                        return;
                    }
                });

                t.Start();
            }
            else
            {
                SetStatus(eStatus.Disconnecting);

                lock (this)
                {
                    Spectran.Close();
                    Spectran = null;
                }

                SetStatus(eStatus.Ready);
            }
        }
コード例 #6
0
ファイル: USBRXDeviceControl.cs プロジェクト: g3gg0/rx-fft
        public virtual bool OpenTuner()
        {
            /* display the wait message */
#if false
            WaitDialog waitDlg = new WaitDialog();
            waitDlg.Show();
            waitDlg.Refresh();
#endif

            USBRX = new USBRXDevice();
            //USBRX.ShowConsole(true);
            USBRX.TunerCombination = TunerCombination;

            try
            {
                if (!USBRX.Init())
                {
                    ErrorMessage = "Could not find USB-RX on USB.";
#if false
                    waitDlg.Close();
#endif
                    base.Close();
                    return(false);
                }
            }
            catch (BadImageFormatException e)
            {
                ErrorMessage = "Unsupported architecture.";
#if false
                waitDlg.Close();
#endif
                base.Close();
                return(false);
            }
            catch (Exception e)
            {
                ErrorMessage = "Unhandled exception." + Environment.NewLine + e;
#if false
                waitDlg.Close();
#endif
                base.Close();
                return(false);
            }
            ErrorMessage = "";

            FilterList.NCOFreq = USBRX.Atmel.TCXOFreq;
            FilterList.UpdateFilters("Filter");
            FilterList.AddFilters("..\\..\\..\\Filter");
            FilterList.FilterSelected += new EventHandler(FilterList_FilterSelected);

            USBRX.Tuner.SamplingRateChanged     += new EventHandler(Tuner_FilterRateChanged);
            USBRX.Tuner.FilterWidthChanged      += new EventHandler(Tuner_FilterWidthChanged);
            USBRX.Tuner.InvertedSpectrumChanged += new EventHandler(Tuner_InvertedSpectrumChanged);
            USBRX.Tuner.DeviceDisappeared       += new EventHandler(Tuner_DeviceDisappeared);

            frequencySelector1.UpperLimit = USBRX.Tuner.HighestFrequency;
            frequencySelector1.LowerLimit = USBRX.Tuner.LowestFrequency;
            CurrentFrequency = USBRX.Tuner.GetFrequency();
            SetFreqTextbox(CurrentFrequency);

            _SampleSource = new ShmemSampleSource("USB-RX Device Control", USBRX.ShmemChannel, 1, 0);
            _SampleSource.InvertedSpectrum = InvertedSpectrum;
            _SampleSource.DataFormat       = ByteUtil.eSampleFormat.Direct16BitIQFixedPointLE;

            ToolTip ttFreq = new ToolTip();
            ttFreq.SetToolTip(frequencySelector1, "Min Freq: " + FrequencyFormatter.FreqToStringAccurate(USBRX.Tuner.LowestFrequency) + Environment.NewLine + "Max Freq: " + FrequencyFormatter.FreqToStringAccurate(USBRX.Tuner.HighestFrequency));
            ttFreq.AutomaticDelay = 500;

            UpdateAtmelFilters();
            SelectFiles(true);

            Connected = true;

            /* small hack to select first (widest) filter */
            FilterList.FilterSelect(FilterList.FirstFilter);

            /* close wait dialog and show ours */
#if false
            waitDlg.Close();
#endif

            Show();

            radioAcqOff.Checked   = true;
            radioTunerInt.Checked = true;
            radioAgcOff.Checked   = true;
            chkAtt.Checked        = false;
            chkPreAmp.Checked     = false;

            radioTunerInt_CheckedChanged(null, null);
            chkAtt_CheckedChanged(null, null);
            chkPreAmp_CheckedChanged(null, null);
            radioAgcOff_CheckedChanged(null, null);

            radioAcqBlock.Checked = true;


            DeviceOpened?.Invoke(this, EventArgs.Empty);

            return(true);
        }