Пример #1
0
        private void addressChange(object sender, EventArgs e)
        {
            TextBox textBox = sender as TextBox;

            if (textBox != port && textBox.TextLength == textBox.MaxLength)
            {
                shiftFocus(sender, e);
            }
            bool valid = checkAddress();

            if (valid)
            {
                sock = new ArduinoSocket(formatIP(), (ushort)Convert.ToInt16(port.Text), outputStream);
            }
            else
            {
                sock = null;
            }
            setNetworkControlEnable(valid, true);
        }
Пример #2
0
        void readAddressFromRegistry()
        {
            Object ipVal = remoteStartupKey.GetValue("ip");
            bool   valid = true;

            if (ipVal == null)
            {
                valid = false;
            }
            else
            {
                int[]    ipNum    = new int[4];
                string   ipVal_dc = ipVal as string;
                string[] ipArray  = ipVal_dc.Split('.');
                if (ipArray.Length != 4)
                {
                    valid = false;
                }
                for (int i = 0; i < 4 && valid; ++i)
                {
                    valid = valid && parseInt(ipArray[i], ref ipNum[i]);
                    int[] range = getTextBoxRange(octets[i]);
                    if (ipNum[i] < range[0] || ipNum[i] > range[1])
                    {
                        valid = false;
                    }
                }
                if (valid)
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        octets[i].Text = Convert.ToString(ipNum[i]);
                    }
                }
                else
                {
                    for (int i = 0; i < 4; ++i)
                    {
                        octets[i].Clear();
                    }
                }
            }
            if (valid)
            {
                object portVal = remoteStartupKey.GetValue("port");
                if (portVal == null)
                {
                    valid = false;
                }
                else
                {
                    string portStr = portVal as string;
                    int    portNum = 0;
                    int[]  range   = getTextBoxRange(port);
                    if (parseInt(portStr, ref portNum) && portNum >= range[0] && portNum <= range[1])
                    {
                        port.Text = Convert.ToString(portNum);
                    }
                    else
                    {
                        port.Clear();
                        valid = false;
                    }
                }
            }
            if (valid)
            {
                sock = new ArduinoSocket(formatIP(), (ushort)Convert.ToInt16(port.Text), outputStream);
            }
            else
            {
                sock = null;
            }
        }