1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, CPort, StdCtrls, CPortCtl, ExtCtrls, Vcl.ComCtrls, Vcl.Grids;
type
TForm1 = class(TForm)
Panel1: TPanel;
ComLed1: TComLed;
ComLed2: TComLed;
u: TComLed;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
btnConnecter: TButton;
ComComboBox1: TComComboBox;
ComComboBox2: TComComboBox;
ComComboBox3: TComComboBox;
ComComboBox4: TComComboBox;
ComComboBox5: TComComboBox;
Panel2: TPanel;
Memo1: TMemo;
ComPort1: TComPort;
BoutonLire: TButton;
ButtonEcrire: TButton;
ButtonEffacer: TButton;
ButtonVérifier: TButton;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
ProgressBarLecture: TProgressBar;
ProgressBarEffacer: TProgressBar;
ProgressBarEcrire: TProgressBar;
ProgressBarVerifier: TProgressBar;
ButtonEnregistrer: TButton;
ButtonOuvrir: TButton;
StrGrd: TStringGrid;
procedure FormCreate(Sender: TObject);
procedure ComPort1RxChar(Sender: TObject; Count: Integer);
procedure ComPort1AfterOpen(Sender: TObject);
procedure btnConnecterClick(Sender: TObject);
procedure BoutonLireClick(Sender: TObject);
procedure ButtonEffacerClick(Sender: TObject);
procedure ButtonEcrireClick(Sender: TObject);
procedure ButtonVérifierClick(Sender: TObject);
procedure ButtonOuvrirClick(Sender: TObject);
procedure StrGrdClick(Sender: TObject);
procedure StrGrdDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
procedure ButtonEnregistrerClick(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
var
Form1: TForm1;
N_BuFFer, Col_Cell : integer;
Var Chaine:String;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
StrGrd.ColWidths[0] := 50; // Largeur colonne[0]
StrGrd.ColWidths[17] := 100; // Largeur colonne[9]
Memo1.Lines.Clear;
Comport1.Timeouts.ReadTotalConstant := 2000;
N_BuFFer := 1898232;
StrGrd.RowCount := 118640
end;
procedure TForm1.StrGrdClick(Sender: TObject);
begin
end;
//////////////// lire /////////////////////////////////////////////////////
procedure TForm1.BoutonLireClick(Sender: TObject);
var Long,Li,i, L, K :Integer;
S,Res :string;
begin
boutonLire.Enabled := True;
buttonEcrire.Enabled := false;
buttonEffacer.Enabled := false;
buttonVérifier.Enabled := false;
with ProgressBarlecture do Position := 0;
with ProgressBarEcrire do Position := 0;
with ProgressBarEffacer do Position := 0;
with ProgressBarVerifier do Position := 0;
ProgressBarLecture.Min := 0;
ProgressBarLecture.Max := N_BuFFer -1;
Memo1.lines.add ('Lecture');
for L := 0 to StrGrd.RowCount do StrGrd.Cells[0,L] := inttohex(L * 16,4) + ':' ; // Ecrire l'adresse dans la cell[0,x]
ComPort1.WriteStr('l');
Comport1.ClearBuffer(True,False); // Supression de ce qui traine dans le buffer d'entrée
for L := 0 to N_BuFFer -1 do // Lire toute la mémoire
begin
Application.ProcessMessages; // Ne pas figer l'appli
ProgressBarLecture.Position := L; // Progressbar avance
Comport1.ReadStr(Chaine,1); // Lecture bloquante de la longueur demandée
Res:='';
Res:=Res+IntToHex(Ord(Chaine[1]),2)+' '; //string to Hex
K := L mod 16 + 1; // Position colonne en cours
StrGrd.Cells[K,L div 16] :=chaine; // Valeur lue dans cellule
/////////////// erreurs ////////////////////////////////////////////////////////
// if strtoint('$' + StrGrd.Cells[K,L div 16]) > 32 then StrGrd.Cells[17,L div 16] := StrGrd.Cells[17,L div 16] + chr(strtoint('$' + copy(StrGrd.Cells[K,L div 16],3,2)))
// else StrGrd.Cells[17,L div 16] := StrGrd.Cells[17,L div 16] + '.';
/////////////////////////////////////////////////////////////////////////////////
end ;
boutonLire.Enabled := True;
buttonEcrire.Enabled := True;
buttonEffacer.Enabled := True;
buttonVérifier.Enabled := True;
end;
////////////////////////////////////////////////////////////////////////////////
procedure TForm1.btnConnecterClick(Sender: TObject);
begin
Comport1.Connected := Not Comport1.Connected;
end;
////////////////////////////////////////////////////////////////////////////////////
procedure TForm1.ComPort1AfterOpen(Sender: TObject);
begin
btnConnecter.Enabled := True;
boutonLire.Enabled := True;
buttonEcrire.Enabled := True;
buttonEffacer.Enabled := True;
buttonVérifier.Enabled := True;
end;
procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
Var Chaine:String;
begin
ComPort1.ReadStr(Chaine,Count);
Memo1.Lines.Text := Memo1.Lines.Text + Chaine;
end;
/////////////// Ecrire /////////////////////////////////////////////////////////////////
procedure TForm1.ButtonEcrireClick(Sender: TObject);
var Long,Li,i, L, K :Integer;
s ,Res:string;
label attend;
begin
boutonLire.Enabled := false;
buttonEcrire.Enabled := True;
buttonEffacer.Enabled := false;
buttonVérifier.Enabled := false;
ProgressBarlecture.Position := 0;
ProgressBarEcrire.Position := 0;
ProgressBarEffacer.Position := 0;
ProgressBarVerifier.Position := 0;
ProgressBarEcrire.Min := 0;
ProgressBarEcrire.Max := N_BuFFer -1;
ComPort1.WriteStr('e');
for L := 0 to N_BuFFer -1 do // ecrire toute la mémoire
begin
Application.ProcessMessages; // Ne pas figer l'appli
ProgressBarEcrire.Position := L; // Progressbar avance
s:= StrGrd.Cells[L mod 16 + 1,L div 16 ];
Res:='' ;
Li := Length(s);
If Li = 0 Then Exit;
for i := 1 to Length(s) do Res:=Res+IntToHex(Ord(s[i]),2)+' ';
Memo1.lines.Text := Memo1.lines.Text + (' res='+Res);
Memo1.lines.Text := Memo1.lines.Text + (' s='+s);
Comport1.WriteStr(s); // Valeur a ecrire
//Comport1.WriteStr(Res); // Valeur a ecrire
attend:
Comport1.ClearBuffer(True,False); // Supression de ce qui traine dans le buffer d'entrée
Long:=Comport1.ReadStr(Chaine,1);
//Comport1.ReadStr(Chaine,1);
Memo1.lines.Text := Memo1.lines.Text + (' octet='+Chaine);
// if Chaine <> 'w' then goto attend ;
end ;
end;
//////////////////////////////////////////////////////////////////////////////////////////
//////////////////////// Effacer /////////////////////////////////////////////////////////
procedure TForm1.ButtonEffacerClick(Sender: TObject);
var Long:Integer;
begin
boutonLire.Enabled := false;
buttonEcrire.Enabled := false;
buttonEffacer.Enabled := True;
buttonVérifier.Enabled := false;
with ProgressBarlecture do Position := 0;
with ProgressBarEcrire do Position := 0;
with ProgressBarEffacer do Position := 0;
with ProgressBarVerifier do Position := 0;
ComPort1.WriteStr('z');
Comport1.ClearBuffer(True,False); // Supression de ce qui traine dans le buffer d'entrée
Long:=Comport1.ReadStr(Chaine,2); // Lecture bloquante de la longueur demandée
Memo1.lines.Text := Memo1.lines.Text+(' Efface='+Chaine);
if (Chaine = 'ok') then
begin
with ProgressBarEffacer do
begin
Min := 0;
Max := 100;
Position := 100;
end;
boutonLire.Enabled := True;
buttonEcrire.Enabled := True;
buttonEffacer.Enabled := True;
buttonVérifier.Enabled := True;
end;
///////////////////////////////////////////////////////////////////////////////////////////////
end;
procedure TForm1.ButtonEnregistrerClick(Sender: TObject);
var fichier: textfile;
i,t,CHKSUM:integer;
S:string;
begin
// Enregistrer au Format BIN
assignfile(fichier ,SaveDialog1.FileName + '.bin');// Ouverture du fichier
Rewrite(fichier); // Créer ou Ecraser le fichier
for i := 0 to (N_BuFFer div 16)-1 do // Pour tout le buffer
for t := 1 to 16 do // Traiter par bloc de 16
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////ERREUR $ n'est pas une entrée valide ///////////////////////////////////////////////////////////////
// if t <= 8 then Write(fichier,chr(strtoint('$' + StrGrd.Cells[t,i * 2])))
// else Write(fichier,chr(strtoint('$' + StrGrd.Cells[t - 8,i * 2 + 1])));
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
closefile(fichier); // Fermer le fichier
end;
procedure TForm1.ButtonOuvrirClick(Sender: TObject);
var fichier: file;
fichierT: textfile;
L,i,row,col,DbutAdr,Nb_BYT,Num_Adr:integer;
unByte:byte;
S,n:string;
Label erreur,ok,fin;
begin
if OpenDialog1.Execute then
begin
// Ecrire l'adresse dans la cell[0,x]
for L := 0 to StrGrd.RowCount do StrGrd.Cells[0,L] := inttohex(L * 16,4) + ':' ;
// Ouvrir au Format BIN <= ///////////////////////////////
assignfile(fichier ,OpenDialog1.FileName); // Ouverture du fichier
Reset(fichier,1); // Début du fichier + format (1 byte)
for i:= 0 to N_BuFFer - 1 do // Remplir tout le stringgrid
begin
if Eof(fichier) then goto fin; // Si fin du fichier sortir
BlockRead(fichier, unByte, 1); // Lire un byte du fichier
// Modifier cell Hex correspondante
StrGrd.cells[(i mod 16) + 1,i div 16] := IntToHex(unByte,2);
// StrGrd.cells[(i mod 16) + 1,i div 16] := unByte;
// Modifier cell ASCII correspondante
S := StrGrd.cells[17,i div 16]; // Sauver l'ASCII StringGrid
// pour reconstruction
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////ERREUR $ n'est pas une entrée valide ///////////////////////////////////////////////////////////////
//// if unByte > 32 then S[i mod 16 + 1] := chr(strtoint('$'+copy(StrGrd.Cells[(i mod 16) + 1,i div 16],3,2)))
///// else S[i mod 16 + 1] := '.';
/// //////////////////////////////////////////////////////////////////////////////////////////////////
StrGrd.Cells[17,i div 16] := S; // Recharger l'ASCII StringGrid
end;
fin:
closefile(fichier); // Fermer le fichier
end;
end;
procedure TForm1.ButtonVérifierClick(Sender: TObject);
begin
with ProgressBarVerifier do
begin
Min := 0;
Max := 100;
Position := 100;
end;
end;
////////////////////////////
// Relook de Stringrid ....
procedure TForm1.StrGrdDrawCell(Sender: TObject; ACol, ARow: Integer;
Rect: TRect; State: TGridDrawState);
begin
With Sender as TStringGrid do With Canvas Do
begin
if gdSelected In State Then // fond si sélectioné
if (ACol = 18) then Brush.Color := $0098F9FE else Brush.Color := $00FFFFC6
else // Permuter couleur de fond si pas sélection
If Odd(ARow) Then Brush.Color := $00D9EFFB
else Brush.Color := $FFFFE0;
if (ACol = 18) then canvas.font.color := clmaroon; // Couleur ascii
If gdSelected In State Then Font.Color := clblack; // Couleur HEX
if (ACol = 0) then canvas.font.color := clblue; // Couleur ADRESSE
// Dessin du texte centré
FillRect(Rect);
DrawText(Canvas.Handle, PChar(Cells[ACol,ARow]), -1, Rect ,
DT_CENTER or DT_NOPREFIX or DT_VCENTER or DT_SINGLELINE );
end;
end;
end. |
Partager