HamBook – Rev 3

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.Tasks;
using static HamBook.Radios.Yaesu.FT_891.Constants;

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

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

        public override void Set(int frequency)
        {
            var fa = frequency.ToString("000000000");

            SerialPort.Write($"{Name}{fa}{Generic.Constants.EOT}");
        }

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