public virtual void OnConfigReceived(SerialNetConfig config) { if(ConfigReceived != null) { ConfigReceived(this, new SerialNetConfigEventArgs(config)); } }
public SerialNetDevice() { protocol = new SerialNetProtocol(); config = new SerialNetConfig(protocol); sPort = new SerialPort(config.port, config.baud); sPort.Open(); parser = new SerialNetParser(protocol, sPort); parser.ConfigReceived += new EventHandler<SerialNetConfigEventArgs>(parser_ConfigReceived); //!< parser will bubble up a config if it gets a full one from AT%H command }
void parseIncoming(String text) { string[] values; text = text.Replace('\r',' '); values = text.Split(new char[] { '\n' }); String test = values[0]; switch (values[0].TrimEnd(new char[]{' '})) { case "AT%H": SerialNetConfig config = new SerialNetConfig(protocol, values); if (config != null) OnConfigReceived(config); break; } }
//! Generate a SerialNetConfig object based on the current UI fields //! Used before write config to collect user entries SerialNetConfig UItoConfig() { List<TextBox> invalid = new List<TextBox>(); SerialNetConfig finalConfig = new SerialNetConfig(); if(!long.TryParse(PANIDTextBox.Text, out finalConfig.panIDLong)) invalid.Add(PANIDTextBox); if(!int.TryParse(SPANIDTextBox.Text, out finalConfig.panID)) invalid.Add(PANIDTextBox); if(!long.TryParse(ChannelMaskTextBox.Text, out finalConfig.chMask)) invalid.Add(ChannelMaskTextBox); finalConfig.role = (SerialNetConfig.NODE_ROLE)RoleComboBox.SelectedIndex; foreach(TextBox t in invalid) { t.Background = Brushes.Red; } return finalConfig; }
public SerialNetConfigEventArgs(SerialNetConfig config) { SerialNetConfig = config; }
void parser_ConfigReceived(object sender, SerialNetConfigEventArgs e) { this.config = e.SerialNetConfig; if (ConfigChanged != null) ConfigChanged(this, new SerialNetConfigEventArgs(this.config)); //!< bubble up the config changed event so the UI can subscribe too. }
public void writeConfig(SerialNetConfig configB) { if (DeviceStatus == SerialNetDeviceStatus.OK_NETWORK) sPort.Write("AT+LEAVE\r"); if (config.role != configB.role) { sPort.Write("AT+WROLE=" + configB.role.ToString() + '\r'); } if (config.autonet != configB.autonet) { if (configB.autonet) sPort.Write("AT+WAUTONET=1\r"); else sPort.Write("AT+WAUTONET=0\r"); } readConfig(); }