HamBook – Rev 7

Subversion Repositories:
Rev:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using static HamBook.Radios.Yaesu.FT_891.Constants;

namespace HamBook.Radios.Yaesu.FT_891
{
    [Radio("Yaesu FT-891")]
    public class ID : Generic.CAT.ID
    {
        private static readonly Regex readRegex = new Regex(@"^ID(?<id>[0-9]{4})$", RegexOptions.Compiled);

        public ID(SerialPort serialPort) : base(serialPort)
        {
        }

        public override bool Read()
        {
            SerialPort.Write($"{Name}{Generic.Constants.EOT}");
            var result = SerialPort.ReadTo(Generic.Constants.EOT);
            var match = readRegex.Match(result);
            return int.Parse(match.Result("${id}")) == int.Parse(Constants.ID);
        }
    }
}