Inheritance: Vixen.Module.ModuleDataModelBase
Beispiel #1
0
        public SetupDialog(Data data)
        {
            InitializeComponent();

            _data = data;
            tbHeader.Enabled = false;
            tbFooter.Enabled = false;

            if (!string.IsNullOrEmpty(data.Header))
            {
                cbHeader.Checked = true;
                tbHeader.Enabled = true;
                tbHeader.Text = data.Header;
            }

            if (!string.IsNullOrEmpty(data.Footer))
            {
                cbFooter.Checked = true;
                tbFooter.Enabled = true;
                tbFooter.Text = data.Footer;
            }

            if (!string.IsNullOrEmpty(data.PortName))
            {
                _serialPort = new SerialPort(data.PortName, data.BaudRate, data.Parity, data.DataBits, data.StopBits);
                updateSettingLabel();
                btnOkay.Enabled = true;
            }
            else
            {
                lblSettings.Text = "Not Set";
                btnOkay.Enabled = false;
            }
        }
Beispiel #2
0
		public SetupDialog(Data data)
		{
			InitializeComponent();
			ForeColor = ThemeColorTable.ForeColor;
			BackColor = ThemeColorTable.BackgroundColor;
			ThemeUpdateControls.UpdateControls(this);

			_data = data;
			tbHeader.Enabled = false;
			tbFooter.Enabled = false;

			if (!string.IsNullOrEmpty(data.Header)) {
				cbHeader.Checked = true;
				tbHeader.Enabled = true;
				tbHeader.Text = data.Header;
			}

			if (!string.IsNullOrEmpty(data.Footer)) {
				cbFooter.Checked = true;
				tbFooter.Enabled = true;
				tbFooter.Text = data.Footer;
			}

			if (!string.IsNullOrEmpty(data.PortName)) {
				Port = new SerialPort(data.PortName, data.BaudRate, data.Parity, data.DataBits, data.StopBits);
				updateSettingLabel();
				btnOkay.Enabled = true;
			}
			else {
				lblSettings.Text = "Not Set";
				btnOkay.Enabled = false;
			}
		}
        internal void SendUpdate(ICommand[] outputStates, Data _Data, CommandHandler _commandHandler)
        {
            if (serialPortIsValid && isSerialPortOpen)
            {
                byte[] _header = Encoding.ASCII.GetBytes(_Data.Header == null ? string.Empty : _Data.Header);
                var headerLen = _header.Length; // compute this here so we don't have to compute it in the loop

                byte[] _footer = Encoding.ASCII.GetBytes(_Data.Footer == null ? string.Empty : _Data.Footer);

                byte[] _packet = new byte[headerLen + outputStates.Length + _footer.Length];

                _header.CopyTo(_packet, 0);
                _footer.CopyTo(_packet, _packet.Length - _footer.Length);

                ICommand command = null;

                // Why do we use the command handler?  For this module, it just seems like unnecessary overhead.
                for (int i = 0; i < outputStates.Length; i++)
                {
                    _commandHandler.Reset();
                    command = outputStates[i];
                    if (command != null)
                    {
                        command.Dispatch(_commandHandler);
                    }
                    _packet[i + headerLen] = _commandHandler.Value;
                }

                if (_packet.Length > 0)
                {
                    _SerialPort.Write(_packet, 0, _packet.Length);
                }
            }
        }
        private void createSerialPortFromData(Data _Data)
        {
            if (_Data.IsValid)
            {
                _SerialPort = new SerialPort(
                    _Data.PortName,
                    _Data.BaudRate,
                    _Data.Parity,
                    _Data.DataBits,
                    _Data.StopBits);

                _SerialPort.Handshake = Handshake.None;
                _SerialPort.Encoding = Encoding.UTF8;
            }
        }
 protected internal void initModule(Data _Data)
 {
     dropExistingSerialPort();
     createSerialPortFromData(_Data);
 }