Changeset 406
- Timestamp:
- Aug 14, 2012, 10:28:11 AM (12 years ago)
- Location:
- ISPProgrammer
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ISPProgrammer/Dallas/UDallasProgrammer.pas
r370 r406 7 7 uses 8 8 Classes, SysUtils, USerialPort, UCommSerialPort, UCommPin, 9 UJobProgressView, UStreamHelper,SyncObjs, DateUtils, Dialogs, URegistry,10 Forms, UISPProgrammer, Registry ;9 UJobProgressView, SyncObjs, DateUtils, Dialogs, URegistry, 10 Forms, UISPProgrammer, Registry, UBinarySerializer, SpecializedList; 11 11 12 12 const … … 22 22 FOnLogData: TOnLogDataEvent; 23 23 Pin: TCommPin; 24 Response: T StreamHelper; // should be thread safe24 Response: TBinarySerializer; // should be thread safe 25 25 ResponseLock: TCriticalSection; 26 ResponseTemp: T StreamHelper;26 ResponseTemp: TBinarySerializer; 27 27 ReceiveEvent: TEvent; 28 FwSerialPort: TCommSerialPort; 28 SerialPortBackup: TCommSerialPort; 29 SerialPortBackupPin: TCommPin; 29 30 HexData: TStringList; 30 Request: T StreamHelper;31 Request: TBinarySerializer; 31 32 StartTime: TDateTime; 32 33 WaitResult: TWaitResult; 33 procedure ReceiveData(Sender: TCommPin; Stream: T Stream);34 procedure ReceiveData(Sender: TCommPin; Stream: TListByte); 34 35 function WaitForString(EndString: string; Timeout: TDateTime): TWaitResult; 35 36 procedure ResponseClear; 36 37 procedure CheckErrorCode(Value: string); 37 procedure TruncateBeginOfStream(Stream: TStream);38 38 protected 39 39 procedure SetActive(AValue: Boolean); override; … … 74 74 { TDallasProgrammer } 75 75 76 procedure TDallasProgrammer.ReceiveData(Sender: TCommPin; Stream: TStream);76 procedure TDallasProgrammer.ReceiveData(Sender: TCommPin; Stream: TListByte); 77 77 var 78 78 OldPosition: Integer; … … 81 81 ResponseLock.Acquire; 82 82 OldPosition := Response.Position; 83 Response.Position := Response. Size;84 Response.Write Stream(Stream, Stream.Size);83 Response.Position := Response.List.Count; 84 Response.WriteList(Stream, 0, Stream.Count); 85 85 Response.Position := OldPosition; 86 86 finally … … 134 134 inherited; 135 135 if AValue then begin 136 Request := TStreamHelper.Create; 136 Request := TBinarySerializer.Create; 137 Request.List := TListByte.Create; 138 Request.OwnsList := True; 137 139 HexData := TStringList.Create; 138 140 139 141 SerialPort.Active := False; 140 FwSerialPort := TCommSerialPort.Create; 141 FwSerialPort.Name := SerialPort.Name; 142 FwSerialPort.FlowControl := fcNone; 143 FwSerialPort.BaudRate := BaudRate; 144 FwSerialPort.DTR := True; 145 FwSerialPort.Flush; 146 FwSerialPort.Purge; 142 SerialPortBackup.Assign(SerialPort); 143 SerialPortBackupPin := SerialPort.Pin.RemotePin; 144 SerialPort.Pin.Disconnect; 145 146 //SerialPort.Name := SerialPort.Name; 147 SerialPort.FlowControl := fcNone; 148 SerialPort.BaudRate := BaudRate; 149 SerialPort.DTR := True; 150 SerialPort.Pin.Connect(Pin); 151 SerialPort.Flush; 152 SerialPort.Purge; 147 153 ResponseClear; 148 FwSerialPort.Pin.Connect(Pin); 149 FwSerialPort.Active := True; 154 SerialPort.Active := True; 150 155 if Assigned(FOnLogData) then 151 156 Pin.OnLogData := FOnLogData; … … 153 158 ReadIdentification; 154 159 end else begin 155 FwSerialPort.Free; 160 SerialPort.Active := False; 161 SerialPort.Assign(SerialPortBackup); 162 SerialPort.Pin.Connect(SerialPortBackupPin); 156 163 SerialPort.Active := True; 157 164 HexData.Free; … … 174 181 end; 175 182 176 procedure TDallasProgrammer.TruncateBeginOfStream(Stream: TStream);177 begin178 // Delete start of Response stream179 //Stream.Position := Stream.Position - 1;180 if (Stream.Size - Stream.Position) > 0 then begin181 ResponseTemp.Clear;182 ResponseTemp.CopyFrom(Stream, Stream.Size - Stream.Position);183 Stream.Size := 0;184 ResponseTemp.Position := 0;185 Stream.CopyFrom(ResponseTemp, ResponseTemp.Size);186 Stream.Position := 0;187 end else Stream.Size := 0;188 end;189 190 183 procedure TDallasProgrammer.LoadFromRegistry(Root: HKEY; Key: string); 191 184 begin … … 219 212 Active := True; 220 213 221 Request. Size:= 0;214 Request.List.Count := 0; 222 215 ResponseClear; 223 216 Request.WriteByte(Ord('D')); 224 217 Request.WriteByte($0D); 225 Pin.Send(Request );218 Pin.Send(Request.List); 226 219 if WaitForString(NewLine, Timeout) <> wrSignaled then begin 227 220 raise Exception.Create(STimeout); … … 230 223 try 231 224 ResponseLock.Acquire; 232 TruncateBeginOfStream(Response); 225 Response.List.DeleteItems(0, Response.Position); 226 Response.Position := 0; 233 227 finally 234 228 ResponseLock.Release; … … 256 250 Value := Response.ReadStringTerminated(NewLine); 257 251 if Value <> '' then begin 258 TruncateBeginOfStream(Response); 252 Response.List.DeleteItems(0, Response.Position); 253 Response.Position := 0; 259 254 //Log(Value); 260 255 HexData.Add(Value); … … 269 264 if Job.Terminate then Break; 270 265 until False; 271 //for I := 0 to HexData.Count - 1 do266 //for I := 0 to 10 do //HexData.Count - 1 do 272 267 // Log(HexData[I]); 273 268 if not Job.Terminate then … … 282 277 Active := True; 283 278 284 Request. Size:= 0;279 Request.List.Count := 0; 285 280 ResponseClear; 286 281 Request.WriteByte(Ord('V')); 287 282 Request.WriteByte($0D); 288 Pin.Send(Request );283 Pin.Send(Request.List); 289 284 if WaitForString(NewLine, Timeout) <> wrSignaled then begin 290 Pin.Send(Request );285 Pin.Send(Request.List); 291 286 raise Exception.Create(STimeout); 292 287 end; … … 294 289 Job.Progress.Max := HexData.Count; 295 290 for I := 0 to HexData.Count - 1 do begin 296 Request. Size:= 0;291 Request.List.Count := 0; 297 292 ResponseClear; 298 293 Request.WriteString(HexData[I]); 299 294 Request.WriteByte($0D); 300 Pin.Send(Request );295 Pin.Send(Request.List); 301 296 if ReceiveEvent.WaitFor(Round(Timeout / OneMillisecond)) <> wrSignaled then 302 297 raise Exception.Create(STimeout); … … 304 299 ResponseLock.Acquire; 305 300 Response.Position := 0; 306 if Response. Size= 0 then301 if Response.List.Count = 0 then 307 302 raise Exception.Create(SEmptyBuffer); 308 303 Value := Chr(Response.ReadByte); … … 322 317 begin 323 318 Active := True; 324 325 Request.Size := 0; 319 Request.Clear; 326 320 ResponseClear; 327 321 Request.WriteByte(Ord('L')); 328 322 Request.WriteByte($0D); 329 Pin.Send(Request );323 Pin.Send(Request.List); 330 324 if WaitForString(NewLine, Timeout) <> wrSignaled then begin 331 Pin.Send(Request );325 Pin.Send(Request.List); 332 326 raise Exception.Create(STimeout); 333 327 end; … … 335 329 Job.Progress.Max := HexData.Count; 336 330 for I := 0 to HexData.Count - 1 do begin 337 Request. Size:= 0;331 Request.List.Count := 0; 338 332 ResponseClear; 339 333 Request.WriteString(HexData[I]); 340 334 Request.WriteByte($0D); 341 Pin.Send(Request );335 Pin.Send(Request.List); 342 336 if ReceiveEvent.WaitFor(Round(Timeout / OneMillisecond)) <> wrSignaled then 343 337 raise Exception.Create(STimeout); … … 345 339 ResponseLock.Acquire; 346 340 Response.Position := 0; 347 if Response. Size= 0 then341 if Response.List.Count = 0 then 348 342 raise Exception.Create(SEmptyBuffer); 349 343 Value := Chr(Response.ReadByte); … … 360 354 begin 361 355 Active := True; 362 363 Request.Size := 0; 356 Request.Clear; 364 357 ResponseClear; 365 358 Request.WriteByte(Ord('K')); 366 359 Request.WriteByte($0D); 367 Pin.Send(Request );360 Pin.Send(Request.List); 368 361 if WaitForString('>', Timeout) <> wrSignaled then 369 362 raise Exception.Create(STimeout); … … 387 380 repeat 388 381 ResponseClear; 389 Request. Size:= 0;382 Request.List.Count := 0; 390 383 Request.WriteByte($0D); 391 Pin.Send(Request );384 Pin.Send(Request.List); 392 385 WaitResult := WaitForString('>', Timeout); 393 386 until (WaitResult = wrSignaled) or ((Now - StartTime) > InitTimeout); … … 412 405 Timeout := 3000 * OneMillisecond; 413 406 ReceiveEvent := TSimpleEvent.Create; 414 Response := TStreamHelper.Create; 407 Response := TBinarySerializer.Create; 408 Response.List := TListByte.Create; 409 Response.OwnsList := True; 415 410 ResponseLock := TCriticalSection.Create; 416 ResponseTemp := TStreamHelper.Create; 411 ResponseTemp := TBinarySerializer.Create; 412 ResponseTemp.List := TListByte.Create; 413 ResponseTemp.OwnsList := True; 417 414 Pin := TCommPin.Create; 418 415 Pin.OnReceive := ReceiveData; 419 416 BaudRate := br9600; 417 SerialPortBackup := TCommSerialPort.Create; 420 418 end; 421 419 422 420 destructor TDallasProgrammer.Destroy; 423 421 begin 422 Active := False; 423 SerialPortBackup.Free; 424 424 Pin.Free; 425 425 Response.Free; -
ISPProgrammer/UISPProgrammer.pas
r370 r406 20 20 private 21 21 FActive: Boolean; 22 FOnActivate: TNotifyEvent; 23 FOnDeactivate: TNotifyEvent; 22 24 FOnLog: TLogEvent; 23 25 FCPUType: TCPUType; … … 45 47 property Active: Boolean read FActive write SetActive; 46 48 property CPUType: TCPUType read GetCPUType write SetCPUType; 49 property OnActivate: TNotifyEvent read FOnActivate write FOnActivate; 50 property OnDeactivate: TNotifyEvent read FOnDeactivate write FOnDeactivate; 47 51 end; 48 52 … … 68 72 if FActive = AValue then Exit; 69 73 FActive := AValue; 74 if AValue then begin 75 if Assigned(FOnActivate) then 76 FOnActivate(Self); 77 end else begin 78 if Assigned(FOnDeactivate) then 79 FOnDeactivate(Self); 80 end; 70 81 end; 71 82
Note:
See TracChangeset
for help on using the changeset viewer.