Changeset 438 for ISPProgrammer/Dallas
- Timestamp:
- Nov 19, 2012, 2:38:16 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ISPProgrammer/Dallas/UDallasProgrammer.pas
r417 r438 9 9 UJobProgressView, SyncObjs, DateUtils, Dialogs, URegistry, 10 10 Forms, UISPProgrammer, Registry, UBinarySerializer, SpecializedList, 11 UCommTelnet, UCommT CPClient, UCommTelnetComPortOption, UCommConnector;11 UCommTelnet, UCommTelnetComPortOption, UCommConnector; 12 12 13 13 const … … 33 33 Mark: TListByte; 34 34 procedure ReceiveData(Sender: TCommPin; Stream: TListByte); 35 function ReadResponse : string;35 function ReadResponse(Count: Integer = 0): string; 36 36 function ResponseCount: Integer; 37 37 procedure ResponseClear; … … 62 62 resourcestring 63 63 STimeout = 'Timeout'; 64 SEmptyBuffer = 'Empty buffer';64 //SEmptyBuffer = 'Empty buffer'; 65 65 SInvalidHexFormat = 'Invalid Intel Hex record format'; 66 66 SFlashControllerError = 'Flash controller error'; … … 79 79 procedure TDallasProgrammer.ReceiveData(Sender: TCommPin; Stream: TListByte); 80 80 var 81 OldPosition: Integer;82 81 NewList: TListByte; 83 82 begin … … 92 91 end; 93 92 94 function TDallasProgrammer.ReadResponse : string;93 function TDallasProgrammer.ReadResponse(Count: Integer = 0): string; 95 94 var 96 95 Serializer: TBinarySerializer; … … 100 99 StartTime := Now; 101 100 repeat 102 if ResponseCount > 0 then Break; 101 if Count = 0 then begin 102 if ResponseCount > 0 then Break; 103 end else begin 104 if ResponseCount >= Count then Break; 105 end; 106 Sleep(1); 103 107 ElapsedTime := Now - StartTime; 104 108 until (ElapsedTime > Timeout); … … 109 113 Serializer := TBinarySerializer.Create; 110 114 Serializer.List := TListByte(ResponseQueue.First); 111 Result := Serializer.ReadString(Serializer.List.Count); 115 if Count = 0 then 116 Result := Serializer.ReadString(Serializer.List.Count) 117 else Result := Serializer.ReadString(Count); 112 118 ResponseQueue.Delete(0); 113 119 finally … … 140 146 var 141 147 SerialPort: TCommSerialPort; 142 Telnet: TCommTelnet;143 148 TelnetOption: TTelnetOptionComPort; 144 149 begin … … 217 222 RootKey := Root; 218 223 OpenKey(Key + '\ISPProgrammer\Dallas', True); 219 BaudRate := ReadIntegerWithDefault('FirmwareBaudRate ', 57600);224 BaudRate := ReadIntegerWithDefault('FirmwareBaudRateNumeric', 57600); 220 225 finally 221 226 Free; … … 229 234 RootKey := Root; 230 235 OpenKey(Key + '\ISPProgrammer\Dallas', True); 231 WriteInteger('FirmwareBaudRate ', Integer(BaudRate));236 WriteInteger('FirmwareBaudRateNumeric', Integer(BaudRate)); 232 237 finally 233 238 Free; … … 321 326 HexFile.SaveToStringList(HexData); 322 327 Job.Progress.Max := HexData.Count; 323 for I := 0 to HexData.Count - 1 do begin 324 Request.Clear; 325 ResponseClear; 326 Request.WriteString(HexData[I]); 327 Request.WriteList(Mark, 0, Mark.Count); 328 Pin.Send(Request.List); 329 Value := ReadResponse; 330 CheckWriteErrorCode(Value); 328 // Delayed response check mechanism, 329 // to avoid thread sleep(1) to context switch after 16 ms 330 // During 16 ms delay: 57600 / 10 * 0.016 = 97 bytes can be transfered 331 // One line of hex file is 74 bytes long 332 // Then two during context switching next line should be written to output buffer 333 // On I = 0 do not check response 334 // On I = HexData.Count do not send data, only check response 335 ResponseClear; 336 for I := 0 to HexData.Count do begin 337 if I < HexData.Count then begin 338 Request.Clear; 339 Request.WriteString(HexData[I]); 340 Request.WriteList(Mark, 0, Mark.Count); 341 Pin.Send(Request.List); 342 end; 343 if I > 0 then begin 344 Value := ReadResponse; 345 CheckWriteErrorCode(Value); 346 end; 331 347 Job.Progress.Value := I; 332 348 if Job.Terminate then Break; … … 353 369 function TDallasProgrammer.ReadIdentification: string; 354 370 var 355 InitTimeout: TDateTime;356 371 Value: string; 357 372 begin 358 373 Result := ''; 359 InitTimeout := 6000 * OneMillisecond;360 374 Active := True; 361 375 … … 365 379 Value := ReadResponse; // Empty line 366 380 Identification := ReadResponse; 381 382 // Make one empty command to clear possible previous data 383 ResponseClear; 384 Request.Clear; 385 Pin.Send(Request.List); 386 Value := ReadResponse; // Empty line 367 387 368 388 Log(SIdentification + ': ' + Identification);
Note:
See TracChangeset
for help on using the changeset viewer.