OmronFinsNetInitializationOnConnectAsync 方法 |
命名空间: HslCommunication.Profinet.Omron
/// <inheritdoc/> public override OperateResult<byte[]> ReadFromCoreServer( CommunicationPipe pipe, byte[] send, bool hasResponseData, bool usePackAndUnpack ) { while (true) { OperateResult<byte[]> read = base.ReadFromCoreServer( pipe, send, hasResponseData, usePackAndUnpack ); if (!read.IsSuccess) return read; if (read.Content?.Length >= 4) { if ((read.Content[2] * 256 + read.Content[3]) != 0x07) return read; } } } /// <inheritdoc/> protected override OperateResult InitializationOnConnect( ) { // 第一次握手 -> First handshake OperateResult<byte[]> read_first = ReadFromCoreServer( this.CommunicationPipe, plcHead1, hasResponseData: true, usePackAndUnpack: true ); if (!read_first.IsSuccess) return read_first; // 第二次握手 -> Second handshake OperateResult<byte[]> read_second = ReadFromCoreServer( this.CommunicationPipe, plcHead2, hasResponseData: true, usePackAndUnpack: true ); if (!read_second.IsSuccess) return read_second; // 调整单次接收的pdu长度信息 pdu_length = ByteTransform.TransUInt16( read_second.Content.SelectLast( 2 ), 0 ) - 28; if (pdu_length < 200) pdu_length = 200; incrementCount = new SoftIncrementCount( ushort.MaxValue, 1 ); // 返回成功的信号 -> Return a successful signal return OperateResult.CreateSuccessResult( ); } #if !NET35 && !NET20 /// <inheritdoc/> public async override Task<OperateResult<byte[]>> ReadFromCoreServerAsync( CommunicationPipe pipe, byte[] send, bool hasResponseData, bool usePackAndUnpack ) { while (true) { OperateResult<byte[]> read = await base.ReadFromCoreServerAsync( pipe, send, hasResponseData, usePackAndUnpack ); if (!read.IsSuccess) return read; if (read.Content?.Length >= 4) { if ((read.Content[2] * 256 + read.Content[3]) != 0x07) return read; } } } /// <inheritdoc/> protected override async Task<OperateResult> InitializationOnConnectAsync( ) { // 第一次握手 -> First handshake OperateResult<byte[]> read_first = await ReadFromCoreServerAsync( this.CommunicationPipe, plcHead1, hasResponseData: true, usePackAndUnpack: true ); if (!read_first.IsSuccess) return read_first; // 第二次握手 -> Second handshake OperateResult<byte[]> read_second = await ReadFromCoreServerAsync( this.CommunicationPipe, plcHead2, hasResponseData: true, usePackAndUnpack: true ); if (!read_second.IsSuccess) return read_second; // 调整单次接收的pdu长度信息 pdu_length = ByteTransform.TransUInt16( read_second.Content.SelectLast( 2 ), 0 ) - 28; if (pdu_length < 200) pdu_length = 200; incrementCount = new SoftIncrementCount( ushort.MaxValue, 1 ); // 返回成功的信号 -> Return a successful signal return OperateResult.CreateSuccessResult( ); } #endif