Пример #1
0
        static void Main(string[] args)
        {
            //3C 04 0C AA 08 31 2E 33 35 32 2E 30 32 66 ED
            Console.WriteLine(DataHelper.ConvertToHexFromInt(10));
            Console.WriteLine(DataHelper.ConvertToHexFromInt(269));
            ConnectToServer();
            Console.WriteLine("TCP客户端已连接到服务器");
            Console.WriteLine("现在可以给服务器发送指令了");
            while (true)
            {
                try
                {
                    string text = Console.ReadLine();
                    if (text == "quit")
                    {
                        break;
                    }
                    else
                    {
                        if (string.IsNullOrEmpty(text))
                        {
                            //获取温度湿度 250301FF0066已解析
                            //获取采集保存间隔250308DD0066已解析
                            //获取历史总包数历史总条数250306AA0066已解析待验证
                            //下载历史数据250306AA0201000066已解析待验证


                            //修改节点地址
                            //获取设备硬件软件版本号25080CAA0066
                            //设置设备地址25070255010B66

                            //读温度报警值上限下限25030A010066已解析
                            //读湿度报警值上限下限25030A020066已解析

                            //写温度报警值25030A01040A00DE0366
                            //写湿度报警值25030A0204C800700366
                            //读温湿度报警状态25030ABB0066

                            //读取保存间隔250308DD0066已解析
                            //设置保存间隔 写分钟   记录间隔 存储容量
                            //250308DD0305E80366
                            //设置保存间隔 写小时
                            //250308DD0401DC050066

                            //清空历史记录
                            //250309FF0066
                            //读取设备日期时间已解析
                            //250308CC0066


                            //设置时间
                            //250308BB0617071618303066
                            //开启温度报警25030AAA010166
                            //开启湿度报警25030AAA010266
                            //开启温湿度报警25030AAA010366
                            //关闭温湿度报警25030AAA010066

                            // text = "250F06AA0066";
                            text = "250401FF0066";
                        }
                        var cmdbytes = new GetDataCommand(text).GetCommandBytes();

                        _client.Send(cmdbytes);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            _client.Shutdown();
            Console.WriteLine("TCP客户端已经从服务器断开了");

            Console.ReadKey();
        }
Пример #2
0
 public void ShutDown()
 {
     Client.Shutdown();
 }
Пример #3
0
        static void Main(string[] args)
        {
            ConnectServer();

            Console.WriteLine("APM TCP client has connected to server.");
            Console.WriteLine("Type something to send to server...");

            while (true)
            {
                try
                {
                    string text = Console.ReadLine();
                    if (text == "quit")
                    {
                        break;
                    }
                    else if (text == "many")
                    {
                        text = new string('x', 8192);
                        for (int i = 0; i < 1000000; i++)
                        {
                            _client.Send(Encoding.UTF8.GetBytes(text));
                        }
                    }
                    else if (text == "big1k")
                    {
                        text = new string('x', 1024 * 1);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big10k")
                    {
                        text = new string('x', 1024 * 10);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big100k")
                    {
                        text = new string('x', 1024 * 100);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big1m")
                    {
                        text = new string('x', 1024 * 1024 * 1);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big2m")
                    {
                        text = new string('x', 1024 * 1024 * 2);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big5m")
                    {
                        text = new string('x', 1024 * 1024 * 5);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big10m")
                    {
                        text = new string('x', 1024 * 1024 * 10);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big20m")
                    {
                        text = new string('x', 1024 * 1024 * 20);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big50m")
                    {
                        text = new string('x', 1024 * 1024 * 50);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big100m")
                    {
                        text = new string('x', 1024 * 1024 * 100);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else if (text == "big1g")
                    {
                        text = new string('x', 1024 * 1024 * 1024);
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                    else
                    {
                        _client.Send(Encoding.UTF8.GetBytes(text));
                    }
                }
                catch (Exception ex) { Console.WriteLine(ex.Message); }
            }

            _client.Shutdown();
            Console.WriteLine("TCP client has disconnected from server.");

            Console.ReadKey();
        }
Пример #4
0
 public void Dispose()
 {
     _client.Shutdown();
 }