예제 #1
0
        private void UploadQing_Click(object sender, RibbonControlEventArgs e)
        {
            //开一个新线程
            //for循环将 数据一条一条的上传

            for (int i = 2; i < 50; i++)
            {
                string[] data = CellSetFunctions.IndexForUploading(i);
                PostManToWeChat.PostDataToQing(data[0], data[1], data[2], data[3]);
            }
            Debug.WriteLine("所以数据上传完成");
        }
예제 #2
0
        /// <summary>
        /// 接收消息
        /// </summary>
        /// <param name="o"></param>
        public static void Recive(object o)
        {
            try
            {
                var send = o as Socket;
                while (true)
                {
                    //获取发送过来的消息容器
                    byte[] buffer    = new byte[1024 * 1024 * 20];
                    var    effective = send.Receive(buffer);
                    //有效字节为0则跳过
                    if (effective == 0)
                    {
                        break;
                    }
                    //这里绑定了IP send.RemoteEndPoint +
                    string   str = Encoding.UTF8.GetString(buffer, 0, effective);
                    string[] ip  = send.RemoteEndPoint.ToString().Split(':');
                    try
                    {
                        if (ip[0] == "192.168.43.161")
                        {
                            //走到这一步这说明小车移动了
                            CellSetFunctions.InsertSheet3RowData(str);
                        }
                        else
                        {
                            ControlDataClass dataClass = JsonConvert.DeserializeObject <ControlDataClass>(str);
                            CellSetFunctions.InsertSheet2RowData(dataClass.Humi, dataClass.Temp, dataClass.Light);
                        }
                    }
                    catch
                    {
                        //令人窒息的Bug!!!!
                    }


                    Debug.WriteLine(str);
                    //var buffers = Encoding.UTF8.GetBytes("Recived:" + str);
                    //将得到的字符串再返回给下位机
                    //send.Send(buffers);
                    //拿到值了
                    //ExcelAct(str);
                    //Range["F2"].Value2 = "sss";
                }
            }
            catch
            {
            }
        }