Changeset 417 for ISPProgrammer


Ignore:
Timestamp:
Aug 20, 2012, 2:47:30 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Classs TDallasProgrammer in ISPProgrammer package now user generalized property Connector for communication with serial port combinations.
Location:
ISPProgrammer
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ISPProgrammer/Dallas/UDallasProgrammer.pas

    r413 r417  
    99  UJobProgressView, SyncObjs, DateUtils, Dialogs, URegistry,
    1010  Forms, UISPProgrammer, Registry, UBinarySerializer, SpecializedList,
    11   UCommTelnet;
     11  UCommTelnet, UCommTCPClient, UCommTelnetComPortOption, UCommConnector;
    1212
    1313const
     
    2727    ResponseLock: TCriticalSection;
    2828    ResponseTemp: TBinarySerializer;
    29     SerialPortBackup: TCommSerialPort;
    30     SerialPortBackupPin: TCommPin;
     29    ConnectorBackup: TDeviceConnector;
     30    ConnectorBackupPin: TCommPin;
    3131    HexData: TStringList;
    3232    Request: TBinarySerializer;
     
    3636    function ResponseCount: Integer;
    3737    procedure ResponseClear;
    38     procedure CheckErrorCode(Value: string);
     38    procedure CheckWriteErrorCode(Value: string);
     39    procedure CheckResponseErrorCode(Value: string);
    3940  protected
    4041    procedure SetActive(AValue: Boolean); override;
     
    4344    Identification: string;
    4445    BaudRate: Integer;
     46    Connector: TDeviceConnector;
    4547    procedure LoadFromRegistry(Root: HKEY; Key: string); override;
    4648    procedure SaveToRegistry(Root: HKEY; Key: string); override;
     
    139141  SerialPort: TCommSerialPort;
    140142  Telnet: TCommTelnet;
     143  TelnetOption: TTelnetOptionComPort;
    141144begin
    142145  if Active = AValue then Exit;
     
    148151    HexData := TStringList.Create;
    149152
    150     if ExtPin.Connected and (ExtPin.RemotePin.Node is TCommSerialPort) then begin
    151       SerialPort := TCommSerialPort(ExtPin.RemotePin.Node);
    152       SerialPort.Active := False;
    153       SerialPortBackup.Assign(SerialPort);
    154       SerialPortBackupPin := SerialPort.Pin.RemotePin;
    155       SerialPort.Pin.Disconnect;
    156 
     153    Connector.Active := False;
     154    ConnectorBackup.Assign(Connector);
     155    ConnectorBackupPin := Connector.Pin.RemotePin;
     156    Connector.Pin.Disconnect;
     157    if Connector.ConnectionType = ctSerialPort then begin
    157158      //SerialPort.Name := SerialPort.Name;
    158       SerialPort.SerialPort.FlowControl := fcNone;
    159       SerialPort.SerialPort.BaudRate := BaudRate;
    160       SerialPort.SerialPort.DTR := True;
    161       SerialPort.Pin.Connect(CommMark.PinRaw);
    162       SerialPort.SerialPort.Flush;
    163       SerialPort.SerialPort.Purge;
    164       SerialPort.Active := True;
    165       if Assigned(FOnLogData) then
    166         Pin.OnLogData := FOnLogData;
    167     end;
    168     if ExtPin.Connected and (ExtPin.RemotePin.Node is TCommTelnet) then begin
    169       Telnet := TCommTelnet(ExtPin.RemotePin.Node);
    170     end;
     159      Connector.CommSerial.SerialPort.FlowControl := fcNone;
     160      Connector.CommSerial.SerialPort.BaudRate := BaudRate;
     161      Connector.CommSerial.SerialPort.DTR := True;
     162      Connector.CommSerial.SerialPort.Flush;
     163    end else
     164    if Connector.ConnectionType = ctNetworkClient then begin
     165      TelnetOption := TTelnetOptionComPort(Connector.CommTelnet.SearchOption(tmComPortControlOption));
     166      TelnetOption.FlowControl := fcNone;
     167      TelnetOption.BaudRate := BaudRate;
     168      TelnetOption.DTR := True;
     169    end;
     170    Connector.CommSerial.SerialPort.Purge;
     171    Connector.CommTelnet.Purge;
     172    Connector.Pin.Connect(CommMark.PinRaw);
     173    if Assigned(FOnLogData) then
     174      Pin.OnLogData := FOnLogData;
     175    CommMark.Active := True;
     176    Connector.Active := True;
    171177    ResponseClear;
    172     CommMark.Active := True;
     178    Sleep(1000);
    173179    ReadIdentification;
    174180  end else begin
    175181    CommMark.Active := False;
    176     if ExtPin.Connected and (ExtPin.RemotePin.Node is TCommSerialPort) then begin
    177       SerialPort := TCommSerialPort(ExtPin.Node);
    178       SerialPort.Active := False;
    179       SerialPort.Assign(SerialPortBackup);
    180       SerialPort.Pin.Connect(SerialPortBackupPin);
    181       SerialPort.Active := True;
    182     end;
    183     if ExtPin.Connected and (ExtPin.RemotePin.Node is TCommTelnet) then begin
    184       Telnet := TCommTelnet(ExtPin.RemotePin.Node);
    185     end;
     182    Connector.Active := False;
     183    Connector.Assign(ConnectorBackup);
     184    Connector.Pin.Connect(ConnectorBackupPin);
     185    Connector.Active := True;
    186186    HexData.Free;
    187187    Request.Free;
     
    189189end;
    190190
    191 procedure TDallasProgrammer.CheckErrorCode(Value: string);
     191procedure TDallasProgrammer.CheckWriteErrorCode(Value: string);
    192192begin
    193193  if Value = 'H' then raise Exception.Create(SInvalidHexFormat)
     
    203203end;
    204204
     205procedure TDallasProgrammer.CheckResponseErrorCode(Value: string);
     206begin
     207  if Value <> '' then begin
     208    if Value[1] = 'E' then
     209      raise Exception.Create('Dallas error: ' + Value);
     210  end;
     211end;
     212
    205213procedure TDallasProgrammer.LoadFromRegistry(Root: HKEY; Key: string);
    206214begin
     
    239247  Pin.Send(Request.List);
    240248  Value := ReadResponse;
    241   ReadResponse; // Empty line
     249  Value := ReadResponse; // Empty line
     250  CheckResponseErrorCode(Value);
    242251
    243252  //HexFile.SaveToStringList(HexData);
     
    287296      Pin.Send(Request.List);
    288297      Value := ReadResponse;
    289       CheckErrorCode(Value);
     298      CheckWriteErrorCode(Value);
    290299      Job.Progress.Value := I;
    291300      if Job.Terminate then Break;
     
    319328      Pin.Send(Request.List);
    320329      Value := ReadResponse;
    321       CheckErrorCode(Value);
     330      CheckWriteErrorCode(Value);
    322331      Job.Progress.Value := I;
    323332      if Job.Terminate then Break;
     
    335344  Request.WriteByte(Ord('K'));
    336345  Pin.Send(Request.List);
    337   ReadResponse;
     346  CheckResponseErrorCode(ReadResponse);
    338347end;
    339348
     
    354363  Request.Clear;
    355364  Pin.Send(Request.List);
    356   ReadResponse; // Empty line
     365  Value := ReadResponse; // Empty line
    357366  Identification := ReadResponse;
    358   Result := Identification;
     367
    359368  Log(SIdentification + ': ' + Identification);
    360369end;
     
    378387  CommMark.PinFrame.Connect(Pin);
    379388  BaudRate := 9600;
    380   SerialPortBackup := TCommSerialPort.Create(nil);
     389  ConnectorBackup := TDeviceConnector.Create;
    381390end;
    382391
     
    384393begin
    385394  Active := False;
    386   Mark.Free;
    387   CommMark.Free;
    388   SerialPortBackup.Free;
    389   Pin.Free;
    390   ResponseQueue.Free;
    391   ResponseLock.Free;
    392   ResponseTemp.Free;
    393   inherited Destroy;
     395  FreeAndNil(Mark);
     396  FreeAndNil(CommMark);
     397  FreeAndNil(ConnectorBackup);
     398  FreeAndNil(Pin);
     399  FreeAndNil(ResponseQueue);
     400  FreeAndNil(ResponseLock);
     401  FreeAndNil(ResponseTemp);
     402  inherited;
    394403end;
    395404
  • ISPProgrammer/PRESTO/UPresto.pas

    r414 r417  
    88
    99uses
    10   Classes, SysUtils, UISPProgrammer, UPrestoDLL,
     10  Classes, SysUtils, UISPProgrammer, UPrestoDLL, UCommPin,
    1111  UStreamHelper, Globals, Processors, Delays, UCPUType, Registry,
    1212  UJobProgressView;
  • ISPProgrammer/UISPProgrammer.pas

    r414 r417  
    3232    FileName: string;
    3333    Capabilities: TISPProgCapabilities;
    34     ExtPin: TCommPin;
    3534    procedure Log(Text: string);
    3635    procedure LoadFromRegistry(Root: HKEY; Key: string); virtual;
     
    130129constructor TISPProgrammer.Create;
    131130begin
    132   ExtPin := TCommPin.Create;
     131  //ExtPin := TCommPin.Create;
    133132  HexFile := TIntelHexFile.Create;
    134133  HexFile.BytePerLine := 20;
     
    138137begin
    139138  Active := False;
    140   FreeAndNil(ExtPin);
     139  //FreeAndNil(ExtPin);
    141140  FreeAndNil(HexFile);
    142141  inherited Destroy;
Note: See TracChangeset for help on using the changeset viewer.