Rev 145 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace NITNavComm {public partial class NITCommNavForm : Form {private NITNavCommDevice navcomm = null;public NITCommNavForm() {InitializeComponent();this.controlStatus(false);}private void controlStatus(bool status) {cmdSend0.Enabled = status;cmdSend1.Enabled = status;cmdUpdate.Enabled = status;inputTimer.Enabled = status;}public void UpdateDevice() {this.UpdateDisplay();this.UpdateInput();}public void UpdateDisplay(byte display) {byte[] data;if (display == 0) {data = navcomm.getFreq(0);freq0.Value = this.byteArraytoString(ref data, 5);data = navcomm.getFreq(1);freq1.Value = this.byteArraytoString(ref data, 5);} else {data = navcomm.getFreq(2);freq2.Value = this.byteArraytoString(ref data, 5);data = navcomm.getFreq(3);freq3.Value = this.byteArraytoString(ref data, 5);}navcomm.updateDisplay(display);}public void UpdateDisplay() {this.UpdateDisplay(0);this.UpdateDisplay(1);}public void UpdateInput() {this.UpdateInput(0);}public void UpdateInput(byte display) {navcomm.updateInput();cmdSwap0.Checked = navcomm.isSwapSet(0);cmdFlip0.Checked = navcomm.isFlipSet(0);txtRot0.Text = navcomm.getRotary(0, 0).ToString("X");}private string byteArraytoString(ref byte[] data, byte len) {StringBuilder sb = new StringBuilder();for (byte i = 0; i < len; i++) {if (data[i] == 0x0a)sb.Append(' ');elsesb.Append((byte)(data[i]));}return sb.ToString();}public void setDevice(NITNavCommDevice navcomm) {this.navcomm = navcomm;if (!navcomm.isOpen())navcomm.Open();if (navcomm.isOpen())this.controlStatus(true);}public void SwapFreq(byte display) {navcomm.swapFreq(display);this.UpdateDisplay(display);}private void cmdSend0_Click(object sender, EventArgs e) {char[] data = txtSend0.Text.ToArray();byte[] bytes = new byte[5];for (byte i = 0; i < 5; i++) {if (data[i] == 'a' || data[i] == ' ')bytes[i] = (byte)0x0a;elsebytes[i] = (byte)(data[i] - '0');}navcomm.setFreq(1, ref bytes);this.UpdateDisplay(0);}private void cmdSend1_Click(object sender, EventArgs e) {char[] data = txtSend1.Text.ToArray();byte[] bytes = new byte[5];for (byte i = 0; i < 5; i++) {if (data[i] == 'a' || data[i] == ' ')bytes[i] = (byte)0x0a;elsebytes[i] = (byte)(data[i] - '0');}navcomm.setFreq(3, ref bytes);this.UpdateDisplay(1);}private void cmdClose_Click(object sender, EventArgs e) {if (this.navcomm != null && this.navcomm.isOpen())navcomm.Close();this.Close();}private void cmdUpdate_Click(object sender, EventArgs e) {this.UpdateDevice();}private void cmdSwap0_CheckedChanged(object sender, EventArgs e) {if (cmdSwap0.Checked)this.SwapFreq(0);}private void cmdSwap0_Click(object sender, EventArgs e) {cmdSwap0.Checked = false;this.SwapFreq(0);}private void inputTimer_Tick(object sender, EventArgs e) {this.UpdateInput();}}}