/// <summary> /// ボーレートを合わせる /// </summary> /// <returns></returns> private void SyncBaudRate(out SoftwareVersion version) { int[] BaudRateList = { 0, 115200, 38400, 230400, 57600, 19200, 9600, 4800 }; foreach (int baudRate in BaudRateList) { // 0は今の設定を使う if (0 != baudRate) { _com.BaudRate = baudRate; System.Threading.Thread.Sleep(50); } try { int readTimeout = _com.ReadTimeout; // 読み出しのタイムアウトを短くする _com.ReadTimeout = READ_TIMEOUT_INTERNAL; // ソフトバージョンを取得してみる version = GetSoftwareVersion(); // タイムアウト値をもどします。 _com.ReadTimeout = readTimeout; System.Diagnostics.Debug.Print("Soft Type=0x{0:X2}", version.SoftType); System.Diagnostics.Debug.Print("Kernel Vresion=0x{0:X8}", version.KernelVersion); System.Diagnostics.Debug.Print("ODM Vresion=0x{0:X8}", version.ODMVersion); System.Diagnostics.Debug.Print("Revision=0x{0:X8}", version.Revision); return; } catch { continue; } } throw new InvalidOperationException("応答を受信できませんでした"); }
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); } }
/// <summary> /// ソフトバージョン取得 /// 取得のためにコマンドを再発行する /// </summary> /// <returns></returns> public SoftwareVersion GetSoftwareVersion() { Payload p = new Payload(MessageID.Query_Software_version, new byte[] { 0x01 }); if (RESULT.RESULT_ACK != this.waitSendResult(p)) { throw new Exception("NACK!"); } Payload result; result = Read(); if (result.ID != MessageID.Software_version) { throw new Exception("Sequence error"); } SoftwareVersion resutl = new SoftwareVersion(result.Body); return(resutl); }
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); } }