コード例 #1
0
ファイル: SkytraqController.cs プロジェクト: sayrun/Bayaki
        /// <summary>
        /// 自動のポート選択
        /// COMポートの一覧から順次ポートを開いて、Version情報を取得してみる
        /// </summary>
        /// <returns>ポート名称</returns>
        public static string AutoSelectPort()
        {
            SkytraqController port = null;

            foreach (string portName in System.IO.Ports.SerialPort.GetPortNames())
            {
                try
                {
                    port = new SkytraqController(portName, READ_TIMEOUT_INTERNAL, WRITE_TIMEOUT_INTERNAL);

                    return(portName);
                }
                catch
                {
                    continue;
                }
                finally
                {
                    if (null != port)
                    {
                        port.Dispose();
                        port = null;
                    }
                }
            }
            throw new InvalidOperationException("利用できるComPortがない");
        }
コード例 #2
0
        private void _erase_Click(object sender, EventArgs e)
        {
            if (DialogResult.OK != MessageBox.Show(Properties.Resources.MSG5, this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
            {
                // 実行を中止しますよ
                return;
            }

            UseWaitCursor = true;
            NowProcessing = false;

            _progress.Value = 0;

            string portName = this.PortName;

            if (Properties.Resources.PORT_AUTOSEL == portName)
            {
                try
                {
                    portName      = SkytraqController.AutoSelectPort();
                    this.PortName = portName;
                }
                catch
                {
                    _posrts.Items.Remove(portName);
                    MessageBox.Show(Properties.Resources.MSG1, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
            _eraseWorker.RunWorkerAsync(portName);

            _timer.Start();
        }
コード例 #3
0
ファイル: SetEphemerisForm.cs プロジェクト: sayrun/Bayaki
 private void SetEphemerisForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (null != _port)
     {
         _port.Dispose();
         _port = null;
     }
 }
コード例 #4
0
 private void ConfiurationForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (null != _port)
     {
         _port.Dispose();
         _port = null;
     }
 }
コード例 #5
0
 private void DownloadDataForm_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (null != _port)
     {
         _port.Dispose();
         _port = null;
     }
 }
コード例 #6
0
        private void _connect_Click(object sender, EventArgs e)
        {
            try
            {
                string portName = this.PortName;
                if (Properties.Resources.PORT_AUTOSEL == portName)
                {
                    try
                    {
                        portName      = SkytraqController.AutoSelectPort();
                        this.PortName = portName;
                    }
                    catch
                    {
                        _posrts.Items.Remove(portName);
                        MessageBox.Show(Properties.Resources.MSG1, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }
                _port = new SkytraqController(portName);
                MyEnviroment.LatestPortName = portName;
                _port.OnRead += _port_OnRead;

                // Version情報
                SoftwareVersion sv = _port.SoftwareVersion;
                _kernelVersion.Text = string.Format("{0:D2}.{1:D2}.{2:D2}", ((sv.KernelVersion >> 16) & 0x00ff), ((sv.KernelVersion >> 8) & 0x00ff), (sv.KernelVersion & 0x00ff));
                _ODMVersion.Text    = string.Format("{0:D2}.{1:D2}.{2:D2}", ((sv.ODMVersion >> 16) & 0x00ff), ((sv.ODMVersion >> 8) & 0x00ff), (sv.ODMVersion & 0x00ff));
                _Revision.Text      = string.Format("{0:D2}/{1:D2}/{2:D2}", ((sv.Revision >> 16) & 0x00ff), ((sv.Revision >> 8) & 0x00ff), (sv.Revision & 0x00ff));

                // バッファーサイズ
                BufferStatus bs          = _port.GetBufferStatus();
                UInt16       usedSectors = bs.TotalSectors;
                usedSectors          -= bs.FreeSectors;
                _bufferStatus.Maximum = bs.TotalSectors;
                _bufferStatus.Value   = usedSectors;

                // ボタンを制御
                _connect.Enabled  = false;
                _download.Enabled = true;
                _posrts.Enabled   = false;

                if (bs.TotalSectors == bs.FreeSectors)
                {
                    _download.Enabled = false;
                    MessageBox.Show(Properties.Resources.MSG3, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format(Properties.Resources.MSG4, ex.Message), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
コード例 #7
0
        private void _eraseWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            string portName = e.Argument as string;

            try
            {
                using (SkytraqController skytraq = new SkytraqController(portName))
                {
                    MyEnviroment.LatestPortName = portName;

                    bool result = skytraq.EraceLatLonData();

                    e.Result = result;
                }
            }
            catch
            {
                e.Result = false;
            }
        }
コード例 #8
0
ファイル: SetEphemerisForm.cs プロジェクト: sayrun/Bayaki
        private void _start_Click(object sender, EventArgs e)
        {
            string portName = this.PortName;

            if (Properties.Resources.PORT_AUTOSEL == portName)
            {
                try
                {
                    portName      = SkytraqController.AutoSelectPort();
                    this.PortName = portName;
                }
                catch
                {
                    _posrts.Items.Remove(portName);
                    MessageBox.Show(Properties.Resources.MSG1, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
            try
            {
                _port = new SkytraqController(portName);
                MyEnviroment.LatestPortName = portName;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            _port.OnSetEphemeris += _port_OnSetEphemeris;

            System.Net.WebClient wc = new System.Net.WebClient();
            wc.Credentials = new System.Net.NetworkCredential(_username.Text, _password.Text);
            string URL = string.Format("ftp://{0}/ephemeris/Eph.dat", _host.Text);

            wc.DownloadProgressChanged += Wc_DownloadProgressChanged;
            wc.DownloadDataCompleted   += Wc_DownloadDataCompleted;
            wc.DownloadDataAsync(new Uri(URL));

            return;
        }
コード例 #9
0
        private void _connect_Click(object sender, EventArgs e)
        {
            try
            {
                string portName = this.PortName;
                if (Properties.Resources.PORT_AUTOSEL == portName)
                {
                    try
                    {
                        portName      = SkytraqController.AutoSelectPort();
                        this.PortName = portName;
                    }
                    catch
                    {
                        _posrts.Items.Remove(portName);
                        MessageBox.Show(Properties.Resources.MSG1, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        return;
                    }
                }
                _port = new SkytraqController(portName);
                MyEnviroment.LatestPortName = portName;

                // Version情報
                SoftwareVersion sv = _port.SoftwareVersion;
                _kernelVersion.Text = string.Format("{0:D2}.{1:D2}.{2:D2}", ((sv.KernelVersion >> 16) & 0x00ff), ((sv.KernelVersion >> 8) & 0x00ff), (sv.KernelVersion & 0x00ff));
                _ODMVersion.Text    = string.Format("{0:D2}.{1:D2}.{2:D2}", ((sv.ODMVersion >> 16) & 0x00ff), ((sv.ODMVersion >> 8) & 0x00ff), (sv.ODMVersion & 0x00ff));
                _Revision.Text      = string.Format("{0:D2}/{1:D2}/{2:D2}", ((sv.Revision >> 16) & 0x00ff), ((sv.Revision >> 8) & 0x00ff), (sv.Revision & 0x00ff));

                // バッファ情報
                _bs = _port.GetBufferStatus();
                if (0 != _bs.Time)
                {
                    _thresholdType.SelectedIndex = 0;
                }
                else
                {
                    if (0 != _bs.Distance)
                    {
                        _thresholdType.SelectedIndex = 1;
                    }
                    else
                    {
                        _bs.Time = 5;
                        _thresholdType.SelectedIndex = 0;
                    }
                }
                _speed.Value = _bs.Speed;

                _thresholdType.Enabled = true;
                _threshold.Enabled     = true;
                _speed.Enabled         = true;
                _update.Enabled        = true;
            }
            catch (Exception ex)
            {
                _thresholdType.Enabled = false;
                _threshold.Enabled     = false;
                _speed.Enabled         = false;
                _update.Enabled        = false;

                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }