コード例 #1
0
 public virtual void OnConfigReceived(SerialNetConfig config)
 {
     if(ConfigReceived != null)
     {
         ConfigReceived(this, new SerialNetConfigEventArgs(config));
     }
 }
コード例 #2
0
        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
        }
コード例 #3
0
        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;
            }
        }
コード例 #4
0
        //! 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;
        }
コード例 #5
0
 public SerialNetConfigEventArgs(SerialNetConfig config)
 {
     SerialNetConfig = config;
 }
コード例 #6
0
 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.
 }
コード例 #7
0
        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();
        }