private static int getPort()
        {
            int          port;
            FileInfoRead read = new FileInfoRead();

            port = int.Parse(read.port);
            return(port);
        }
Ejemplo n.º 2
0
 public MainWindow()
 {
     InitializeComponent();
     read = new FileInfoRead();
     concenIPText.Text         = read.concentratorIP;
     concenPortText.Text       = read.concentratorPORT;
     concenIPText.IsReadOnly   = true;
     concenIPText.Background   = Brushes.Gray;
     concenPortText.IsReadOnly = true;
     concenPortText.Background = Brushes.Gray;
     response = new DataAnalyze();
 }
Ejemplo n.º 3
0
        private void excuteBtn_Click(object sender, RoutedEventArgs e)
        {
            SetFile = new FileInfoRead();
            DBManager          db     = new DBManager();
            IPEndPoint         remote = new IPEndPoint(IPAddress.Parse(SetFile.concentratorIP), Convert.ToInt32(SetFile.concentratorPORT));
            SetConcentratorNet set    = new SetConcentratorNet(concentratorText.Text, concentratorIPText.Text, concentratorPortText.Text, localHostSubnetMsakText.Text, remoteHostIPText.Text, remoteHostPortText.Text, gatewayIPText.Text);

            byte[] order = set.getSettingOrder();
            if (order[1] == 0x10)
            {
                socketSetting.SendTo(order, remote);
            }
            else
            {
                MessageBox.Show("检查输入后重试");
                return;
            }

            //延时等待集中器回复,等待最大时长5秒
            DateTime now = DateTime.Now;
            int      s;
            bool     success = false;

            do
            {
                TimeSpan span = DateTime.Now - now;
                s = span.Seconds;
                if (DataAnalyze.setConcentratorResponse)
                {
                    success = true;
                    DataAnalyze.setConcentratorResponse = false;
                    break;
                }
            }while (s < 5);
            if (success)
            {
                if (new FileInfoRead().WriteIniData(concentratorIPText.Text, concentratorPortText.Text))
                {
                    MessageBox.Show("配置成功");
                }
                else
                {
                    MessageBox.Show("配置成功但写入配置文件失败");
                }
            }
            else
            {
                MessageBox.Show("配置失败");
            }
        }
Ejemplo n.º 4
0
        private void fireSendBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                read = new FileInfoRead();
                //更新集中器IP和PORT
                concenIPText.Text   = read.concentratorIP;
                concenPortText.Text = read.concentratorPORT;
                int        concentratoraddress = Convert.ToInt32(fireText.Text.Trim(), 16);
                IPEndPoint remote     = new IPEndPoint(IPAddress.Parse(read.concentratorIP), Convert.ToInt32(read.concentratorPORT));
                Socket     socketSend = server._serverSock;
                //构造发送命令:服务器主动申请数据
                int    strapNumber = Convert.ToInt32(strapNum2.Text);
                byte[] orderMeg    = RequestOrder((byte)concentratoraddress, strapNumber, 0x06);
                socketSend.SendTo(orderMeg, remote);
                //等待获取回复, 最大延时5秒
                DateTime now = DateTime.Now;
                int      s;
                bool     success = false;
                do
                {
                    TimeSpan span = DateTime.Now - now;
                    s = span.Seconds;
                    if (DataAnalyze.fireStrapResponse)
                    {
                        success = true;
                        DataAnalyze.fireStrapResponse = false;
                        break;
                    }
                }while (s < 5);
                if (success)
                {
                    MessageBox.Show("请求成功");
                }
                else
                {
                    MessageBox.Show("请求失败");
                }
            }

            catch
            {
                MessageBox.Show("检查服务是否开启");
            }
        }
Ejemplo n.º 5
0
        public ConcentratorNetSetting(Socket socket_)
        {
            socketSetting = socket_;
            InitializeComponent();
            SetFile = new FileInfoRead();

            //服务器参数设置
            remoteHostIPText.Text   = GetAddressIP();
            remoteHostPortText.Text = SetFile.port;

            //显示集中器初始网络参数
            concentratorIPText.Text   = SetFile.concentratorIP;
            concentratorPortText.Text = SetFile.concentratorPORT;
            //服务器网络参数设为只读
            remoteHostPortText.IsReadOnly = true;
            //本机网络参数文本框背景变暗
            remoteHostIPText.Background   = Brushes.Gray;
            remoteHostPortText.Background = Brushes.Gray;
        }
Ejemplo n.º 6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            dtgShow.SelectAllCells();//选中所有行
            var           cells = dtgShow.SelectedCells;
            StringBuilder sb    = new StringBuilder();

            if (cells.Any())
            {
                foreach (var cell in cells)
                {
                    sb.Append((cell.Column.GetCellContent(cell.Item) as TextBlock).Text);
                    sb.Append(" ");
                }
            }
            string[] str  = sb.ToString().Split(' ');
            byte[]   data = exeData(str);
            if (data == null)
            {
                MessageBox.Show("请检查输入完整");
            }
            else
            {
                SetFile = new FileInfoRead();
                IPEndPoint remote = new IPEndPoint(IPAddress.Parse(SetFile.concentratorIP), Convert.ToInt32(SetFile.concentratorPORT));
                socketSetting.SendTo(data, remote);
            }
            //延时等待集中器回复,等待最大时长5秒
            DateTime now = DateTime.Now;
            int      s;
            bool     success = false;

            do
            {
                TimeSpan span = DateTime.Now - now;
                s = span.Seconds;
                if (DataAnalyze.setTempStrapAddressResponse)
                {
                    success = true;
                    DataAnalyze.setTempStrapAddressResponse = false;
                    break;
                }
            }while (s < 5);
            if (success)
            {
                DBManager db  = new DBManager();
                string    sql = "insert into strapmap (devName,strapaddress,type) values ";
                for (int i = 0; i < str.Length / 2; i++)
                {
                    sql = sql + "('" + str[2 * i] + "','" + str[2 * i + 1] + "',' 测温 '),";
                }
                sql = sql.Substring(0, sql.Length - 1);
                if (db.Insert(sql))
                {
                    MessageBox.Show("配置成功");
                }
                else
                {
                    MessageBox.Show("配置成功但写入数据库失败");
                }
            }
            else
            {
                MessageBox.Show("配置失败");
            }
        }