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 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, CPort, CPortCtl, ComCtrls, jpeg, Menus;
type
TForm1 = class(TForm)
ComPort1: TComPort;
Timer1: TTimer;
ComLed3: TComLed;
Label3: TLabel;
Timer2: TTimer;
Edit1: TEdit;
Edit2: TEdit;
Image1: TImage;
Button4: TButton;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
MainMenu1: TMainMenu;
Fichier1: TMenuItem;
Quitter1: TMenuItem;
Aide1: TMenuItem;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
RichEditRecept: TRichEdit;
RichEditLog: TRichEdit;
RichEdit_OPR: TRichEdit;
Label4: TLabel;
GroupBox3: TGroupBox;
Choix_page: TRadioGroup;
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure ComPort1RxChar(Sender: TObject; Count: Integer);
procedure Button4Click(Sender: TObject);
procedure Quitter1Click(Sender: TObject);
procedure Aide1Click(Sender: TObject);
procedure RichEditReceptChange(Sender: TObject);
procedure RichEditLogChange(Sender: TObject);
procedure RichEdit_OPRChange(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Choix_pageClick(Sender: TObject);
private
{ Private declarations }
MonMessage : String;
procedure Env_Eve_Local;
procedure Env_Alm_Local;
procedure Env_opr_Local;
procedure Env_Eve_X;
procedure Env_Alm_X;
procedure Env_Opr_X;
procedure Ecriture_et_couleur_OPR;
procedure Ecriture_et_couleur_ALM;
procedure Ecriture_et_couleur_ACK;
procedure Ecriture_et_couleur_RTN;
procedure Ecriture_et_couleur_ALM_20_0h;
procedure Ecriture_et_couleur_ACK_20_0h;
procedure Ecriture_et_couleur_RTN_20_0h;
procedure Effacement_ecran_et_compteur_RichEdit_Log_20_0h;
procedure retour_auto_page;
public
{ Public declarations }
end;
var
Form1: TForm1;
AllowedDateTime: string;
NomFichEvenement, NomFichEvenement1: string;
ExtRecept, ExtInhi: string;
NomFichInhi, NomFichInhi1 : String;
NomFichAlarme, NomFichAlarme1 : string;
ExtLog : string;
LegalDateTime : string;
TrameCp : string;
Cpt_ALM, Cpt_Evt, Cpt_Alm_Inhi,Cpt_Alm_20_0h,Imp_20_0h,tempo_Retour: integer;
implementation
uses Unit2,Unit3;
{$R *.dfm}
procedure TForm1.Timer1Timer(Sender: TObject); // Gestion du Port Com
begin
If comport1.Port = 'COM1'
Then
begin
comport1.SetDTR(true); // met à l'état de travail "0" la sortie DTR (+10V)
comport1.SetRTS(true); // met à l'état de travail "0" la sortie RTS (+10V)
end
Else
begin
comport1.SetDTR(false) ;
comport1.SetRTS(false);
end;
If Comport1.Port = 'COM2' then
begin
Journaux.Visible := true;
Choix_page.Tag := 1;
Tempo_retour := 0;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled:=true;
Application.Title:='Alarmes CMR';
end;
// Retourne un string sous la forme "ddmmyyyyhhmmss" :
function AllowedStrDateTime(const sDate, sTime: string): string;
var
AllowedStrDate, AllowedStrTime: string;
begin
AllowedStrDate := Copy(sDate, 1 , 2) +' '+ Copy(sDate, 4, 2) +' '+ Copy(sDate, 7, 4);
AllowedStrTime := Copy(sTime, 1, 2) +'H'+ Copy(sTime, 4, 2) +'min'+ Copy(sTime, 7, 2)+'s';
Result := AllowedStrDate + ' à ' + AllowedStrTime;
end;
procedure TForm1.ComPort1RxChar(Sender: TObject; Count: Integer);
var
NouveauMsg : string;
PosEndTrame,p : Integer;
begin
{*** lecture du port com 1 ***}
ComPort1.ReadStr(NouveauMsg, Count);
MonMessage := MonMessage + NouveauMsg;
MonMessage := Uppercase(MonMessage);
PosEndTrame := Pos(#13, MonMessage);
if PosEndTrame <> 0 then
while PosEndTrame <> 0 do
begin
TrameCp := Copy(MonMessage, 0, PosEndTrame -1);
{ *** Remplacement du caractère $F8 par $B0 ***}
p := pos( chr($F8), TrameCp);
if p>0 then // si le caractère est présent, on le remplace
begin
TrameCp[p] := chr($B0);
richEditRecept.Lines.Add(TrameCp); // dans tous les cas, la trame est ajoutée
Inc (Cpt_Evt);
end;
{ *** Remplacement du caractère $82 par $45 ***}
p := pos( chr($82), TrameCp);
if p>0 then
begin
TrameCp[p] := chr($45);
RichEditRecept.Lines.Add(TrameCp);
Inc (Cpt_Evt);
end;
{ *** Mis en couleur de certaines lignes et écriture dans les RichEdit respectif *** }
Ecriture_et_couleur_OPR;
Ecriture_et_couleur_ALM;
Ecriture_et_couleur_ACK;
Ecriture_et_couleur_RTN;
{ *** Ecriture dans le RichEdit_LOG_20_0h ***}
If Edit2.Tag = 1 then
begin
Ecriture_et_couleur_ALM_20_0h;
Ecriture_et_couleur_ACK_20_0h;
Ecriture_et_couleur_RTN_20_0h;
end;
MonMessage := Copy(MonMessage, PosEndTrame +1, Length(MonMessage));
PosEndTrame := Pos(#13, MonMessage);
end;
end;
procedure TForm1.Timer2Timer(Sender: TObject);// gestion de date et heure, Enregistrement Auto, Nb de lignes
const EnregistAuto=('00:00:00');
const Alm_20_0h_debut = ('20:00:00');
const Alm_20_0h_fin = ('23:59:59');
const Reset_ecran_Alm_20_0h = ('19:59:00');
Begin
{ *** affichage du nombre d'évènements, alarmes et alarmes inhibées *** }
label1.Caption := ('Nb d'' évènements ' + inttostr (Cpt_Evt)) ;
label2.Caption := ('Nb d'' alarmes ' + inttostr(Cpt_Alm)) ;
label4.Caption := ('Nb d'' alarmes inhibées ' + IntToStr (Cpt_ALM_inhi));
Alm_20_0h.Label2.Caption := ('Nb d'' alarmes ' + inttostr(Cpt_Alm_20_0h)) ;
label14.Caption := FormatDateTime('dddddd tt', Now);
Alm_20_0h.Label3.Caption := FormatDateTime('dddddd tt',Now);
Edit1.Text := DateToStr(Date);
Edit2.Text := TimeToStr(Time);
{ *** Enregistrement auto ***}
if Edit2.Text = EnregistAuto then
begin
Env_Eve_Local;
Env_Alm_Local;
Env_Opr_Local;
{ Env_Eve_X;
Env_Alm_X;
Env_Opr_X; }
end;
{ *** Autorisation d'Ecriture des alarmes entre 20 et 0 heures ***}
if Edit2.Text = Alm_20_0h_debut then
Edit2.Tag := 1;
if Edit2.Text = Alm_20_0h_fin then
Edit2.Tag := 0 ;
{ *** Retour à la page principal automatiquement ***}
Retour_auto_page ;
{ *** Effacement RichEdit_log_20_0h et mis à 0 du Compteur ***}
if Edit2.Text = Reset_ecran_Alm_20_0h then
Effacement_ecran_et_compteur_RichEdit_Log_20_0h;
end;
procedure TForm1.Button4Click(Sender: TObject); //Enregistement manu
begin
Env_Eve_Local;
Env_Alm_Local;
Env_Opr_Local;
{ Env_Eve_X;
Env_Alm_X;
Env_Opr_X; }
end;
procedure TForm1.Ecriture_et_couleur_OPR;
begin
if (pos(' OPR ', TrameCP)) <> 0 then
begin
RichEdit_OPR.SelAttributes.Color := clBlue;
RichEdit_OPR.Lines.Add(TrameCp);
Inc (Cpt_Alm_Inhi);
end;
end;
procedure TForm1.Ecriture_et_couleur_ALM;
begin
if (Pos(' ALM ', TrameCp)) <> 0 then
begin
RichEditLog.SelAttributes.Color := clred ;
richEditLog.Lines.Add(TrameCp);
Inc (Cpt_ALM);
end;
end;
procedure TForm1.Ecriture_et_couleur_ACK;
begin
if (Pos(' ACK ', TrameCp)) <> 0 then
begin
//RichEditLog.SelAttributes.Color := $000080FF; // Orange
RichEditLog.SelAttributes.Color := clTeal;
richEditLog.Lines.Add(trameCp);
end;
end;
procedure TForm1.Ecriture_et_couleur_RTN;
begin
if (Pos(' RTN ', TrameCp)) <> 0 then
begin
RichEditLog.SelAttributes.Color := clLime;
RichEditLog.Lines.Add(trameCp);
end;
end;
procedure TForm1.Ecriture_et_couleur_ALM_20_0h;
begin
if (Pos(' ALM ', TrameCp)) <> 0 then
begin
Alm_20_0h.RichEdit_LOG_20_0h.SelAttributes.Color := clred;
Alm_20_0h.RichEdit_LOG_20_0h.Lines.Add(TrameCp);
Inc (Cpt_ALM_20_0h);
end;
end;
procedure TForm1.Ecriture_et_couleur_ACK_20_0h;
begin
if (Pos(' ACK ', TrameCp)) <> 0 then
begin
//RichEditLog.SelAttributes.Color := $000080FF; // Orange
Alm_20_0h.RichEdit_LOG_20_0h.SelAttributes.Color := clTeal;
Alm_20_0h.RichEdit_LOG_20_0h.Lines.Add(TrameCp);
end;
end;
procedure TForm1.Ecriture_et_couleur_RTN_20_0h;
begin
if (Pos(' RTN ', TrameCp)) <> 0 then
begin
ALm_20_0h.RichEdit_LOG_20_0h.SelAttributes.Color := clLime;
Alm_20_0h.RichEdit_LOG_20_0h.Lines.Add(trameCp);
end;
end;
procedure TForm1.Effacement_ecran_et_compteur_RichEdit_Log_20_0h;
begin
Alm_20_0h.RichEdit_LOG_20_0h.Clear ();
Cpt_Alm_20_0h := 0;
end;
procedure TForm1.retour_auto_page;
Begin
if Choix_page.Tag = 1 then
begin
inc (Tempo_retour);
end;
if Tempo_retour = 1200 then // 10 min après ouverture
begin
Alm_20_0h.Visible := false;
Journaux.Visible := false;
Choix_page.Tag := 0;
end;
end;
procedure TForm1.Env_Eve_Local;
begin
// envoi des évènements sur un disque local
NomFichEvenement := 'E:\CMR\Evènements\Evènements.doc '; // Pc portable et PC en machine
ExtRecept := ExtractFileExt(NomFichEvenement);
Delete(NomFichEvenement, Pos(ExtRecept, NomFichEvenement), Length(ExtRecept));
AllowedDateTime := AllowedStrDateTime (Edit1.Text,Edit2.Text);
NomFichEvenement := Format('%s %s %s', [NomFichEvenement, AllowedDateTime, ExtRecept]);
RichEditRecept.Lines.SaveToFile(NomFichEvenement);
label12.Visible := true;
label12.Caption := AllowedDateTime;
Cpt_Evt := 0;
end;
procedure TForm1.Env_Alm_Local;
begin
// envoi des alarmes sur un disque local
NomFichAlarme := 'E:\CMR\Alarmes\Alarmes.doc '; // Pc portable et PC en machine
ExtLog := ExtractFileExt(NomFichAlarme);
Delete(NomFichAlarme, Pos(Extlog, NomFichAlarme), Length(ExtLog));
AllowedDateTime := AllowedStrDateTime (Edit1.Text,Edit2.Text);
NomFichAlarme := Format('%s %s %s', [NomFichAlarme, AllowedDateTime, Extlog]);
RichEditLog.Lines.SaveToFile(NomFichAlarme);
Cpt_ALM := 0;
end;
procedure TForm1.Env_opr_Local;
begin
// envoi des alarmes inhibées sur un disque local
NomFichInhi := 'E:\CMR\Alarmes Inhibées\Alarmes Inhibées.doc '; // Pc portable et PC en machine
ExtInhi := ExtractFileExt(NomFichInhi);
Delete(NomFichInhi, Pos(ExtInhi, NomFichInhi), Length(ExtInhi));
AllowedDateTime := AllowedStrDateTime (Edit1.Text,Edit2.Text);
NomFichInhi := Format('%s %s %s', [NomFichInhi, AllowedDateTime, ExtInhi]);
RichEdit_OPR.Lines.SaveToFile(NomFichInhi);
Cpt_Alm_Inhi := 0;
end;
procedure TForm1.Env_Eve_X;
begin
// envoi les évènements sur le disque X du réseau
NomFichEvenement1 := 'X:\02 - Chef Mécanicien\CMR\Evènements\Evènements.doc ';
ExtLog := ExtractFileExt(NomFichEvenement1);
Delete(NomFichEvenement1, Pos(ExtRecept, NomFichEvenement1), Length(ExtRecept));
AllowedDateTime := AllowedStrDateTime(Edit1.Text,Edit2.Text);
NomFichEvenement1 := Format('%s %s %s', [NomFichEvenement1, AllowedDateTime, ExtRecept]);
RichEditRecept.Lines.SaveToFile(NomFichEvenement1);
RichEditRecept.Clear ();
Cpt_Evt := 0;
end;
procedure TForm1.Env_Alm_X;
begin
// envoi les alarmes sur le disque X du réseau
NomFichAlarme1 := 'X:\02 - Chef Mécanicien\CMR\Alarmes\Alarmes.doc ';
ExtLog := ExtractFileExt(NomFichAlarme1);
Delete(NomFichAlarme1, Pos(ExtLog, NomFichAlarme1), Length(Extlog));
AllowedDateTime := AllowedStrDateTime(Edit1.Text,Edit2.Text);
NomFichAlarme1 := Format('%s %s %s', [NomFichAlarme1, AllowedDateTime, Extlog]);
RichEditLog.Lines.SaveToFile(NomFichAlarme1);
RichEditLog.Clear ();
Cpt_ALM := 0;
end;
procedure TForm1.Env_Opr_X;
begin
// envoi des alarmes inhibées sur un disque X du réseau
NomFichInhi1 := 'X:\02 - Chef Mécanicien\CMR\Alarmes Inhibées\Alarmes Inhibées.doc '; // Pc portable et PC en machine
ExtInhi := ExtractFileExt(NomFichInhi1);
Delete(NomFichInhi1, Pos(ExtInhi, NomFichInhi1), Length(ExtInhi));
AllowedDateTime := AllowedStrDateTime (Edit1.Text,Edit2.Text);
NomFichInhi1 := Format('%s %s %s', [NomFichInhi1, AllowedDateTime, ExtInhi]);
RichEdit_OPR.Lines.SaveToFile(NomFichInhi1);
RichEdit_OPR.Clear ();
Cpt_Alm_Inhi := 0;
end;
procedure TForm1.Aide1Click(Sender: TObject);
begin
showmessage ('Enregistrement sur le ''E:\CMR\... '' et ''X:\02 - Chef Mécanicien\CMR\... ''à chaque passage à 0h, mais il est possible d''effectuer un enregistrement immediat avec la touche enregistrement. Si vous quittez, un enregistrement est effectué ');
end;
procedure TForm1.RichEditReceptChange(Sender: TObject);
begin
SendMessage(RichEditRecept.Handle,WM_VSCROLL,SB_BOTTOM,0);
end;
procedure TForm1.RichEditLogChange(Sender: TObject);
begin
SendMessage(RichEditLog.Handle,WM_VSCROLL,SB_BOTTOM,0);
end;
procedure TForm1.RichEdit_OPRChange(Sender: TObject);
begin
SendMessage(RichEdit_OPR.Handle,WM_VSCROLL,SB_BOTTOM,0);
end;
procedure TForm1.Quitter1Click(Sender: TObject);
begin
Env_Eve_Local;
Env_Alm_Local;
Env_Opr_Local;
{ Env_Eve_X;
Env_Alm_X;
Env_Opr_X; }
comport1.SetDTR(false); // met à l'état de repos "1" la sortie DTR (-10V)
comport1.SetRTS(false); // met à l'état de repos "1" la sortie RTS (-10V)
comport1.Connected:=false;
close;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Env_Eve_Local;
Env_Alm_Local;
Env_Opr_Local;
{ Env_Eve_X;
Env_Alm_X;
Env_Opr_X; }
end;
procedure TForm1.Choix_pageClick(Sender: TObject);
begin
case Choix_page.ItemIndex of
0:
begin
Alm_20_0h.Visible := true;
Choix_page.Tag := 1;
Tempo_retour := 0;
end;
1:
begin
Journaux.Visible := true;
Choix_page.Tag := 1;
Tempo_retour := 0;
end;
end;
end;
end. |
Partager