{******* UNIT1.PAS *******} unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls, Buttons, ExtCtrls, StdCtrls, Grids, TeEngine, Series, TeeProcs, Chart, OleCtrls, TVICLPTLib_TLB; type TForm1 = class(TForm) PageControl1: TPageControl; TabSheet1: TTabSheet; GroupBox1: TGroupBox; SpeedButton1: TSpeedButton; ListBox1: TListBox; StringGrid1: TStringGrid; TabSheet2: TTabSheet; GroupBox2: TGroupBox; TabSheet3: TTabSheet; GroupBox3: TGroupBox; ListBox2: TListBox; StringGrid2: TStringGrid; ComboBox1: TComboBox; Label1: TLabel; Label2: TLabel; Timer1: TTimer; TVicLPT1: TTVicLPT; SpeedButton2: TSpeedButton; SpeedButton3: TSpeedButton; SpeedButton4: TSpeedButton; SpeedButton5: TSpeedButton; SpeedButton6: TSpeedButton; Panel1: TPanel; Panel2: TPanel; Image1: TImage; CheckBox1: TCheckBox; Label3: TLabel; CheckBox2: TCheckBox; SpeedButton7: TSpeedButton; SaveDialog1: TSaveDialog; ListBox3: TListBox; OpenDialog1: TOpenDialog; SpeedButton8: TSpeedButton; ListBox4: TListBox; Label4: TLabel; Label5: TLabel; Edit1: TEdit; Label6: TLabel; ComboBox2: TComboBox; Label7: TLabel; Memo1: TMemo; procedure SpeedButton1Click(Sender: TObject); procedure PageControl1Change(Sender: TObject); procedure FormActivate(Sender: TObject); procedure Timer1Timer(Sender: TObject); function FlipNow(C: Integer): Integer; procedure SetBit9; procedure ClrBit9; function ReadNow: Integer; function ReadFilterFile(C: Integer): BOOL; function Filter(C: Integer): Integer; procedure WriteNow(C: Integer); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure SpeedButton2Click(Sender: TObject); procedure SpeedButton3Click(Sender: TObject); procedure SpeedButton6Click(Sender: TObject); procedure SpeedButton5Click(Sender: TObject); procedure SpeedButton4Click(Sender: TObject); procedure SpeedButton8Click(Sender: TObject); procedure SpeedButton7Click(Sender: TObject); procedure ComboBox2Change(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1 : TForm1; Files : array[1..100] of TextFile; FilterNeeded : array[1..100] of BOOL; FilterCoefA : array[1..100, 1..10] of real; FilterCoefB : array[1..100, 1..10] of real; WithFiles : array[1..100] of BOOL; LastValues : array[1..100, 0..9] of Byte; CurrentValue : array[1..100] of Byte; LastValuesX : array[1..100, 0..9] of Byte; Period : array[1..100] of Integer; LastChecked : array[1..100] of Byte; No_Of_Channels : Integer; Timeout, Timer : Integer; MonX : Integer; Coef, LeadChannel: Integer; ReportFile : TextFile; OpenedReportFile : BOOL; StopPressed : BOOL; implementation uses Unit2; {$R *.DFM} function TForm1.FlipNow(C: Integer): Integer; var X, Y, I: Integer; begin X := 0; Y := C; for I := 1 to 8 do begin X := X * 2 + Y mod 2; Y := trunc(Y / 2); end; FlipNow := X; end; function TForm1.Filter(C: Integer): Integer; var I: Integer; X: real; begin X := 0; for I := 0 to 9 do X := X + FilterCoefA[C, 10 - I] * LastValuesX[C, (I + CurrentValue[C] + 1) mod 10]; for I := 0 to 8 do X := X - FilterCoefB[C, 10 - I] * LastValues[C, (I + CurrentValue[C] + 1) mod 10]; X := X / FilterCoefB[C, 1]; if (X < 256) and (X > -1) then Filter := trunc(X) else Filter := 255; end; function TForm1.ReadFilterFile(C: Integer): BOOL; var FF: TextFile; A : Char; S : string; X : BOOL; Coeff, J, I: Integer; begin X := False; Coeff := 1; for I := 1 to 10 do begin FilterCoefA[C + 1, I] := 0; FilterCoefB[C + 1, I] := 0; end; I := 1; J := 0; Assignfile(FF, StringGrid1.Cells[5, C]); reset(FF); while not EOF(FF) do begin read (FF, A); if A = Chr(13) then begin read (FF, A); if A <> Chr(10) then X := True else begin if I < 11 then begin if J = 0 then Coeff := StrToInt(S); if J = 1 then FilterCoefA[C + 1, I] := StrToInt(S) / Coeff; if J = 2 then FilterCoefB[C + 1, I] := StrToInt(S) / Coeff; end else X := True; S := ''; I := 1; J := J + 1; end; end else if A = ' ' then begin if I < 11 then begin if J = 1 then FilterCoefA[C + 1, I] := StrToInt(S) / Coeff; if J = 2 then FilterCoefB[C + 1, I] := StrToInt(S) / Coeff; end else X := True; I := I + 1; S := ''; end else S := S + A; end; if J = 1 then FilterCoefA[C + 1, I] := StrToInt(S) / Coeff; if J = 2 then FilterCoefB[C + 1, I] := StrToInt(S) / Coeff; if J <> 2 then X := True; if X then ShowMessage('Unknown format for Filter File'); closeFile(FF); ReadFilterFile := X; end; procedure TForm1.SetBit9; begin TVicLPT1.ControlPortBit[2] := 1; end; procedure TForm1.ClrBit9; begin TVicLPT1.ControlPortBit[2] := 0; end; function TForm1.ReadNow: Integer; var C: Integer; label EndNow; begin TVicLPT1.ControlPortBit[5] := 1; TVicLPT1.ControlPortBit[1] := 0; //Read Enable TVicLPT1.ControlPortBit[3] := 1; //Set Strobe Timer := - Timeout; while (Timer < Timeout) and (TVicLPT1.StatusPortBit[7] = 0) do //Wait for ACK Timer := Timer + 1; if (Timer >= Timeout) then begin ListBox2.Items.Add('Error : No Data Received From Data Acquisition Module (ERR3)'); TVicLPT1.ControlPortBit[3] := 0; //Clear Strobe ReadNow := -1; goto EndNow; end; C := TVicLPT1.DataPort; TVicLPT1.ControlPortBit[3] := 0; //Clear Strobe Timer := - Timeout; while (Timer < Timeout) and (TVicLPT1.StatusPortBit[7] = 1) do Timer := Timer + 1; if (Timer >= Timeout) then begin ListBox2.Items.Add('Error : Invalid Acknowledge From Data Server (ERR4)'); TVicLPT1.ControlPortBit[3] := 0; //Clear Strobe ReadNow := -1; end else ReadNow := C; EndNow: end; procedure TForm1.WriteNow(C: Integer); begin TVicLPT1.ControlPortBit[5] := 0; TVicLPT1.ControlPortBit[0] := 0; {Set Strobe} TVicLPT1.ControlPortBit[1] := 1; {Write Enable} TVicLPT1.DataPort := C; TVicLPT1.ControlPortBit[0] := 1; {Clear Strobe} Timer := - Timeout; while (Timer < Timeout) and (TVicLPT1.StatusPortBit[5] = 1) do //Wait for ACK Timer := Timer + 1; if (Timer >= Timeout) then begin ListBox2.Items.Add('Error : No Connection To Data Server (ERR1)'); TVicLPT1.ControlPortBit[0] := 0; //Set Strobe end else begin TVicLPT1.ControlPortBit[0] := 0; //Set Strobe Timer := - Timeout; while (Timer < Timeout) and (TVicLPT1.StatusPortBit[5] = 0) do //Wait for ACK Timer := Timer + 1; if (Timer >= Timeout) then begin ListBox2.Items.Add('Error : Invalid Acknowledge From Data Server (ERR2)'); TVicLPT1.ControlPortBit[0] := 0; //Set Strobe end; TVicLPT1.DataPort := $FF; end; end; procedure TForm1.SpeedButton1Click(Sender: TObject); begin Form2.TrackBar1.Position := 0; Form2.TrackBar2.Position := 128; Form2.Label3.CAPTION := 'Coefficient : 128'; Form2.Label1.CAPTION := 'Every 0 minute(s) and 0 second(s) and 2 hundredth(s) of seocond.'; Form2.RadioButton1.checked := True; Form2.RadioButton2.checked := False; Form2.CheckBox1.checked := False; Form2.CheckBox2.checked := True; Form2.CheckBox3.checked := False; Form2.ShowModal; end; procedure TForm1.PageControl1Change(Sender: TObject); var I, ii, X: Integer; Error_in_FF: BOOL; begin if CheckBox1.checked then begin SetBit9; for I := 1 to 32 do WriteNow($80 + I - 1); ClrBit9; end; for I := 1 to 100 do begin WithFiles[I] := False; FilterNeeded[I] := False; end; ComboBox1.Clear; ListBox2.Clear; if OpenedReportFile then closeFile(ReportFile); Assignfile(ReportFile, Edit1.Text + '.dat'); rewrite(ReportFile); OpenedReportFile := True; if PageControl1.ActivePage = TabSheet2 then begin StringGrid2.Cells[0, 0] := 'Number of Analog Inputs'; X := 0; for I := 0 to StringGrid1.RowCount - 2 do if StringGrid1.Cells[0, I] = 'AI' then X := X + 1; StringGrid2.Cells[1, 0] := IntToStr(X); StringGrid2.Cells[0, 1] := 'Number of Digital Inputs'; X := 0; for I := 0 to StringGrid1.RowCount - 2 do if StringGrid1.Cells[0, I] = 'DI' then X := X + 1; StringGrid2.Cells[1, 1] := IntToStr(X); StringGrid2.Cells[0, 2] := 'Number of Analog Outputs'; X := 0; for I := 0 to StringGrid1.RowCount - 2 do if StringGrid1.Cells[0, I] = 'AO' then X := X + 1; StringGrid2.Cells[1, 2] := IntToStr(X); StringGrid2.Cells[0, 3] := 'Number of Digital Outputs'; X := 0; for I := 0 to StringGrid1.RowCount - 2 do if StringGrid1.Cells[0, I] = 'DO' then X := X + 1; StringGrid2.Cells[1, 3] := IntToStr(X); for I := 0 to StringGrid1.RowCount - 2 do if Copy(StringGrid1.Cells[0, I], 2, 1) = 'I' then if StrToInt(StringGrid1.Cells[4, I]) mod 2 = 1 then begin ComboBox1.Items.Add(ListBox1.Items.Strings[I]); ComboBox1.Text := ListBox1.Items.Strings[I]; end; for I := 0 to StringGrid1.RowCount - 2 do begin for ii := 1 to 10 do begin LastValues[I + 1, ii] := 0; LastValuesX[I + 1, ii] := 0; end; CurrentValue[I + 1] := 0; LastChecked[I + 1] := I; Period[I + 1] := trunc(exp(StrToInt(StringGrid1.Cells[3, I]) * 0.0001846422)); end; for I := 0 to StringGrid1.RowCount - 2 do if StringGrid1.Cells[0, I] = 'AO' then begin if (StringGrid1.Cells[4, I] = '0') then begin Assignfile(Files[I + 1], 'AO' + StringGrid1.Cells[1, I] + '_0.dat'); reset(Files[I + 1]); WithFiles[I + 1] := True; end else WithFiles[I + 1] := False; end else if StringGrid1.Cells[0, I] = 'DO' then begin if (StringGrid1.Cells[4, I] = '0') then begin Assignfile(Files[I + 1], 'DO' + StringGrid1.Cells[1, I] + '_' + StringGrid1.Cells[2, I] + '.dat'); reset(Files[I + 1]); WithFiles[I + 1] := True; end else WithFiles[I + 1] := False; end else if StringGrid1.Cells[0, I] = 'AI' then begin if (trunc(StrToInt(StringGrid1.Cells[4, I]) / 2) mod 2 = 1) then begin Assignfile(Files[I + 1], 'AI' + StringGrid1.Cells[1, I] + '_' + StringGrid1.Cells[2, I] + '.dat'); rewrite(Files[I + 1]); write (ReportFile, 'AI' + StringGrid1.Cells[1, I] + '_' + StringGrid1.Cells[2, I] + Chr(9)); WithFiles[I + 1] := True; end else WithFiles[I + 1] := False; if (trunc(StrToInt(StringGrid1.Cells[4, I]) / 4) mod 2 = 1) then begin Error_in_FF := ReadFilterFile(I); if Error_in_FF = False then FilterNeeded[I + 1] := True; end; end else if StringGrid1.Cells[0, I] = 'DI' then begin if (trunc(StrToInt(StringGrid1.Cells[4, I]) / 2) mod 2 = 1) then begin Assignfile(Files[I + 1], 'DI' + StringGrid1.Cells[1, I] + '_' + StringGrid1.Cells[2, I] + '.dat'); rewrite(Files[I + 1]); write (ReportFile, 'DI' + StringGrid1.Cells[1, I] + '_' + StringGrid1.Cells[2, I] + Chr(9)); WithFiles[I + 1] := True; end else WithFiles[I + 1] := False; if (trunc(StrToInt(StringGrid1.Cells[4, I]) / 4) mod 2 = 1) then begin Error_in_FF := ReadFilterFile(I); if Error_in_FF = False then FilterNeeded[I + 1] := True; end; end; end; writeLn(ReportFile, ''); write (ReportFile, '--------------------------------------------------'); end; procedure TForm1.FormActivate(Sender: TObject); begin OpenedReportFile := False; Image1.Canvas.MOVETO(0, 100); No_Of_Channels := 0; PageControl1.ActivePage := TabSheet1; TVicLPT1.Active := 1; if TVicLPT1.Active = 0 then begin ShowMessage('Error : Unable to open LPT port'); Application.Terminate; end; Timeout := 300; SpeedButton7Click(Sender); Timeout := 30000; end; procedure TForm1.Timer1Timer(Sender: TObject); var I: Integer; ReadItNow: Integer; begin Application.HandleMessage; Timer1.ENABLED := False; writeLn(ReportFile); for I := 1 to No_Of_Channels do begin LastChecked[I] := LastChecked[I] + 1; if Period[I] <= LastChecked[I] then begin if StringGrid1.Cells[0, I - 1] = 'AI' then begin SetBit9; WriteNow($60 + StrToInt(StringGrid1.Cells[1, I - 1])); ClrBit9; WriteNow(StrToInt(StringGrid1.Cells[2, I - 1])); ReadItNow := ReadNow; if ReadItNow <> -1 then begin if FilterNeeded[I] = True then begin LastValuesX[I, CurrentValue[I]] := ReadItNow; LastValues[I, CurrentValue[I]] := Filter(I); end else LastValues[I, CurrentValue[I]] := ReadItNow; CurrentValue[I] := (CurrentValue[I] + 1) mod 10; if WithFiles[I] then begin writeLn(Files[I], ReadItNow); write (ReportFile, IntToStr(ReadItNow) + Chr(9)); end; end; if ComboBox1.Text = ListBox1.Items.Strings[I - 1] then begin MonX := MonX + 1; if MonX = 280 then begin Image1.Canvas.FillRect(Image1.Canvas.ClipRect); Image1.Canvas.MOVETO(0, 255 - LastValues[I, CurrentValue[I]]); MonX := 0; end else Image1.Canvas.LineTo(MonX, 255 - LastValues[I, CurrentValue[I]]); end; LastChecked[I] := 0; end else if StringGrid1.Cells[0, I - 1] = 'DI' then begin SetBit9; WriteNow($40 + StrToInt(StringGrid1.Cells[1, I - 1])); ClrBit9; WriteNow(StrToInt(StringGrid1.Cells[2, I - 1])); ReadItNow := ReadNow; if ReadItNow <> -1 then begin if FilterNeeded[I] = True then begin LastValuesX[I, CurrentValue[I]] := ReadItNow; LastValues[I, CurrentValue[I]] := Filter(I); end else LastValues[I, CurrentValue[I]] := ReadItNow; CurrentValue[I] := (CurrentValue[I] + 1) mod 10; if WithFiles[I] then begin if ReadItNow = 255 then writeLn(Files[I], StringGrid1.Cells[6, I - 1]) else writeLn(Files[I], 0); if ReadItNow = 255 then write (ReportFile, StringGrid1.Cells[6, I - 1] + Chr(9)) else write (ReportFile, '0' + Chr(9)); end; end; if ComboBox1.Text = ListBox1.Items.Strings[I - 1] then begin MonX := MonX + 1; if MonX = 280 then begin Image1.Canvas.FillRect(Image1.Canvas.ClipRect); Image1.Canvas.MOVETO(0, 255 - LastValues[I, CurrentValue[I]]); MonX := 0; end else Image1.Canvas.LineTo(MonX, 255 - LastValues[I, CurrentValue[I]]); end; LastChecked[I] := 0; end else if StringGrid1.Cells[0, I - 1] = 'AO' then begin LastChecked[I] := 0; SetBit9; WriteNow($20 + StrToInt(StringGrid1.Cells[1, I - 1])); ClrBit9; if WithFiles[I] then begin readLN(Files[I], ReadItNow); if EOF(Files[I]) then begin reset(Files[I]); end; WriteNow(FlipNow(ReadItNow)); end else begin if StringGrid1.Cells[0, StrToInt(StringGrid1.Cells[5, I - 1])] = 'AI' then WriteNow(FlipNow(LastValues[StrToInt(StringGrid1.Cells[5, I - 1]) + 1, CurrentValue[StrToInt(StringGrid1.Cells[5, I - 1]) + 1]])) else WriteNow(FlipNow(trunc(LastValues[StrToInt(StringGrid1.Cells[5, I - 1]) + 1, CurrentValue[StrToInt(StringGrid1.Cells[5, I - 1]) + 1]] / 255 * StrToInt(StringGrid1.Cells[6, I - 1])))); end; end else if StringGrid1.Cells[0, I - 1] = 'DO' then begin LastChecked[I] := 0; SetBit9; WriteNow(StrToInt(StringGrid1.Cells[1, I - 1])); ClrBit9; if WithFiles[I] then begin readLN(Files[I], ReadItNow); if EOF(Files[I]) then begin reset(Files[I]); end; if ReadItNow > StrToInt(StringGrid1.Cells[6, I - 1]) then WriteNow(4 + StrToInt(StringGrid1.Cells[2, I - 1])) else WriteNow(StrToInt(StringGrid1.Cells[2, I - 1])); end else begin if StringGrid1.Cells[0, StrToInt(StringGrid1.Cells[5, I - 1])] = 'AI' then begin if LastValues[StrToInt(StringGrid1.Cells[5, I - 1]) + 1, CurrentValue[StrToInt(StringGrid1.Cells[5, I - 1]) + 1]] > StrToInt(StringGrid1.Cells[6, I - 1]) then WriteNow(4 + StrToInt(StringGrid1.Cells[2, I - 1])) else WriteNow(StrToInt(StringGrid1.Cells[2, I - 1])); end else WriteNow(trunc(LastValues[StrToInt(StringGrid1.Cells[5, I - 1]) + 1, CurrentValue[StrToInt(StringGrid1.Cells[5, I - 1]) + 1]] / 250) * 4 + StrToInt(StringGrid1.Cells[2, I - 1])); end; end; end; end; if CheckBox2.checked = False then Timer1.ENABLED := True; end; procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); var I: Integer; begin if OpenedReportFile then closeFile(ReportFile); TVicLPT1.Active := 0; for I := 1 to 100 do if WithFiles[I] then closeFile(Files[I]); end; procedure TForm1.SpeedButton2Click(Sender: TObject); begin SpeedButton3.ENABLED := True; SpeedButton2.ENABLED := False; StopPressed := False; if CheckBox2.checked = True then begin while StopPressed = False do Timer1Timer(Sender); end else Timer1.ENABLED := True; end; procedure TForm1.SpeedButton3Click(Sender: TObject); begin Timer1.ENABLED := False; TVicLPT1.Active := 0; StopPressed := True; SpeedButton2.ENABLED := True; SpeedButton3.ENABLED := False; end; procedure TForm1.SpeedButton6Click(Sender: TObject); begin Form1.CLOSE; end; procedure TForm1.SpeedButton5Click(Sender: TObject); var I, J: Integer; begin SaveDialog1.Filename := ''; SaveDialog1.Execute; if SaveDialog1.Filename <> '' then begin ListBox3.Clear; for I := 1 to StringGrid1.RowCount - 1 do for J := 1 to 7 do if StringGrid1.Cells[J - 1, I - 1] = '' then ListBox3.Items.Add('NOP') else ListBox3.Items.Add(StringGrid1.Cells[J - 1, I - 1]); ListBox3.Items.SaveToFile(SaveDialog1.Filename); end; end; procedure TForm1.SpeedButton4Click(Sender: TObject); var I, J: Integer; begin OpenDialog1.Filename := ''; OpenDialog1.Execute; if OpenDialog1.Filename <> '' then begin ListBox3.Clear; ListBox3.Items.LOADFROMFILE(OpenDialog1.Filename); if ListBox3.Items.Count mod 7 <> 0 then ShowMessage('Unknown File Format') else begin StringGrid1.RowCount := trunc(ListBox3.Items.Count / 7) + 1; No_Of_Channels := StringGrid1.RowCount - 1; for J := 1 to 7 do StringGrid1.Cells[J - 1, 0] := ''; for I := 1 to trunc(ListBox3.Items.Count / 7) do for J := 1 to 7 do if ListBox3.Items.Strings[(I - 1) * 7 + J - 1] = 'NOP' then StringGrid1.Cells[J - 1, I - 1] := '' else StringGrid1.Cells[J - 1, I - 1] := ListBox3.Items.Strings[(I - 1) * 7 + J - 1]; ListBox1.Clear; for I := 1 to trunc(ListBox3.Items.Count / 7) do ListBox1.Items.Add('Module ' + StringGrid1.Cells[1, I - 1] + '/Channel ' + StringGrid1.Cells[0, I - 1] + StringGrid1.Cells[2, I - 1]); end; end; end; procedure TForm1.SpeedButton8Click(Sender: TObject); var J: Integer; begin ListBox1.Clear; StringGrid1.RowCount := 1; No_Of_Channels := 0; for J := 1 to 7 do StringGrid1.Cells[J - 1, 0] := ''; end; procedure TForm1.SpeedButton7Click(Sender: TObject); var I, X,U: Integer; begin ListBox4.Clear; Timeout := 300; for I := 1 to 32 do begin SetBit9; WriteNow($40 + I - 1); ClrBit9; WriteNow(0); X := ReadNow; U := 0; if X <> -1 then if (X = 255) or (X = 0) then U:=U+1; SetBit9; WriteNow($40 + I - 1); ClrBit9; WriteNow(0); X := ReadNow; if X <> -1 then if (X = 255) or (X = 0) then U:=U+1; SetBit9; WriteNow($40 + I - 1); ClrBit9; WriteNow(0); X := ReadNow; if X <> -1 then if (X = 255) or (X = 0) then U:=U+1; if U >1 then ListBox4.Items.Add('Module ' + IntToStr(I - 1)); end; Timeout := 30000; end; procedure TForm1.ComboBox2Change(Sender: TObject); begin if ComboBox2.Text = 'LPT1' then TVicLPT1.CurrentLPT := 1 else TVicLPT1.CurrentLPT := 2; end; end. {******* UNIT2.PAS *******} unit Unit2; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, Buttons; type TForm2 = class(TForm) ListBox1: TListBox; ListBox2: TListBox; TrackBar1: TTrackBar; Label1: TLabel; Label2: TLabel; GroupBox1: TGroupBox; GroupBox2: TGroupBox; RadioButton1: TRadioButton; RadioButton2: TRadioButton; CheckBox1: TCheckBox; CheckBox2: TCheckBox; SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; Label3: TLabel; TrackBar2: TTrackBar; Label4: TLabel; CheckBox3: TCheckBox; OpenDialog1: TOpenDialog; procedure TrackBar1Change(Sender: TObject); procedure ListBox2Click(Sender: TObject); procedure FormActivate(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); procedure RadioButton2Enter(Sender: TObject); procedure TrackBar2Change(Sender: TObject); procedure CheckBox3Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form2: TForm2; implementation uses Unit3, Unit1; {$R *.DFM} procedure TForm2.TrackBar1Change(Sender: TObject); var X: Double; Minutes, Seconds, HSeconds: Integer; begin X := trunc(2 * exp(0.0001846422 * TrackBar1.Position)); Minutes := trunc(X / 6000); Seconds := trunc((X - Minutes * 6000) / 100); HSeconds := trunc(X - trunc(X / 100) * 100); Label1.CAPTION := 'Every ' + IntToStr(Minutes) + ' minute(s) and ' + IntToStr(Seconds) + ' second(s) and ' + IntToStr(HSeconds) + ' hundredth(s) of seocond.'; end; procedure TForm2.ListBox2Click(Sender: TObject); var I: Integer; begin for I := 0 to ListBox2.Items.Count do if ListBox2.Selected[I] = True then break; if I < 8 then Label2.CAPTION := 'Analog Input' else if I > 12 then Label2.CAPTION := 'Digital Output' else if I = 12 then Label2.CAPTION := 'Analog Output' else Label2.CAPTION := 'Digital Input'; if I < 12 then begin GroupBox1.Visible := True; GroupBox2.Visible := False; end else begin GroupBox1.Visible := False; GroupBox2.Visible := True; end; end; procedure TForm2.FormActivate(Sender: TObject); begin GroupBox2.Top := 30; end; procedure TForm2.SpeedButton1Click(Sender: TObject); var R, M, C, I, Option: Integer; begin M := -1; C := -1; Coef := TrackBar2.Position; for I := 0 to ListBox1.Items.Count - 1 do if ListBox1.Selected[I] = True then M := I; for I := 0 to ListBox2.Items.Count - 1 do if ListBox2.Selected[I] = True then C := I; if (M = -1) or (C = -1) then ShowMessage('Select a Module and a Channel') else begin R := Form1.StringGrid1.RowCount - 1; if C < 8 then begin Form1.StringGrid1.Cells[0, R] := 'AI'; Form1.StringGrid1.Cells[1, R] := IntToStr(M); Form1.StringGrid1.Cells[2, R] := IntToStr(C); Form1.StringGrid1.Cells[3, R] := IntToStr(TrackBar1.Position); if CheckBox1.checked then Option := 1 else Option := 0; if CheckBox2.checked then Option := Option + 2; if CheckBox3.checked then Option := Option + 4; Form1.StringGrid1.Cells[4, R] := IntToStr(Option); Form1.ListBox1.Items.Add('Module ' + IntToStr(M) + '/Channel AI' + IntToStr(C)); Form1.StringGrid1.Cells[5, R] := OpenDialog1.FileName; Form1.StringGrid1.Cells[6, R] := IntToStr(Coef); end else if C = 12 then begin Form1.StringGrid1.Cells[0, R] := 'AO'; Form1.StringGrid1.Cells[1, R] := IntToStr(M); Form1.StringGrid1.Cells[2, R] := '0'; Form1.StringGrid1.Cells[3, R] := IntToStr(TrackBar1.Position); if RadioButton1.checked then Option := 0 else Option := 1; Form1.StringGrid1.Cells[4, R] := IntToStr(Option); Form1.ListBox1.Items.Add('Module' + IntToStr(M) + '/Channel AO' + IntToStr(0)); if RadioButton2.checked = True then Form1.StringGrid1.Cells[5, R] := IntToStr(LeadChannel); Form1.StringGrid1.Cells[6, R] := IntToStr(Coef); end else if C > 12 then begin Form1.StringGrid1.Cells[0, R] := 'DO'; Form1.StringGrid1.Cells[1, R] := IntToStr(M); Form1.StringGrid1.Cells[2, R] := IntToStr(C - 13); Form1.StringGrid1.Cells[3, R] := IntToStr(TrackBar1.Position); if RadioButton1.checked then Option := 0 else Option := 1; Form1.StringGrid1.Cells[4, R] := IntToStr(Option); Form1.ListBox1.Items.Add('Module ' + IntToStr(M) + '/Channel DO' + IntToStr(C - 13)); if RadioButton2.checked = True then Form1.StringGrid1.Cells[5, R] := IntToStr(LeadChannel); Form1.StringGrid1.Cells[6, R] := IntToStr(Coef); end else begin Form1.StringGrid1.Cells[0, R] := 'DI'; Form1.StringGrid1.Cells[1, R] := IntToStr(M); Form1.StringGrid1.Cells[2, R] := IntToStr(C - 8); Form1.StringGrid1.Cells[3, R] := IntToStr(TrackBar1.Position); if CheckBox1.checked then Option := 1 else Option := 0; if CheckBox2.checked then Option := Option + 2; if CheckBox3.checked then Option := Option + 4; Form1.StringGrid1.Cells[4, R] := IntToStr(Option); Form1.ListBox1.Items.Add('Module ' + IntToStr(M) + '/Channel DI' + IntToStr(C - 8)); Form1.StringGrid1.Cells[5, R] := OpenDialog1.FileName; Form1.StringGrid1.Cells[6, R] := IntToStr(Coef); end; Form1.StringGrid1.RowCount := Form1.StringGrid1.RowCount + 1; No_Of_Channels := No_Of_Channels + 1; Form2.CLOSE; end; end; procedure TForm2.SpeedButton2Click(Sender: TObject); begin Form2.CLOSE; end; procedure TForm2.RadioButton2Enter(Sender: TObject); begin Form3.ShowModal; ListBox2.SetFocus; end; procedure TForm2.TrackBar2Change(Sender: TObject); begin Label3.CAPTION := 'Coefficient : ' + IntToStr(TrackBar2.Position); Coef := TrackBar2.Position; end; procedure TForm2.CheckBox3Click(Sender: TObject); begin if CheckBox3.checked = True then begin OpenDialog1.Filename := ''; OpenDialog1.Execute; end; end; end. {******* UNIT3.PAS *******} unit Unit3; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons; type TForm3 = class(TForm) ListBox1: TListBox; SpeedButton1: TSpeedButton; SpeedButton2: TSpeedButton; procedure FormActivate(Sender: TObject); procedure SpeedButton2Click(Sender: TObject); procedure SpeedButton1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form3: TForm3; implementation uses Unit1, Unit2; {$R *.DFM} procedure TForm3.FormActivate(Sender: TObject); var I: Integer; S: string; begin ListBox1.Clear; for I := 0 to Form1.StringGrid1.RowCount - 2 do begin S := Form1.StringGrid1.Cells[0, I]; if S[2] = 'I' then ListBox1.Items.Add(Form1.ListBox1.Items.Strings[I]); end; end; procedure TForm3.SpeedButton2Click(Sender: TObject); begin Form2.RadioButton2.checked := False; Form2.RadioButton1.checked := True; Form3.CLOSE; end; procedure TForm3.SpeedButton1Click(Sender: TObject); var I, J, M: Integer; begin M := -1; for J := 0 to ListBox1.Items.Count - 1 do if ListBox1.Selected[J] = True then M := J; if M = -1 then ShowMessage('Select a channel') else begin for I := 0 to Form1.ListBox1.Items.Count - 1 do if Form1.ListBox1.Items.Strings[I] = ListBox1.Items.Strings[M] then LeadChannel := I; Form2.RadioButton2.checked := True; Form3.CLOSE; end; end; end.