private void _writeSocket(byte[] buffer, int length) { if (_socket != null && _socket.Connected && _dtuconnected) { try { byte[] sn = BitConverter.GetBytes(ulong.Parse(_connectionInfo.DtuSn, NumberStyles.AllowHexSpecifier)); Array.Reverse(sn); byte[] bytes = buffer.Take(length).ToArray(); if (GetType() == typeof(NetTransService)) { MonitorDataManager.instance.Add(_connectionInfo.DtuSn, bytes, MonitorDataType.MDT_LOC); PassThrough passthrough = new PassThrough(sn, bytes); Package pkg = new Package(passthrough); Logger.Trace("[{0}] ===> {1}", _connectionInfo.DtuSn, pkg.ToString()); _socket.Send(pkg.toBytes()); } else if (GetType() == typeof(ComTransService)) { if (_connector.GetType() == typeof(ComConnector)) { ComConnector cc = _connector as ComConnector; MonitorDataManager.instance.Add(_connectionInfo.DtuSn, bytes, MonitorDataType.MDT_COM); byte syncflag = 1; //同步波特率 ComPassThrough compassthrough = new ComPassThrough(sn, syncflag, cc.VCom.DCBlock.BaudRate, cc.VCom.DCBlock.ByteSize, cc.VCom.DCBlock.Parity, cc.VCom.DCBlock.StopBits, bytes); Package pkg = new Package(compassthrough); Logger.Trace("[{0}] ===> {1}", _connectionInfo.DtuSn, pkg.ToString()); _socket.Send(pkg.toBytes()); } } } catch (Exception e) { Logger.Error(e.ToString()); } } }
public ComTransService(ConnectionInfo info) : base(info) { _connector = new ComConnector(info); }