HP\李良庭
2025-07-08 868daf94f29ce1ffdd799a68c07bb668cd373bcd
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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
{------------------------------------------------------------------------------}  
{µ¥ÔªÃû³Æ£ºuInit.pas                                                           }
{Ä£¿éÃû³Æ£º³õʼ»¯º¯Êý¿â                                                        }
{Ä£¿é˵Ã÷£º°üÀ¨Ö÷½ø³ÌÆô¶¯Ê±£¬È«¾Ö±äÁ¿³õʼ»¯¡¢ÏµÍ³Ä¿Â¼³õʼ»¯¡¢ÅäÖüÓÔØ          }
{½¨Á¢ÈÕÆÚ£º2009-12-20                                                          }
{ÐÞ¸ÄÐ޸ģº2023-02-21                                                          }
{°æÈ¨ËùÓУºÀîÁ¼Í¥ liangtingli@outlook.com                                      }
{------------------------------------------------------------------------------}
 
unit uInit;
 
interface
 
uses
  Windows, Classes, Messages, Forms, Dialogs, SysUtils, StrUtils, DateUtils,
  StdCtrls, Variants, ComCtrls, Buttons, Math, IniFiles, Graphics, ShellAPI,
  SQLite3, SQLiteTable3;
 
  {ÉêÃ÷È«¾Ö¹«¹²µ÷Óú¯Êý}
  procedure OpenOnScreenKeyboard();
  procedure InitGlobal();
  procedure InitSystemDir();
  procedure InitDatas();
  procedure LoadSystemInfo();
  procedure LoadOptions();
  procedure SaveOptions();
  function GetCurrMsgPos(index:Integer):TPoint;
 
  //ÊÚȨÎļþ¼ì²éÄ£¿é
  function GetMachineCode():String;
  function CheckLicense(sFilename, sCode:String):Boolean;
  procedure RegCheckMode();
  procedure RegCheck1Mode();
  //±£´æcsvÊý¾Ý
  procedure WriteCsvFile(name: string; mois,temp,water: Double);
  //ˢйÊÕÏÂë
  function RefashFaultCode(cod:Integer):String;
  //×Ô¶¯Ä£Ê½ÏÂˢйÊÕÏÂë
  function AutoFaultCode(cod:Integer):string;
implementation
 
uses
  uMain, log4me, uDM, PubUtils, MsgVar, Global, uSaveData, CpuidInfo, UntDes;
 
  {º¯Êý·½·¨}
 
//------- µ÷ÓÃÈý·½¼üÅÌ ------------------------------------
//µ÷ÓÃosk¼üÅÌ
procedure OpenOnScreenKeyboard();
type TWow64DisableWow64FsRedirection = function(var Wow64FsEnableRedirection: LongBool): LongBool; StdCall;
type TWow64RevertWow64FsRedirection = function(var Wow64RevertWow64FsRedirection: LongBool): LongBool; StdCall;
var
  hHandle: THandle;
  Wow64DisableWow64FsRedirection: TWow64DisableWow64FsRedirection;
  Wow64RevertWow64FsRedirection: TWow64RevertWow64FsRedirection;
  OldValue: LongBool;
  rs: Integer;
begin
  //Çл»32λÎļþϵͳ
  try
    hHandle := GetModuleHandle('kernel32.dll');
    @Wow64DisableWow64FsRedirection := GetProcAddress(hHandle, 'Wow64DisableWow64FsRedirection');
    if ((hHandle <> 0) and (@Wow64DisableWow64FsRedirection <> nil)) then
      Wow64DisableWow64FsRedirection(OldValue);
  except
  end;
  //µ÷ÓÃoskÆÁÄ»¼üÅÌ
  rs := ShellExecute(Application.Handle, 'open', 'osk.exe', nil, nil, SW_SHOWNORMAL);
  if rs <= 32 then begin
    ShowMessage(Format('´íÎó£ºÎÞ·¨´ò¿ªÆÁÄ»¼üÅÌ£¬´íÎó´úÂë-[%d].',[rs]));
    log4Info(Format('´íÎó£ºÎÞ·¨´ò¿ªÆÁÄ»¼üÅÌ£¬´íÎó´úÂë-[%d].',[rs]));
  end
  else
    log4Info('ϵͳ£ºÉÏλ»úÈí¼þ´ò¿ª osk ÏµÍ³ÆÁÄ»¼üÅÌ.');
  //ÓûØ64λÎļþϵͳ
  try
    hHandle := GetModuleHandle('kernel32.dll');
    @Wow64RevertWow64FsRedirection := GetProcAddress(hHandle, 'Wow64RevertWow64FsRedirection');
    if ((hHandle <> 0) and (@Wow64RevertWow64FsRedirection <> nil)) then
      Wow64RevertWow64FsRedirection(OldValue);
  except
  end;
end;
 
//---------------------------------------------------------------------------
//³õʼ»¯È«¾Ö±äÁ¿
procedure InitGlobal();
begin
  //³ÌÐò·¾¶
  glAppPath := ExtractFilePath(Application.ExeName);
 
  //configDB file
  glConfig_db := glAppPath + CONFIG_DIR + t_Config + '.db';
  glConn_db   := glAppPath + CONFIG_DIR + t_Conn + '.db';
  glGrain_db  := glAppPath + CONFIG_DIR + t_Grain + '.db';
  glWeight_db := glAppPath + CONFIG_DIR + t_Weight + '.db';
  glManager_db := glAppPath + CONFIG_DIR + t_Manager + '.db';
  glData_db   := glAppPath + CONFIG_DIR + t_Data + '.db';
  //³õʼ»¯CalcÈ«¾Ö±äÁ¿
  glCalcOutput := '';
  glCurrFocus  := 0;
  //³õʼ»¯ÊÖ¶¯Ä£Ê½·µ»Ø¿ÚÁîÖµ
  frmMain.sLoginPwd := '';
  //³õʼ»¯Ñù±¾´æ´¢±äÁ¿
  smp.flag := false;
  smp.info := '';
  smp.prefix := '';
  smp.dir := '';
end;
 
//³õʼ»¯ÏµÍ³Ä¿Â¼
procedure InitSystemDir();
var
  path : String;
begin
  //´´½¨ÅäÖÃÎļþ¼Ð
  path := glAppPath + CONFIG_DIR;
  if not DirectoryExists(path) then ForceDirectories(path);
 
  //´´½¨Êý¾ÝÎļþ¼Ð
  path := glAppPath + DATA_DIR;
  if not DirectoryExists(path) then ForceDirectories(path);
 
  //´´½¨ÈÕÖ¾Îļþ¼Ð
  path := glAppPath + LOG_DIR;
  if not DirectoryExists(path) then ForceDirectories(path);
end;
 
//³õʼ»¯Êý¾Ý²É¼¯½á¹¹
procedure InitDatas();
begin
  //³õʼ»¯Datas²âÁ¿Êý¾Ý
  Datas.Voltage := 0;   //ԭʼµçƽ
  Datas.Weight := 0;    //ÖØÁ¿
  Datas.Temp := 0;      //ζÈ
  Datas.Humid:= 0;      //ʪ¶È
  //³õʼ»¯×Ô¶¯¼ì²â±êÇ©
  frmMain.lblAutoRet.Caption := '';
  frmMain.lblAutoRet_error.Caption := '';
end;
 
//¼ÓÔØÏµÍ³ÐÅÏ¢½çÃæ
procedure LoadSystemInfo();
begin
  with frmMain do begin
    //³õʼ»¯Ë®·ÖÒÇ´®¿ÚÏÂÀ­²Ëµ¥
    cbSerialPort.Items.Clear;
    EnumComPorts(cbSerialPort.Items);
    //¼ÓÔØË®·ÖÒDzÎÊý
    cbSerialPort.Text := WrConn.SerialPort;
    edtBaud.Text := IntToStr(WrConn.baud);
    edtParity.Text := WrConn.parity;
    edtData_bit.Text := IntToStr(WrConn.data_bit);
    edtStop_bit.Text := IntToStr(WrConn.stop_bit);
    cbAutoRun.Checked := glAutoRun;
    //Ôö¼ÓÁ½¸öʱ¼äÉèÖÃÖµ
    edtTime1.Text := IntToStr(glTime1);
    edtTime2.Text := IntToStr(glTime2);
 
    //¼ÓÔØÇ¤¼ñϵͳ²ÎÊý
    edtIP.Text := PlcConn.ip;
    edtPort.Text := IntToStr(PlcConn.port);
    edtHeartIP.Text := PlcConn.heart_ip;
    edtHeartPort.Text := IntToStr(PlcConn.heart_port);
 
    //¼ÓÔØÊÖ¶¯¼ì²âºÍ²ÎÊýÅäÖýçÃæµÄÊý¾Ý´æ´¢²ÎÊý
    cbTestAutoSave.Checked := smp.flag;
    edtSampleName.Text := smp.info;
    cbAutoSave.Checked := smp.flag;
    edtPrefix.Text := smp.prefix;
    edtDir.Text := smp.dir;
 
    //¼ÓÔØµÇ¼¿ÚÁî
    edtPassword.Text := SysConfig.password;
    edtDelay.Text := IntToStr(SysConfig.delay);
  end;
end;
 
//¼ÓÔØ²ÎÊýµ½½çÃæ
procedure LoadOptions();
begin
  with frmMain do begin
    //ÊÖ¶¯¼ì²â½çÃæ
    mtManClock.Value := 0;
    edtMoisture.Text := '';
    edtWeightRatio.Text := '';
    edtWeight.Text := '';
    edtTemp.Text := '';
    edtWater.Text := '';
    lbType.ItemIndex := Grain.Code-1; //Á¸ÖÖ´úÂëÓë½çÃæItemIndexµÄ¶ÔÓ¦¹ØÏµ
    sLabel15.Caption := Format('Á¸Ê³ÖÖÀà - [%s]',[Grain.Name]);
    sLabel3.Caption := Format('Ñ¡Ôñ - [%s]',[Grain.Name]);
    //ÒÇÆ÷У׼½çÃæ
    lbType1.ItemIndex := Grain.Code-1;
    edtAutoCoef1.Text := Grain.coef[0];
    edtAutoCoef2.Text := Grain.coef[1];
    edtAutoCoef3.Text := Grain.coef[2];
    edtAutoCoef4.Text := Grain.coef[3];
    edtAutoCoef5.Text := Grain.coef[4];
    //²ÎÊýÉèÖýçÃæ
    edtVolume.Text := FloatToStr(SysConfig.Volume);
    edtTare.Text := FloatToStr(SysConfig.Tare);
    edtFreq.Text := FloatToStr(SysConfig.Freq);
    edtDecay.Text:= FloatToStr(SysConfig.Decay);
    edtStartFreq.Text := FloatToStr(SysConfig.StartFreq);
    edtStopFreq.Text := FloatToStr(SysConfig.StopFreq);
    edtStep.Text := IntToStr(SysConfig.Step);
    lbASK.ItemIndex := SysConfig.Ask;  //ASK´úÂëÓë½çÃæItemIndexµÄ¶ÔÓ¦¹ØÏµ
    //ϵͳÐÅÏ¢½çÃæ
    lblVersion.Caption := Format('°æ±¾ %s ', [glFileVersion]);
  end;
end;
 
//±£´æ½çÃæ²ÎÊý
procedure SaveOptions();
begin
  //
end;
 
//------ ¹¦Äܺ¯Êý -------------------------------------------------------------
//»ñÈ¡µ±Ç°½¹µãÊäÈë¿òµÄ¾ø¶Ô×ø±ê
function GetCurrMsgPos(index:Integer):TPoint;
var
  x1,y1 : Integer;  //ÐÞÕýÖµ
  x3,x45,y2 : Integer;
begin
  with frmMain do begin
    x1 := edtMois1.Width + 5;
    y1 := -100;
    x3 := edtMois1.Width - 8;
    x45 := -473;
    y2  := -250;
    case index of
      1:begin
        Result.X := Left+edtMois1.Left+x1;
        Result.Y := Top+edtMois1.Top+y1;
      end;
      2:begin
        Result.X := Left+edtMois2.Left+x1;
        Result.Y := Top+edtMois2.Top+y1;
      end;
      3:begin
        Result.X := Left+edtMois3.Left+x3;
        Result.Y := Top+edtMois3.Top+y1;
      end;
      4:begin
        Result.X := Left+edtMois4.Left+x45;
        Result.Y := Top+edtMois4.Top+y1;
      end;
      5:begin
        Result.X := Left+edtMois5.Left+x45;
        Result.Y := Top+edtMois5.Top+y1;
      end;
      6:begin
        Result.X := Left+edtManCoef1.Left+x1;
        Result.Y := Top+edtManCoef1.Top+y2;
      end;
      7:begin
        Result.X := Left+edtManCoef2.Left+x1;
        Result.Y := Top+edtManCoef2.Top+y2;
      end;
      8:begin
        Result.X := Left+edtManCoef3.Left+x3;
        Result.Y := Top+edtManCoef3.Top+y2;
      end;
      9:begin
        Result.X := Left+edtManCoef4.Left+x45;
        Result.Y := Top+edtManCoef4.Top+y2;
      end;
      10:begin
        Result.X := Left+edtManCoef5.Left+x45;
        Result.Y := Top+edtManCoef5.Top+y2;
      end;
      11:begin
        Result.X := Left+edtIp.Left+edtIp.Width+35;
        Result.Y := Top+edtIp.Top+edtIp.Height+70;
      end;
      12:begin
        Result.X := Left+edtPort.Left+edtPort.Width+30;
        Result.Y := Top+edtPort.Top+edtPort.Height+70;
      end;
      13:begin
        Result.X := Left+edtTime1.Left+edtTime1.Width+35;
        Result.Y := Top+edtTime1.Top+edtTime1.Height+190;
      end;
      14:begin
        Result.X := Left+edtTime2.Left+edtTime2.Width+35;
        Result.Y := Top+edtTime2.Top+edtTime2.Height+190;
      end;
      15:begin
        Result.X := Left+edtWeight1.Left+edtWeight1.Width+5;
        Result.Y := Top+edtWeight1.Top+edtWeight1.Height-50;
      end;
      16:begin
        Result.X := Left+edtWeight2.Left+edtWeight2.Width+5;
        Result.Y := Top+edtWeight2.Top+edtWeight2.Height-50;
      end;
      17:begin
        Result.X := Left+edtWeight3.Left-475;
        Result.Y := Top+edtWeight3.Top+edtWeight3.Height-50;
      end;
      18:begin
        Result.X := Left+edtWeight3.Left-220;
        Result.Y := Top+edtWeight3.Top+edtWeight3.Height-120;
      end;
      19:begin
        Result.X := Left+edtWeight3.Left-220;
        Result.Y := Top+edtWeight3.Top+edtWeight3.Height-60;
      end;
      20:begin
        Result.X := Left+edtVolume.Left+edtVolume.Width+5;
        Result.Y := Top+edtVolume.Top+edtVolume.Height-45;
      end;
      21:begin
        Result.X := Left+edtTare.Left+edtTare.Width+5;
        Result.Y := Top+edtTare.Top+edtTare.Height-45;
      end;
      22:begin
        Result.X := Left+edtDelay.Left+edtDelay.Width+35;
        Result.Y := Top+edtDelay.Top+edtDelay.Height+140;
      end;
      23:begin
        Result.X := Left+edtPassword.Left+35;
        Result.Y := Top+edtPassword.Top+210;
      end;
      24:begin
        Result.X := Left+edtManVal.Left+x1;
        Result.Y := Top+edtManVal.Top-120;
      end;
      25:begin
        Result.X := Left+edtIntercept.Left+x1;
        Result.Y := Top+edtIntercept.Top-180;
      end;
      26:begin
        Result.X := Left+edtHeartIp.Left+40;
        Result.Y := Top+edtHeartIp.Top+120;
      end;
      27:begin
        Result.X := Left+edtHeartPort.Left+40;
        Result.Y := Top+edtHeartPort.Top+120;
      end;
    end;
  end;
end;
 
//------- ÏµÍ³ÊÚȨÏà¹Øº¯Êý -----------------------------------------------------
//¼ÆËã±¾»ú»úÆ÷Â룬Êä³ö»úÆ÷ÂëÃÜÎÄ
function GetMachineCode():String;
var
  ss : string;
begin
  SetCPU(GetCurrentProcess,1);
  ss := GetCnCPUID();
  //Éú³ÉÒ»¸ö»úÆ÷Âë
  Result := EncryStrHex(ss, sConfig);
end;
 
//ÊÚȨÎļþУÑ飬·µ»ØÐ£Ñé½á¹û
//Èë²Î£ºsfilename-УÑéÎļþ
//      sCode-¼ÆËã±¾»ú»úÆ÷Âë
//·µ»Ø£ºtrue-УÑé³É¹¦£»false-УÑéʧ°Ü
function CheckLicense(sFilename, sCode:String):Boolean;
var
  i : Integer;
  sDecry : String;  //½âÃܺóµÄÃ÷ÎÄ
  sl : TStringList;
begin
  //ÈÝ´í´¦Àí
  if not FileExists(sFileName) then begin
    Result := false;
    Exit;
  end;
 
  //»ñÈ¡ÃÜÎÄ
  sl := TStringlist.Create();
  try
    sl.LoadFromFile(sFilename);
    sDecry := Trim(sl.Text);                        
  finally
    FreeAndNil(sl);
  end;
 
  //¶ÔÃÜÎÄÐÅÏ¢½øÐнâÂ룬°´Ä¬ÈÏlevel=8
  for i:=1 to 8 do
    sDecry := DecryStrHex(sDecry, sConfig); //±àÂë,Éú³ÉÃ÷ÎÄ
 
  //»ñÈ¡RegCode+RegDate+RegLevel+RegType+RegKey »úÆ÷Âë
  sDESMachineCode := SplitStr(sDecry,' ',0);
  sDESDate := SplitStr(sDecry,' ',1);
  sDESLevel := SplitStr(sDecry,' ',2);
  sDESType := SplitStr(sDecry,' ',3);
  sDESKey := SplitStr(sDecry,' ',4);
 
  //·µ»Ø±È½Ï»úÆ÷Âë
  Result := AnsiSameStr(sCode, sDESMachineCode);
end;
//LicenseÊÚȨ¼ì²éÄ£¿é£¬Èçδע²áÔò×Ô¶¯Í˳ö
procedure RegCheckMode();
var
  sl : TStringList;
  sLicFile, sMchCod, sLicText : String;
begin
  //======ÑéÖ¤ÊÚȨÎļþ===============================
  sLicFile := glAppPath + LICENSE_FILE;
  sMchCod := GetMachineCode();
  if CheckLicense(sLicFile, sMchCod) then
    glRegSuccess := true
  else begin
    //´æ×¢²áÂë
    sl := TStringList.Create();
    sl.Add('»úÆ÷Â룺' + sMchCod);
    sl.Add('Éú³ÉÈÕÆÚ£º' + FormatDateTime('yyyy-mm-dd hh:nn:ss',Now()));
    sl.SaveToFile(glAppPath+'»úÆ÷Âë.txt');
    FreeAndNil(sl);
    //ÌáʾҪ»ñÈ¡ÊÚȨÎļþ
    glRegSuccess := false;  //×¢²áʧ°Ü£¬µ÷Õû±êÖ¾£¬×¼±¸ÊÍ·ÅÍ˳ö¶¨Ê±Æ÷
    sLicText := '¾¯¸æ£ºÏµÍ³ÉÐδע²á£¬ÒÑÔÚÈí¼þĿ¼Éú³É [»úÆ÷Âë] Îļþ£¬Ç뽫¸ÃÎļþÌṩ¸øÏµÍ³¹©Ó¦ÉÌ£¬ÒÔ»ñÈ¡ÕýʽÊÚȨÎļþ£¡';
    MessageBox(frmMain.handle,PChar(sLicText),'×¢²áÌáʾ¶Ô»°¿ò',MB_OK+MB_ICONWARNING);
    //¿ªÆôÍ˳ö¶¨Ê±Æ÷, 0.5sÄÚÍ˳ö
    dm.tmRegFault.Enabled := true;
  end;
end;
 
//¾²Ä¬ÊÚȨ¼ì²éÄ£¿é
procedure RegCheck1Mode();
var
  sLicFile, sMchCod : String;
begin
  sLicFile := glAppPath + LICENSE_FILE;
  sMchCod := GetMachineCode();
  if not CheckLicense(sLicFile, sMchCod) then
    dm.tmRegFault.Enabled := true;
end;
 
//------------------------------------------------------------------------------
function GetLastNum(const FileName: string): Integer;
var
  FileStream: TextFile;
  LastDataLine,Line,Fields: string;
begin
  Result := 0;
  // ¼ì²éÎļþÊÇ·ñ´æÔÚ
  if not FileExists(FileName) then Exit;
 
  // ´ò¿ªÎļþ
  AssignFile(FileStream, FileName);
  try
    Reset(FileStream);
    // Ìø¹ý±êÌâÐÐ
    if not Eof(FileStream) then ReadLn(FileStream);
    // ¶ÁÈ¡ÎļþµÄÿһÐÐ
    LastDataLine := '';
    while not Eof(FileStream) do begin
      ReadLn(FileStream, Line);
      if Line <> '' then
        LastDataLine := Trim(Line);
    end;
    // ½âÎö×îºóÒ»ÐÐ
    if LastDataLine <> '' then begin
      Fields := SplitStr(LastDataLine,',',0);
      Result := StrToIntDef(Fields,0);
    end;
  finally
    CloseFile(FileStream);
  end;
end;
 
// ½«¼ì²â½á¹û±£´æµ½ csvÎļþ
procedure WriteCsvFile(name: string; mois,temp,water: Double);
var
  pMyFile: textFile;
  sfile,sTitle,sMsg,time : string;
  no : integer;
begin
  //³õʼ»¯Â·¾¶ºÍ±êÌâ
  sFile := smp.dir + smp.prefix + FormatDateTime('yyyymmdd', Now) + '.csv';
  sTitle:= 'ÐòºÅ,Ñù±¾ÐÅÏ¢,º¬Ë®ÂÊ,ζÈ,ʪ¶È,ÈÕÆÚ';
 
  //¶ÁÈ¡ÎļþÀúÊ·noÐòºÅ
  no := GetLastNum(sFile)+1;
  time := FormatDateTime('yyyy-mm-dd hh:nn:ss', Now);
  sMsg  := Format('%d,%s,%.2f,%.2f,%.2f,%s', [no,name,mois,temp,water,time]);
  try
    AssignFile(pMyFile,sFile);
    if FileExists(sFile) then
      Append(pMyFile)
    else begin
      ReWrite(pMyFile);
      WriteLn(pMyFile,sTitle); //н¨csv£¬ÏÈдÈë±êÌâ
    end;
    WriteLn(pMyFile,sMsg);     //дÈëÄÚÈÝ
  finally
    CloseFile(pMyFile);
  end;
end;
 
//Ë¢ÐÂÉ豸¹ÊÕÏÂë
function RefashFaultCode(cod:Integer):string;
var
  str : string;
begin
  //·­Òëcod
  case cod of
    -1:str := 'ͨѶ¹ÊÕÏ';
    0: str := 'Õý³£';
    1: str := 'ÉÏ·§ÃŹعÊÕÏ';
    2: str := 'Ï·§ÃŹعÊÕÏ';
    3: str := 'Ë«·§ÃŹعÊÕÏ';
    4: str := 'ÉÏ·§ÃÅ¿ª¹ÊÕÏ';
    5: str := 'ÉÏ·§ÃÅ¿ª¹Ø¹ÊÕÏ';
    6: str := 'ÉÏ·§ÃÅ¿ª¡¢Ï·§ÃŹعÊÕÏ';
    7: str := 'ÉÏ·§ÃÅ¿ª¹Ø¡¢Ï·§ÃŹعÊÕÏ';
    8: str := 'Ï·§ÃÅ¿ª¹ÊÕÏ';
    9: str := 'Ï·§ÃÅ¿ª¡¢ÉÏ·§ÃŹعÊÕÏ';
    10: str := 'Ï·§ÃÅ¿ª¹Ø¹ÊÕÏ';
    11: str := 'Ï·§ÃÅ¿ª¹Ø¡¢ÉÏ·§ÃŹعÊÕÏ';
    12: str := 'Ë«·§ÃÅ¿ª¹ÊÕÏ';
    13: str := 'ÉÏ·§ÃÅ¿ª¹Ø¡¢Ï·§ÃÅ¿ª¹ÊÕÏ';
    14: str := 'Ï·§ÃÅ¿ª¹Ø¡¢ÉÏ·§ÃÅ¿ª¹ÊÕÏ';
    15: str := 'Ë«·§ÃÅ¿ª¹Ø¹ÊÕÏ';
    16: str := 'ûÓÐÁ¸Ê³ÔÚ©¶·ÖÐ';
    32: str := '³éÌëûÓзźÃ';
    256:str := '¹ÊÕÏÖØÆô';
    else str := '¹ÊÕÏ䶨Òå';
  end;
 
  //·µ»Ø¹ÊÕÏ×Ö·û´®
  result := str;
 
  //Êä³öµ½½çÃæ
  with frmMain do begin
    sLabel72.Caption := Format('É豸״̬-[%s]',[str]);    //¸üе÷Õû½Ø¾à½çÃæ
    sLabel73.Caption := Format('É豸״̬-[%s]',[str]);    //¸üÐÂÊÖ¶¯¼ì²â½çÃæ
    sLabel74.Caption := Format('É豸״̬-[%s]',[str]);    //¸üÐÂ×Ô¶¯Ä£Ê½½çÃæ
    sLabel75.Caption := Format('É豸״̬-[%s]',[str]);    //¸üÐÂÊÖ¶¯Ð£×¼½çÃæ
    sLabel76.Caption := Format('É豸״̬-[%s]',[str]);    //¸üÐÂÊÖ¶¯Ä£Ê½½çÃæ
    sLabel77.Caption := Format('É豸״̬-[%s]',[str]);    //¸üÐÂÒÇÆ÷ά»¤½çÃæ
 
    //ÐÞ¸ÄÑùʽ
    if cod=0 then begin
      sLabel72.Font.Color := clLime;
      sLabel73.Font.Color := clLime;
      sLabel74.Font.Color := clLime;
      sLabel75.Font.Color := clLime;
      sLabel76.Font.Color := clLime;
      sLabel77.Font.Color := clLime;
    end
    else if (cod>=1)or(cod<=15) then begin
      sLabel72.Font.Color := clRed;
      sLabel73.Font.Color := clRed;
      sLabel74.Font.Color := clRed;
      sLabel75.Font.Color := clRed;
      sLabel76.Font.Color := clRed;
      sLabel77.Font.Color := clRed;
    end
    else begin
      sLabel72.Font.Color := clSilver;
      sLabel73.Font.Color := clSilver;
      sLabel74.Font.Color := clSilver;
      sLabel75.Font.Color := clSilver;
      sLabel76.Font.Color := clSilver;
      sLabel77.Font.Color := clSilver;
    end;
 
    //Ç¿ÖÆË¢Ð±êÇ©
    sLabel72.Repaint;
    sLabel73.Repaint;
    sLabel74.Repaint;
    sLabel75.Repaint;
    sLabel76.Repaint;
    sLabel77.Repaint;
  end;
end;
 
//×Ô¶¯Ä£Ê½Ï£¬Ë¢ÐÂÉ豸¹ÊÕÏÂë
function AutoFaultCode(cod:Integer):string;
var
  str : string;
begin
  //·­Òëcod
  case cod of
    -1:str := 'ͨѶ¹ÊÕÏ';
    0: str := 'δ֪¹ÊÕÏ';
    1: str := 'ÉÏ·§ÃŹعÊÕÏ';
    2: str := 'Ï·§ÃŹعÊÕÏ';
    3: str := 'Ë«·§ÃŹعÊÕÏ';
    4: str := 'ÉÏ·§ÃÅ¿ª¹ÊÕÏ';
    5: str := 'ÉÏ·§ÃÅ¿ª¹Ø¹ÊÕÏ';
    6: str := 'ÉÏ·§ÃÅ¿ª¡¢Ï·§ÃŹعÊÕÏ';
    7: str := 'ÉÏ·§ÃÅ¿ª¹Ø¡¢Ï·§ÃŹعÊÕÏ';
    8: str := 'Ï·§ÃÅ¿ª¹ÊÕÏ';
    9: str := 'Ï·§ÃÅ¿ª¡¢ÉÏ·§ÃŹعÊÕÏ';
    10: str := 'Ï·§ÃÅ¿ª¹Ø¹ÊÕÏ';
    11: str := 'Ï·§ÃÅ¿ª¹Ø¡¢ÉÏ·§ÃŹعÊÕÏ';
    12: str := 'Ë«·§ÃÅ¿ª¹ÊÕÏ';
    13: str := 'ÉÏ·§ÃÅ¿ª¹Ø¡¢Ï·§ÃÅ¿ª¹ÊÕÏ';
    14: str := 'Ï·§ÃÅ¿ª¹Ø¡¢ÉÏ·§ÃÅ¿ª¹ÊÕÏ';
    15: str := 'Ë«·§ÃÅ¿ª¹Ø¹ÊÕÏ';
    16: str := 'ûÓÐÁ¸Ê³ÔÚ©¶·ÖÐ';
    32: str := '³éÌëûÓзźÃ';
    256:str := '¹ÊÕÏÖØÆô';
    else str := '¹ÊÕÏ䶨Òå';
  end;
  //Êä³öµ½½çÃæ
  with frmMain do begin
    //¸üÐÂ×Ô¶¯Ä£Ê½½çÃæ
    sLabel74.Caption := Format('É豸״̬-[%s]',[str]);
    //ÐÞ¸ÄÑùʽ
    sLabel74.Font.Color := clRed;
    sLabel74.Repaint;
  end;
  //·µ»Ø¹ÊÕÏ×Ö·û´®
  result := str;
end;
 
end.