Changeset 407 for PinConnection
- Timestamp:
- Aug 14, 2012, 10:31:30 AM (12 years ago)
- Location:
- PinConnection
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
PinConnection/PinConnection.lpk
r340 r407 22 22 <License Value="GNU/GPL"/> 23 23 <Version Minor="3"/> 24 <Files Count="1 1">24 <Files Count="13"> 25 25 <Item1> 26 26 <Filename Value="UCommFrame.pas"/> … … 65 65 <Item11> 66 66 <Filename Value="UCommTCPServer.pas"/> 67 <UnitName Value="UComm Socket"/>67 <UnitName Value="UCommTCPServer"/> 68 68 </Item11> 69 <Item12> 70 <Filename Value="UCommTelnet.pas"/> 71 <UnitName Value="UCommTelnet"/> 72 </Item12> 73 <Item13> 74 <Filename Value="UCommTelnetComPortOption.pas"/> 75 <UnitName Value="UCommTelnetComPortOption"/> 76 </Item13> 69 77 </Files> 70 78 <i18n> -
PinConnection/PinConnection.pas
r340 r407 3 3 } 4 4 5 unit PinConnection; 5 unit PinConnection; 6 6 7 7 interface … … 10 10 UCommFrame, UCommHub, UCommPin, UCommSerialPort, UCommThread, UPacketBurst, 11 11 USerialPort, UCommConcentrator, UCommDelay, UCommTCPClient, UCommTCPServer, 12 LazarusPackageIntf;12 UCommTelnet, UCommTelnetComPortOption, LazarusPackageIntf; 13 13 14 14 implementation 15 15 16 procedure Register; 16 procedure Register; 17 17 begin 18 end; 18 end; 19 19 20 20 initialization 21 RegisterPackage('PinConnection', @Register); 21 RegisterPackage('PinConnection', @Register); 22 22 end. -
PinConnection/UCommConcentrator.pas
r289 r407 9 9 10 10 uses 11 Classes, SysUtils, Contnrs, UCommPin ;11 Classes, SysUtils, Contnrs, UCommPin, SpecializedList; 12 12 13 13 type … … 31 31 FPins: TPinList; 32 32 FMain: TCommPin; 33 procedure MainReceive(Sender: TCommPin; Stream: T Stream);33 procedure MainReceive(Sender: TCommPin; Stream: TListByte); 34 34 procedure MainSetStatus(Sender: TCommPin; Status: Integer); 35 procedure Receive(Sender: TCommPin; Stream: T Stream);35 procedure Receive(Sender: TCommPin; Stream: TListByte); 36 36 procedure SetStatus(Sender: TCommPin; Status: Integer); 37 37 public … … 75 75 { TCommConcentrator } 76 76 77 procedure TCommConcentrator.MainReceive(Sender: TCommPin; Stream: T Stream);77 procedure TCommConcentrator.MainReceive(Sender: TCommPin; Stream: TListByte); 78 78 var 79 79 I: Integer; … … 99 99 end; 100 100 101 procedure TCommConcentrator.Receive(Sender: TCommPin; Stream: T Stream);101 procedure TCommConcentrator.Receive(Sender: TCommPin; Stream: TListByte); 102 102 begin 103 103 if FActive then FMain.Send(Stream); -
PinConnection/UCommDelay.pas
r302 r407 6 6 7 7 uses 8 Classes, SysUtils, UCommPin, UThreading, SyncObjs, SpecializedList, UStreamHelper; 8 Classes, SysUtils, UCommPin, UThreading, SyncObjs, SpecializedList, UStreamHelper, 9 UBinarySerializer; 9 10 10 11 type … … 15 16 TDelayedPacket = class 16 17 ReceiveTime: TDateTime; 17 Data: T StreamHelper;18 Data: TListByte; 18 19 constructor Create; 19 20 destructor Destroy; override; … … 40 41 Thread1: TCommDelayThread; 41 42 Thread2: TCommDelayThread; 42 procedure ReceiveData1(Sender: TCommPin; AStream: T Stream);43 procedure ReceiveData2(Sender: TCommPin; AStream: T Stream);43 procedure ReceiveData1(Sender: TCommPin; AStream: TListByte); 44 procedure ReceiveData2(Sender: TCommPin; AStream: TListByte); 44 45 procedure SetActive(AValue: Boolean); 45 46 public … … 62 63 I: Integer; 63 64 CurrentTime: TDateTime; 64 SendData: T StreamHelper;65 SendData: TListByte; 65 66 DoSleep: Boolean; 66 67 begin 67 68 try 68 SendData := T StreamHelper.Create;69 SendData := TListByte.Create; 69 70 repeat 70 71 DoSleep := True; … … 76 77 if TDelayedPacket(PacketQueue[I]).ReceiveTime < (CurrentTime - Parent.Delay) then begin 77 78 DoSleep := False; 78 SendData.Clear; 79 SendData.WriteStream(TDelayedPacket(PacketQueue[I]).Data, TDelayedPacket(PacketQueue[I]).Data.Size); 79 SendData.Assign(TDelayedPacket(PacketQueue[I]).Data); 80 80 PacketQueue.Delete(I); 81 81 try 82 82 Lock.Release; 83 Pin.Send(SendData .Stream);83 Pin.Send(SendData); 84 84 finally 85 85 Lock.Acquire; … … 100 100 constructor TDelayedPacket.Create; 101 101 begin 102 Data := T StreamHelper.Create;102 Data := TListByte.Create; 103 103 end; 104 104 … … 111 111 { TCommDelay } 112 112 113 procedure TCommDelay.ReceiveData1(Sender: TCommPin; AStream: T Stream);113 procedure TCommDelay.ReceiveData1(Sender: TCommPin; AStream: TListByte); 114 114 begin 115 115 try … … 119 119 with TDelayedPacket(PacketQueue2.AddNew(TDelayedPacket.Create)) do begin 120 120 ReceiveTime := Now; 121 Data. WriteStream(AStream, AStream.Size);121 Data.Assign(AStream); 122 122 end; 123 123 finally … … 126 126 end; 127 127 128 procedure TCommDelay.ReceiveData2(Sender: TCommPin; AStream: T Stream);128 procedure TCommDelay.ReceiveData2(Sender: TCommPin; AStream: TListByte); 129 129 begin 130 130 try … … 134 134 with TDelayedPacket(PacketQueue1.AddNew(TDelayedPacket.Create)) do begin 135 135 ReceiveTime := Now; 136 Data. WriteStream(AStream, AStream.Size);136 Data.Assign(AStream); 137 137 end; 138 138 finally -
PinConnection/UCommFrame.pas
r299 r407 6 6 7 7 uses 8 Classes, UStreamHelper, Dialogs, SysUtils, 8 Classes, UStreamHelper, Dialogs, SysUtils, SpecializedList, UBinarySerializer, 9 9 UCommPin; 10 10 … … 17 17 private 18 18 LastCharIsSpecialChar: Boolean; 19 ReceiveBuffer: T StreamHelper;19 ReceiveBuffer: TBinarySerializer; 20 20 FrameState: TFrameState; 21 21 FFrameErrorCount: Integer; 22 22 FCRCErrorCount: Integer; 23 function GetStreamCRC8(Stream: TStream): Byte; 23 function GetStreamCRC8(Stream: TListByte): Byte; 24 procedure RawDataReceive(Sender: TCommPin; Stream: TListByte); 25 procedure RawSetStatus(Sender: TCommPin; Status: Integer); 26 procedure FrameDataReceive(Sender: TCommPin; Stream: TListByte); 27 procedure FrameSetStatus(Sender: TCommPin; Status: Integer); 24 28 public 25 29 RawDataPin: TCommPin; … … 30 34 ControlCodeFrameEnd: Byte; 31 35 ControlCodeSpecialChar: Byte; 32 procedure RawDataReceive(Sender: TCommPin; Stream: TStream); 33 procedure RawSetStatus(Sender: TCommPin; Status: Integer); 34 procedure FrameDataReceive(Sender: TCommPin; Stream: TStream); 35 procedure FrameSetStatus(Sender: TCommPin; Status: Integer); 36 function ComputeRawSize(DataStream: TStream): Integer; 36 function ComputeRawSize(DataStream: TListByte): Integer; 37 37 constructor Create; 38 38 destructor Destroy; override; … … 48 48 constructor TCommFrame.Create; 49 49 begin 50 ReceiveBuffer := TStreamHelper.Create; 50 ReceiveBuffer := TBinarySerializer.Create; 51 ReceiveBuffer.List := TListByte.Create; 52 ReceiveBuffer.OwnsList := True; 51 53 RawDataPin := TCommPin.Create; 52 54 RawDataPin.OnReceive := RawDataReceive; … … 68 70 end; 69 71 70 procedure TCommFrame.FrameDataReceive(Sender: TCommPin; Stream: T Stream);71 var 72 RawData: T StreamHelper;72 procedure TCommFrame.FrameDataReceive(Sender: TCommPin; Stream: TListByte); 73 var 74 RawData: TBinarySerializer; 73 75 I: Integer; 74 76 Character: Byte; … … 76 78 begin 77 79 // Write CRC code to end of frame 78 Stream.Position := 0;79 80 CRC := GetStreamCRC8(Stream); 80 81 81 82 // Byte stuffing 82 Stream.Position := 0;83 83 try 84 RawData := TStreamHelper.Create; 84 RawData := TBinarySerializer.Create; 85 RawData.List := TListByte.Create; 86 RawData.OwnsList := True; 85 87 RawData.WriteByte(SpecialChar); 86 88 RawData.WriteByte(ControlCodeFrameStart); 87 for I := 0 to Stream. Size- 1 do begin88 Character := Stream .ReadByte;89 for I := 0 to Stream.Count - 1 do begin 90 Character := Stream[I]; 89 91 if Character = SpecialChar then begin 90 92 RawData.WriteByte(SpecialChar); … … 102 104 RawData.WriteByte(ControlCodeFrameEnd); 103 105 if Random >= PacketLoss then 104 RawDataPin.Send(RawData );106 RawDataPin.Send(RawData.List); 105 107 106 108 finally … … 114 116 end; 115 117 116 function TCommFrame.ComputeRawSize(DataStream: TStream): Integer; 118 function TCommFrame.ComputeRawSize(DataStream: TListByte): Integer; 119 var 120 I: Integer; 117 121 begin 118 122 Result := 5; // FrameStart + CRC + FrameEnd 119 DataStream.Position := 0; 120 while DataStream.Position < DataStream.Size do 121 if DataStream.ReadByte = SpecialChar then Inc(Result, 2) 123 for I := 0 to DataStream.Count - 1 do 124 if DataStream[I] = SpecialChar then Inc(Result, 2) 122 125 else Inc(Result, 1); 123 126 end; 124 127 125 procedure TCommFrame.RawDataReceive(Sender: TCommPin; Stream: T Stream);128 procedure TCommFrame.RawDataReceive(Sender: TCommPin; Stream: TListByte); 126 129 var 127 130 Character: Byte; … … 130 133 I: Integer; 131 134 begin 132 for I := 0 to Stream. Size- 1 do begin133 Character := Stream .ReadByte;135 for I := 0 to Stream.Count - 1 do begin 136 Character := Stream[I]; 134 137 if LastCharIsSpecialChar then begin 135 138 if Character = ControlCodeSpecialChar then begin … … 139 142 if FrameState = fsInside then 140 143 Inc(FFrameErrorCount); 141 ReceiveBuffer.Size := 0; 144 ReceiveBuffer.List.Count := 0; 145 ReceiveBuffer.Position := 0; 142 146 FrameState := fsInside; 143 147 end else … … 145 149 if FrameState = fsInside then begin 146 150 // Check CRC 147 if ReceiveBuffer. Size> 0 then begin148 ReceiveBuffer.Position := ReceiveBuffer. Size- 1;151 if ReceiveBuffer.List.Count > 0 then begin 152 ReceiveBuffer.Position := ReceiveBuffer.List.Count - 1; 149 153 CRC := ReceiveBuffer.ReadByte; 150 ReceiveBuffer. Size := ReceiveBuffer.Size- 1;151 ExpectedCRC := GetStreamCRC8(ReceiveBuffer );154 ReceiveBuffer.List.Count := ReceiveBuffer.List.Count - 1; 155 ExpectedCRC := GetStreamCRC8(ReceiveBuffer.List); 152 156 153 157 if ExpectedCRC <> CRC then Inc(FCRCErrorCount) 154 158 else begin 155 159 //if Random >= PacketLoss then 156 FrameDataPin.Send(ReceiveBuffer );160 FrameDataPin.Send(ReceiveBuffer.List); 157 161 end; 158 162 end else Inc(FCRCErrorCount); … … 173 177 end; 174 178 175 function TCommFrame.GetStreamCRC8(Stream: T Stream): Byte;179 function TCommFrame.GetStreamCRC8(Stream: TListByte): Byte; 176 180 var 177 181 I: Integer; … … 182 186 begin 183 187 Pom := 0; 184 Stream.Position := 0;185 188 Result := 0; 186 for I := 0 to Stream. Size- 1 do begin187 Stream.Read(Pom, 1);189 for I := 0 to Stream.Count - 1 do begin 190 Pom := Stream[I]; 188 191 for B := 0 to 7 do begin 189 if ((Result xor Pom) and 1) = 1 then Result := ((Result xor Polynom) shr 1) or $80 192 if ((Result xor Pom) and 1) = 1 then 193 Result := ((Result xor Polynom) shr 1) or $80 190 194 else Result := Result shr 1; 191 195 Pom := (Pom shr 1) or ((Pom shl 7) and $80); // Rotace vpravo -
PinConnection/UCommHub.pas
r289 r407 6 6 7 7 uses 8 Classes, SysUtils, Contnrs, UCommPin ;8 Classes, SysUtils, Contnrs, UCommPin, SpecializedList; 9 9 10 10 type … … 27 27 FActive: Boolean; 28 28 FPins: TPinList; 29 procedure Receive(Sender: TCommPin; Stream: T Stream);29 procedure Receive(Sender: TCommPin; Stream: TListByte); 30 30 procedure SetStatus(Sender: TCommPin; Status: Integer); 31 31 public … … 68 68 { TCommHub } 69 69 70 procedure TCommHub.Receive(Sender: TCommPin; Stream: T Stream);70 procedure TCommHub.Receive(Sender: TCommPin; Stream: TListByte); 71 71 var 72 72 I: Integer; -
PinConnection/UCommPin.pas
r288 r407 6 6 7 7 uses 8 Classes ;8 Classes, SpecializedList; 9 9 10 10 type … … 12 12 13 13 TDataDiretion = (ddReceive, ddSend); 14 TOnLogDataEvent = procedure (Stream: T Stream; Direction: TDataDiretion) of object;15 TOnStreamEvent = procedure (Sender: TCommPin; Stream: T Stream) of object;14 TOnLogDataEvent = procedure (Stream: TListByte; Direction: TDataDiretion) of object; 15 TOnStreamEvent = procedure (Sender: TCommPin; Stream: TListByte) of object; 16 16 TOnSetStatus = procedure (Sender: TCommPin; Status: Integer) of object; 17 17 … … 31 31 procedure SetStatus(AValue: Integer); 32 32 protected 33 procedure Receive(Stream: T Stream);33 procedure Receive(Stream: TListByte); 34 34 procedure ReceiveStatus(AValue: Integer); 35 35 public … … 39 39 procedure Connect(Pin: TCommPin); 40 40 procedure Disconnect; 41 procedure Send(Stream: T Stream);41 procedure Send(Stream: TListByte); 42 42 procedure ResetCounters; 43 43 property Connected: Boolean read GetConnected; … … 100 100 end; 101 101 102 procedure TCommPin.Receive(Stream: T Stream);102 procedure TCommPin.Receive(Stream: TListByte); 103 103 begin 104 Inc(FDataRxCount, Stream. Size);104 Inc(FDataRxCount, Stream.Count); 105 105 Inc(FFrameRxCount); 106 106 if Assigned(FOnLogData) then FOnLogData(Stream, ddReceive); 107 Stream.Position := 0;108 107 if Assigned(FOnReceive) then FOnReceive(Self, Stream); 109 108 end; … … 122 121 end; 123 122 124 procedure TCommPin.Send(Stream: T Stream);123 procedure TCommPin.Send(Stream: TListByte); 125 124 begin 126 Inc(FDataTxCount, Stream. Size);125 Inc(FDataTxCount, Stream.Count); 127 126 Inc(FFrameTxCount); 128 127 if Assigned(FOnLogData) then FOnLogData(Stream, ddSend); -
PinConnection/UCommSerialPort.pas
r288 r407 6 6 7 7 uses 8 Classes, USerialPort, UCommPin, SysUtils, DateUtils, 8 Classes, USerialPort, UCommPin, SysUtils, DateUtils, SpecializedList, 9 9 SyncObjs; 10 10 … … 15 15 TCommSerialPort = class(TSerialPort) 16 16 private 17 procedure Receive(Sender: TCommPin; Stream: T Stream);17 procedure Receive(Sender: TCommPin; Stream: TListByte); 18 18 procedure SetStatus(Sender: TCommPin; AValue: Integer); 19 procedure ReceiveData(Stream: T MemoryStream);19 procedure ReceiveData(Stream: TListByte); 20 20 public 21 21 Lock: TCriticalSection; … … 31 31 { TCommSerialPort } 32 32 33 procedure TCommSerialPort.ReceiveData(Stream: T MemoryStream);33 procedure TCommSerialPort.ReceiveData(Stream: TListByte); 34 34 begin 35 35 if Active then Pin.Send(Stream); … … 64 64 end; 65 65 66 procedure TCommSerialPort.Receive(Sender: TCommPin; Stream: TStream); 66 procedure TCommSerialPort.Receive(Sender: TCommPin; Stream: TListByte); 67 var 68 S: TMemoryStream; 67 69 begin 68 if Active then begin 69 Stream.Position := 0; 70 repeat 71 try 72 Lock.Acquire; 73 if CanWrite(0) then 74 SendStreamRaw(Stream); 75 finally 76 Lock.Release; 77 end; 78 if Stream.Position <> Stream.Size then 79 Sleep(1); 80 until Stream.Position = Stream.Size; 70 try 71 S := TMemoryStream.Create; 72 Stream.WriteToStream(S); 73 if Active then begin 74 S.Position := 0; 75 repeat 76 try 77 Lock.Acquire; 78 if CanWrite(0) then 79 SendStreamRaw(S); 80 finally 81 Lock.Release; 82 end; 83 if S.Position <> S.Size then 84 Sleep(1); 85 until S.Position = S.Size; 86 end; 87 finally 88 S.Free; 81 89 end; 82 90 end; -
PinConnection/UCommTCPClient.pas
r339 r407 7 7 uses 8 8 Classes, SysUtils, blcksock, synsock, UCommPin, UCommon, UThreading, 9 DateUtils ;9 DateUtils, SpecializedList; 10 10 11 11 type … … 19 19 public 20 20 Parent: TCommTCPClient; 21 Stream: T MemoryStream;21 Stream: TListByte; 22 22 procedure Execute; override; 23 23 constructor Create(CreateSuspended: Boolean; … … 33 33 FOnReceiveData: TReceiveDataEvent; 34 34 FReceiveThread: TCommSocketReceiveThread; 35 procedure ReceiveData(Sender: TCommPin; Stream: T Stream);35 procedure ReceiveData(Sender: TCommPin; Stream: TListByte); 36 36 procedure SetActive(const AValue: Boolean); 37 37 public … … 53 53 { TCommTCPClient } 54 54 55 procedure TCommTCPClient.ReceiveData(Sender: TCommPin; Stream:TStream); 55 procedure TCommTCPClient.ReceiveData(Sender: TCommPin; Stream: TListByte); 56 var 57 Mem: TMemoryStream; 56 58 begin 57 59 if FActive then begin 58 Socket.SendStreamRaw(Stream); 60 try 61 Mem := TMemoryStream.Create; 62 Stream.WriteToStream(Mem); 63 Socket.SendStreamRaw(Mem); 64 finally 65 Mem.Free; 66 end; 59 67 end; 60 68 end; … … 120 128 RecvBuffer(Buffer, Length(Buffer)); 121 129 122 Stream.Size := Length(Buffer); 123 Stream.Position := 0; 124 Stream.Write(Buffer[0], Length(Buffer)); 130 Stream.Count := Length(Buffer); 131 Stream.ReplaceBuffer(0, Pointer(Buffer)^, Length(Buffer)); 125 132 Pin.Send(Stream); 126 133 end else InBufferUsed := 0; … … 134 141 begin 135 142 inherited; 136 Stream := T MemoryStream.Create;143 Stream := TListByte.Create; 137 144 end; 138 145 -
PinConnection/UCommTCPServer.pas
r339 r407 7 7 uses 8 8 Classes, SysUtils, blcksock, synsock, UCommPin, UCommon, UThreading, 9 DateUtils, SpecializedList ;9 DateUtils, SpecializedList, tlntsend; 10 10 11 11 type … … 19 19 public 20 20 Parent: TCommTCPServer; 21 Stream: T MemoryStream;21 Stream: TListByte; 22 22 procedure Execute; override; 23 23 constructor Create(CreateSuspended: Boolean; … … 32 32 TCommTCPServerSession = class 33 33 private 34 procedure ReceiveData(Sender: TCommPin; Stream: T Stream);34 procedure ReceiveData(Sender: TCommPin; Stream: TListByte); 35 35 public 36 36 Server: TCommTCPServer; … … 67 67 { TCommTCPServerSession } 68 68 69 procedure TCommTCPServerSession.ReceiveData(Sender: TCommPin; Stream: TStream); 70 begin 71 Socket.SendStreamRaw(Stream); 69 procedure TCommTCPServerSession.ReceiveData(Sender: TCommPin; Stream: TListByte); 70 var 71 Mem: TMemoryStream; 72 begin 73 try 74 Mem := TMemoryStream.Create; 75 Stream.WriteToStream(Mem); 76 Socket.SendStreamRaw(Mem); 77 finally 78 Mem.Free; 79 end; 72 80 end; 73 81 … … 130 138 //if Socket.Socket = INVALID_SOCKET then Break; 131 139 132 Stream.Size := Length(Buffer); 133 Stream.Position := 0; 134 Stream.Write(Buffer[0], Length(Buffer)); 140 Stream.Count := Length(Buffer); 141 Stream.ReplaceBuffer(0, PByte(Buffer)^, Length(Buffer)); 135 142 Pin.Send(Stream); 136 143 DoSleep := False; … … 146 153 begin 147 154 inherited; 148 Stream := T MemoryStream.Create;155 Stream := TListByte.Create; 149 156 end; 150 157 -
PinConnection/UCommThread.pas
r384 r407 7 7 uses 8 8 Classes, SysUtils, blcksock, UCommPin, SyncObjs, UStreamHelper, UCommon, 9 DateUtils, UThreading ;9 DateUtils, UThreading, SpecializedList, UBinarySerializer; 10 10 11 11 type … … 19 19 public 20 20 Parent: TCommThread; 21 Stream: T StreamHelper;21 Stream: TBinarySerializer; 22 22 procedure Execute; override; 23 23 constructor Create(CreateSuspended: Boolean; … … 33 33 FOnReceiveData: TReceiveDataEvent; 34 34 FReceiveThread: TCommThreadReceiveThread; 35 FInputBuffer: T MemoryStream;35 FInputBuffer: TBinarySerializer; 36 36 FInputBufferLock: TCriticalSection; 37 37 FDataAvailable: TEvent; 38 38 FStatusEvent: TEvent; 39 39 FStatusValue: Integer; 40 procedure PinReceiveData(Sender: TCommPin; Stream: T Stream);40 procedure PinReceiveData(Sender: TCommPin; Stream: TListByte); 41 41 procedure PinSetStatus(Sender: TCommPin; Status: Integer); 42 procedure ExtReceiveData(Sender: TCommPin; Stream: T Stream);42 procedure ExtReceiveData(Sender: TCommPin; Stream: TListByte); 43 43 procedure ExtSetStatus(Sender: TCommPin; AStatus: Integer); 44 44 procedure SetActive(const AValue: Boolean); … … 55 55 { TCommThread } 56 56 57 procedure TCommThread.PinReceiveData(Sender: TCommPin; Stream: TStream);57 procedure TCommThread.PinReceiveData(Sender: TCommPin; Stream: TListByte); 58 58 begin 59 59 if FActive then Ext.Send(Stream); … … 65 65 end; 66 66 67 procedure TCommThread.ExtReceiveData(Sender: TCommPin; Stream: TStream); 68 var 69 StreamHelper: TStreamHelper; 67 procedure TCommThread.ExtReceiveData(Sender: TCommPin; Stream: TListByte); 70 68 begin 71 69 try 72 StreamHelper := TStreamHelper.Create(FInputBuffer);73 70 FInputBufferLock.Acquire; 74 StreamHelper.WriteStream(Stream, Stream.Size);71 FInputBuffer.WriteList(Stream, 0, Stream.Count); 75 72 FDataAvailable.SetEvent; 76 73 finally 77 74 FInputBufferLock.Release; 78 StreamHelper.Free;79 75 end; 80 76 end; … … 110 106 begin 111 107 inherited Create; 112 FInputBuffer := TMemoryStream.Create; 108 FInputBuffer := TBinarySerializer.Create; 109 FInputBuffer.List := TListByte.Create; 110 FInputBuffer.OwnsList := True; 113 111 FInputBufferLock := TCriticalSection.Create; 114 112 Ext := TCommPin.Create; … … 150 148 try 151 149 FInputBufferLock.Acquire; 152 Stream.Size := 0; 153 Stream.WriteStream(FInputBuffer, FInputBuffer.Size); 150 Stream.List.Assign(FInputBuffer.List); 154 151 FDataAvailable.ResetEvent; 155 152 FInputBuffer.Clear; … … 157 154 FInputBufferLock.Release; 158 155 end; // else Yield; 159 Pin.Send(Stream );156 Pin.Send(Stream.List); 160 157 end; 161 158 … … 182 179 begin 183 180 inherited; 184 Stream := TStreamHelper.Create; 181 Stream := TBinarySerializer.Create; 182 Stream.List := TListByte.Create; 183 Stream.OwnsList := True; 185 184 end; 186 185 -
PinConnection/UPacketBurst.pas
r231 r407 6 6 7 7 uses 8 Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils, 9 DateUtils ;8 Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils, SpecializedList, 9 DateUtils, UBinarySerializer; 10 10 11 11 type … … 25 25 SendThread: TPacketBurstSendThread; 26 26 SendStreamLock: TCriticalSection; 27 SendStream: T StreamHelper;28 ReceiveStream: T StreamHelper;29 procedure PacketSingleReceive(Sender: TCommPin; Stream: T Stream);30 procedure PacketBurstReceive(Sender: TCommPin; Stream: T Stream);27 SendStream: TBinarySerializer; 28 ReceiveStream: TBinarySerializer; 29 procedure PacketSingleReceive(Sender: TCommPin; Stream: TListByte); 30 procedure PacketBurstReceive(Sender: TCommPin; Stream: TListByte); 31 31 procedure SetActive(const AValue: Boolean); 32 32 public … … 63 63 end; 64 64 65 procedure TPacketBurst.PacketBurstReceive(Sender: TCommPin; Stream: T Stream);65 procedure TPacketBurst.PacketBurstReceive(Sender: TCommPin; Stream: TListByte); 66 66 var 67 PacketStream: T StreamHelper;67 PacketStream: TListByte; 68 68 Size: Word; 69 69 begin 70 70 try 71 PacketStream := T StreamHelper.Create;72 ReceiveStream. Seek(0, soFromEnd);73 ReceiveStream.Write Stream(Stream, Stream.Size);71 PacketStream := TListByte.Create; 72 ReceiveStream.Position := ReceiveStream.List.Count; 73 ReceiveStream.WriteList(Stream, 0, Stream.Count); 74 74 ReceiveStream.Position := 0; 75 75 Size := ReceiveStream.ReadWord; 76 while Size < ReceiveStream. Sizedo begin77 PacketStream. Stream.Size := 0;78 PacketStream.ReadStream(TStream(ReceiveStream), Size);76 while Size < ReceiveStream.List.Count do begin 77 PacketStream.Count := Size; 78 ReceiveStream.ReadList(PacketStream, 0, Size); 79 79 PacketSinglePin.Send(PacketStream); 80 80 Size := ReceiveStream.ReadWord; … … 100 100 end; 101 101 102 procedure TPacketBurst.PacketSingleReceive(Sender: TCommPin; Stream: T Stream);102 procedure TPacketBurst.PacketSingleReceive(Sender: TCommPin; Stream: TListByte); 103 103 var 104 104 SignalEvent: Boolean; … … 106 106 try 107 107 SendStreamLock.Acquire; 108 SendStream.WriteWord(Stream.Size); 109 Stream.Position := 0; 110 SendStream.WriteStream(Stream, Stream.Size); 111 SignalEvent := SendStream.Size > SendBurstSize; 108 SendStream.WriteWord(Stream.Count); 109 SendStream.WriteList(Stream, 0, Stream.Count); 110 SignalEvent := SendStream.List.Count > SendBurstSize; 112 111 finally 113 112 SendStreamLock.Release; … … 120 119 procedure TPacketBurstSendThread.Execute; 121 120 var 122 Stream: T StreamHelper;121 Stream: TListByte; 123 122 begin 124 123 try 125 Stream := T StreamHelper.Create;124 Stream := TListByte.Create; 126 125 with PacketBurst do 127 126 repeat … … 130 129 SendStreamLock.Acquire; 131 130 SendStream.Position := 0; 132 if SendStream. Size< SendBurstSize then begin133 PacketBurstPin.Send(SendStream );134 SendStream. Stream.Size:= 0;131 if SendStream.List.Count < SendBurstSize then begin 132 PacketBurstPin.Send(SendStream.List); 133 SendStream.List.Count := 0; 135 134 end else 136 while (SendStream. Size- SendStream.Position) > SendBurstSize do begin137 Stream. Stream.Size:= 0;135 while (SendStream.List.Count - SendStream.Position) > SendBurstSize do begin 136 Stream.Count := 0; 138 137 SendStream.ReadStream(TStream(Stream), SendBurstSize); 139 138 PacketBurstPin.Send(Stream); -
PinConnection/USerialPort.pas
r404 r407 7 7 uses 8 8 Classes, SysUtils, SynaSer, StdCtrls, Dialogs, UCommon, UThreading, 9 DateUtils, FileUtil ;9 DateUtils, FileUtil, SpecializedList; 10 10 11 11 type … … 19 19 20 20 TSerialPort = class; 21 TReceiveDataEvent = procedure(Stream: T MemoryStream) of object;21 TReceiveDataEvent = procedure(Stream: TListByte) of object; 22 22 23 23 { TSerialPortReceiveThread } … … 45 45 FStopBits: TStopBits; 46 46 FReceiveThread: TSerialPortReceiveThread; 47 FReceiveBuffer: T MemoryStream;47 FReceiveBuffer: TListByte; 48 48 function GetBaudRateNumeric: Integer; 49 49 function GetName: string; … … 70 70 property RTS: Boolean read FRTS write SetRTS; 71 71 property DTR: Boolean read FDTR write SetDTR; 72 property ReceiveBuffer: T MemoryStreamread FReceiveBuffer;72 property ReceiveBuffer: TListByte read FReceiveBuffer; 73 73 74 74 property BaudRateNumeric: Integer read GetBaudRateNumeric write SetBaudRateNumeric; … … 214 214 begin 215 215 inherited Create; 216 FReceiveBuffer := T MemoryStream.Create;216 FReceiveBuffer := TListByte.Create; 217 217 FBaudRate := br9600; 218 218 FName := 'COM1'; … … 335 335 InBufferUsed: Integer; 336 336 Buffer: array of Byte; 337 Read: Integer; 337 338 begin 338 339 InBufferUsed := 0; … … 344 345 if InBufferUsed > 0 then begin 345 346 SetLength(Buffer, InBufferUsed); 346 Re cvBuffer(Buffer, Length(Buffer));347 348 Parent.FReceiveBuffer.Size := Length(Buffer); 349 Parent.FReceiveBuffer. Position := 0;350 Parent.FReceiveBuffer. Write(Buffer[0], Length(Buffer));347 Read := RecvBuffer(Buffer, Length(Buffer)); 348 SetLength(Buffer, Read); 349 350 Parent.FReceiveBuffer.Count := Length(Buffer); 351 Parent.FReceiveBuffer.ReplaceBuffer(0, PByte(Buffer)^, Length(Buffer)); 351 352 if Assigned(Parent.FOnReceiveData) then 352 353 Parent.FOnReceiveData(Parent.FReceiveBuffer);
Note:
See TracChangeset
for help on using the changeset viewer.