コード例 #1
0
        /// <summary>
        /// 注册登记
        /// 15 01 01 00 00 00 00 17 00 7b 22 44 65 76 69 63 65 49 64 22 3a 22 74 65 73 74 31 32 33 34 22 7d 5A 02
        /// </summary>
        public void Regester(BaseDataModel _baseDataModel)
        {
            baseDataModel = _baseDataModel;

            string data = "{\"DeviceId\":\"" + baseDataModel.deviceAddress + "\"}";

            sendDataMethod(data, CMDCode.Register);
            int tryTimes = 0;

            do
            {
                Thread.Sleep(500);
                if (isEnd)
                {
                    break;
                }
                if (tryTimes >= 6)
                {
                    _client.Close();
                    _log.InfoFormat("{0}{1} DustMonitoringService 设备号:{2} 服务器响应超时链接已断开", DateTime.Now, Environment.NewLine, baseDataModel.deviceAddress);
                    break;
                }
                tryTimes++;
            } while (true);

            _client.Close();
            _client.Dispose();
        }
コード例 #2
0
 public void Dispose()
 {
     Client.Close();
     Client.Dispose();
     Client = null;
     PollingTimer.Dispose();
     PollingTimer = null;
 }
コード例 #3
0
        public void Dispose_tests()
        {
            TcpSocketClient client = new TcpSocketClient(new ClamAvSettings("127.0.0.0", 33100), NullLogger <TcpSocketClient> .Instance);

            Action testAction = () => client.Dispose();

            testAction.Should().NotThrow();
            testAction.Should().NotThrow();
            testAction.Should().NotThrow();
        }
コード例 #4
0
        private static async void StartTcpClient()
        {
            var tcpClient = new TcpSocketClient();
            await tcpClient.ConnectAsync("www.abc.dk", "8088", secure : true, ignoreServerCertificateErrors : true);

            var helloWorld = "Hello World!";

            var bytes = Encoding.UTF8.GetBytes(helloWorld);
            await tcpClient.WriteStream.WriteAsync(bytes, 0, bytes.Length);

            tcpClient.Disconnect();
            tcpClient.Dispose();
        }
コード例 #5
0
        /// <summary>
        /// Disconnect the current device an dispose all ressources
        /// </summary>
        public static async void Disconnect()
        {
            connected = false;
            try
            {
                await tcpSocketClient.DisconnectAsync();

                tcpSocketClient.Dispose();
            }
            catch (Exception e)
            {
                throw new Exception(305, "The device could not disconnect");
            }
        }
コード例 #6
0
        public static void Disconnect()
        {
            if (ImageComparisonServer != null)
            {
                try
                {
                    // Properly sends a message notifying we want to close the connection
                    var networkStream = ImageComparisonServer.WriteStream;
                    var binaryWriter  = new BinaryWriter(networkStream);
                    binaryWriter.Write((int)ImageServerMessageType.ConnectionFinished);

                    ImageComparisonServer.Dispose();
                }
                catch (Exception)
                {
                }
                ImageComparisonServer = null;
            }
        }
コード例 #7
0
        /// <summary>
        /// 噪音数据上报
        /// </summary>
        public void UploadData(BaseDataModel _baseDataModel)
        {
            RequstModel requstModel = new RequstModel();
            string      resultStr   = requstModel.ToString(new DataModel()
            {
                Humidity      = _baseDataModel.humidity,
                Noise         = _baseDataModel.noise,
                PM10          = _baseDataModel.PM10,
                PM25          = _baseDataModel.PM25,
                Temperature   = _baseDataModel.temperature,
                WindDirection = _baseDataModel.windDirection,
                WindSpeed     = _baseDataModel.windSpeed,

                TerminalNumber = _baseDataModel.deviceAddress,
                DeviceAddress  = _baseDataModel.deviceAddress
            });

            byte[] sendData = Encoding.ASCII.GetBytes(resultStr);
            tcpSend(sendData);

            int tryTimes = 0;

            do
            {
                Thread.Sleep(500);
                if (isEnd)
                {
                    break;
                }
                if (tryTimes >= 6)
                {
                    _client.Close();
                    _log.InfoFormat("{0}{1} TBJDataUploadService 设备号:{2} 服务器响应超时链接已断开", DateTime.Now, Environment.NewLine, _baseDataModel.deviceAddress);
                    break;
                }
                tryTimes++;
            } while (true);

            _log.InfoFormat("{0}{1} TBJDataUploadService 数据上传完成 设备号:{2}", DateTime.Now, Environment.NewLine, _baseDataModel.deviceAddress);
            _client.Close();
            _client.Dispose();
        }
コード例 #8
0
        /// <summary>
        /// 噪音数据上报
        ///
        //string.Format("&&DataTime={0};" +
        //        "a01001-Rtd={1},a01001-Flag=N;" +
        //        "a01002-Rtd={2},a01002-Flag=N;" +
        //        "a01006-Rtd={3},a01006-Flag=N;" +
        //        "a01007-Rtd={4},a01007-Flag=N;" +
        //        "a01008-Rtd={5},a01008-Flag=N;" +
        //        "a34001-Rtd={6},a34001-Flag=N;" +
        //        "a34002-Rtd={7},a34002-Flag=N;" +
        //        "a34004-Rtd={8},a34004-Flag=N;" +
        //        "La-Rtd={9},La-Flag=N;" +
        //        "longitude={10};latitude={11};&&",
        //                DateTime.Now.ToString("yyyyMMddhhmmss"),
        //        _baseDataModel.temperature,     //温度 摄氏度
        //        _baseDataModel.humidity,     //湿度 %
        //        0,     //气压 千帕
        //        _baseDataModel.windSpeed,     //风速 米/秒
        //        _baseDataModel.windDirection,     //风向 角度
        //        _baseDataModel.TSP,     //总悬浮颗粒物 TSP
        //        _baseDataModel.PM10,     //可吸入颗粒物 PM10
        //        _baseDataModel.PM25,     //细微颗粒物 PM2.5
        //        _baseDataModel.noise,     //噪声 分贝
        //        _baseDataModel.longitude,
        //        _baseDataModel.latitude
        //        )
        /// </summary>
        public void UploadData(BaseDataModel _baseDataModel)
        {
            RequstModel   requstModel = new RequstModel();
            StringBuilder cpsb        = new StringBuilder();

            cpsb.Append("&&").AppendFormat("DataTime={0};", DateTime.Now.ToString("yyyyMMddhhmmss"));

            if (!string.IsNullOrEmpty(_baseDataModel.temperature))//温度 摄氏度
            {
                cpsb.AppendFormat("a01001-Rtd={0},a01001-Flag=N;", _baseDataModel.temperature);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.humidity))//湿度 %
            {
                cpsb.AppendFormat("a01002-Rtd={0},a01002-Flag=N;", _baseDataModel.humidity);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.windSpeed))//风速 米/秒
            {
                cpsb.AppendFormat("a01007-Rtd={0},a01007-Flag=N;", _baseDataModel.windSpeed);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.windDirection))//风向 角度
            {
                cpsb.AppendFormat("a01008-Rtd={0},a01008-Flag=N;", _baseDataModel.windDirection);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.TSP))//总悬浮颗粒物 TSP
            {
                cpsb.AppendFormat("a34001-Rtd={0},a34001-Flag=N;", _baseDataModel.TSP);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.PM10))//可吸入颗粒物 PM10
            {
                cpsb.AppendFormat("a34002-Rtd={0},a34002-Flag=N;", _baseDataModel.PM10);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.PM25))//细微颗粒物 PM2.5
            {
                cpsb.AppendFormat("a34004-Rtd={0},a34004-Flag=N;", _baseDataModel.PM25);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.noise))//噪声 分贝
            {
                cpsb.AppendFormat("La-Rtd={0},La-Flag=N;", _baseDataModel.noise);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.longitude))//经度
            {
                cpsb.AppendFormat("longitude={0};", _baseDataModel.longitude);
            }
            if (!string.IsNullOrEmpty(_baseDataModel.latitude))//纬度
            {
                cpsb.AppendFormat("latitude={0};", _baseDataModel.latitude);
            }
            cpsb.Append("&&");

            string resultStr = requstModel.ToString(new DataModel()
            {
                QN   = DateTime.Now.ToString("yyyyMMddHHmmssfff"),
                ST   = "39",
                CN   = "2011",
                PW   = "123456",
                MN   = _baseDataModel.deviceAddress,
                Flag = "5",
                CP   = cpsb.ToString(),
            });

            byte[] sendData = Encoding.ASCII.GetBytes(resultStr);
            tcpSend(sendData);

            //do
            //{
            //    Thread.Sleep(1000);
            //    if (isEnd)
            //    {
            //        break;
            //    }
            //} while (true);

            _log.InfoFormat("{0}{1} MonitoringPollutantsTask 数据上传完成 设备号:{2}", DateTime.Now, Environment.NewLine, _baseDataModel.deviceAddress);
            _client.Close();
            _client.Dispose();
        }
コード例 #9
0
ファイル: TcpClient.cs プロジェクト: pousqie/MessageRouter
 public void Dispose()
 {
     _client.Dispose();
 }
コード例 #10
0
        public async Task StopAsync()
        {
            await client.DisconnectAsync();

            client.Dispose();
        }