Giáo trình Đo lường và điều khiển bằng máy tính - Chương 5: Card thu thập tín hiệu và điều khiển

PCL-818L là card ISA có nhiều chức năng dùng để đo lường

và điều khiển. Do tính năng ưu việt của card, việc tìm hiểu hoạt

động của nó rất cần thiết để tiếp cận kỹ thuật thu thập số liệu

bằng máy tính DAS (Data Acquisition System).

Sau đây là các chức năng chính của card:

- Chuyển đổi A/D 16 kênh 12 bit tốc độ lấy mẫu 40000/s

- Chuyển đổi D/A 1 kênh 12 bit

- 16 ngõ vào digital TTL

- 16 ngõ ra digital TTL

- 1 Bộ đếm/ định thời 16 bit cho người dùng

pdf43 trang | Chuyên mục: Công Nghệ Tri Thức & Máy Học | Chia sẻ: dkS00TYs | Lượt xem: 1667 | Lượt tải: 1download
Tóm tắt nội dung Giáo trình Đo lường và điều khiển bằng máy tính - Chương 5: Card thu thập tín hiệu và điều khiển, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
in; 
uses 
 Forms, 
 formstar in 'formstar.pas' {frmstart}, 
 formrun in 'formrun.pas' {frmrun}, 
 Driver in '..\..\..\include\driver.pas', 
 global in 'global.pas'; 
{$R *.RES} 
begin 
 Application.Initialize; 
 Application.CreateForm(Tfrmstart, frmstart); 
 Application.CreateForm(Tfrmrun, frmrun); 
 Application.Run; 
end. 
unit Formstar; 
interface 
uses 
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
 StdCtrls, Driver, Global, Menus; 
Tác giả: TS Nguyễn Đức Thành Trang 145 
Thành phố Hồ Chí Minh, tháng 4 năm 2006 
type 
 Tfrmstart = class(TForm) 
 labSelDev: TLabel; 
 cmdRun: TButton; 
 labIOAddr: TLabel; 
 cmdExit: TButton; 
 lstDevice: TListBox; 
 txtIOAddr: TEdit; 
 procedure cmdExitClick(Sender: TObject); 
 procedure cmdRunClick(Sender: TObject); 
 procedure FormCreate(Sender: TObject); 
 procedure lstDeviceClick(Sender: TObject); 
 private 
 { Private declarations } 
 public 
 { Public declarations } 
 end; 
var 
 frmstart: Tfrmstart; 
implementation 
uses formrun; 
var 
 lpDevFeatures : DEVFEATURES; 
 gnNumOfSubdevices : Smallint; 
 Response : Integer; 
{$R *.DFM} 
procedure Tfrmstart.cmdExitClick(Sender: TObject); 
begin 
 if bRun then 
 DRV_DeviceClose(DeviceHandle); 
 close; 
end; 
procedure Tfrmstart.cmdRunClick(Sender: TObject); 
var 
 I, Code: Integer; 
begin 
 { Get text from TEdit control } 
 Val('$' + txtIOAddr.Text, gwPort, Code); 
 FormRun.frmRun.Show; 
end; 
procedure Tfrmstart.FormCreate(Sender: TObject); 
CHƯƠNG 5: CARD THU THẬP TÍN HIỆU VÀ ĐIỀU KHIỂN TRANG 146 
var 
 MaxEntries, OutEntries : Smallint; 
 NumOfDevice : Smallint; 
 i, ii : Integer; 
 tempStr : String; 
 testRes : boolean; 
begin 
 gwPort := $300; 
 bRun := False; 
 { Add type of PC Laboratory Card } 
 ErrCde := DRV_DeviceGetList(DeviceList[0], MaxEntries, OutEntries); 
 If (ErrCde 0) Then 
 begin 
 DRV_GetErrorMessage(ErrCde, pszErrMsg); 
 Response := Application.MessageBox(pszErrMsg, 'Error!!', MB_OK); 
 Exit; 
 end; 
 { Here MaxEntries = OutEntries } 
 ErrCde := DRV_DeviceGetNumOfList(MaxEntries); 
 If (ErrCde 0) Then 
 begin 
 DRV_GetErrorMessage(ErrCde, pszErrMsg); 
 Response := Application.MessageBox(pszErrMsg, 'Error!!', MB_OK); 
 Exit; 
 end; 
 For i := 0 To (MaxEntries - 1) do 
 begin 
 tempStr := ''; 
 For ii := 0 To MaxDevNameLen do 
 tempStr := tempStr + DeviceList[i].szDeviceName[ii]; 
 lstDevice.Items.Add(tempStr); 
 end; 
 labIOAddr.Enabled := False; 
 txtIOAddr.Enabled := False; 
 cmdRun.Enabled := False; 
end; 
procedure Tfrmstart.lstDeviceClick(Sender: TObject); 
var 
 tempNum, i, ii : Integer; 
 nOutEntries : Smallint; 
 TestRes : Boolean; 
Tác giả: TS Nguyễn Đức Thành Trang 147 
Thành phố Hồ Chí Minh, tháng 4 năm 2006 
 TempStr : String; 
begin 
 tempNum := Pos('DEMO', lstDevice.Items[lstDevice.ItemIndex]); 
 if (tempNum 0) then 
 TestRes := True 
 else 
 TestRes := False; 
 { Avoid to open Advantech Demo Card } 
 If (TestRes) Then 
 begin 
 labIOAddr.Enabled := False; 
 txtIOAddr.Enabled := False; 
 cmdRun.Enabled := False; 
 end; 
 If (Not TestRes) Then 
 begin 
 { Check if there is any device attached on this COM or CAN } 
 dwDeviceNum := DeviceList[lstDevice.ItemIndex].dwDeviceNum; 
 txtIOAddr.Text := '300'; 
 labIOAddr.Enabled := True; 
 txtIOAddr.Enabled := True; 
 cmdRun.Enabled := True; 
 end; 
end; 
end. 
unit formrun; 
interface 
uses 
 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, 
 StdCtrls, ExtCtrls, Driver, Global, Menus; 
type 
 Tfrmrun = class(TForm) 
 CmdExit: TButton; 
 GroupSample1: TGroupBox; 
 PictureBit0: Timage; 
 PictureBit1: TImage; 
 PictureBit2: TImage; 
 PictureBit3: TImage; 
 PictureBit4: TImage; 
 PictureBit5: TImage; 
 PictureBit6: TImage; 
CHƯƠNG 5: CARD THU THẬP TÍN HIỆU VÀ ĐIỀU KHIỂN TRANG 148 
 PictureBit7: TImage; 
 CmdBit0: TButton; 
 CmdBit1: TButton; 
 CmdBit2: TButton; 
 CmdBit3: TButton; 
 CmdBit4: TButton; 
 CmdBit5: TButton; 
 CmdBit6: TButton; 
 CmdBit7: TButton; 
 labBit0: TLabel; 
 labBit1: TLabel; 
 labBit2: TLabel; 
 labBit3: TLabel; 
 labBit4: TLabel; 
 labBit5: TLabel; 
 labBit6: TLabel; 
 labBit7: TLabel; 
 GroupSample2: TGroupBox; 
 PictureBit8: TImage; 
 PictureBit9: TImage; 
 PictureBitA: TImage; 
 PictureBitB: TImage; 
 PictureBitC: TImage; 
 PictureBitD: TImage; 
 PictureBitE: TImage; 
 PictureBitF: TImage; 
 Label1: TLabel; 
 Label2: TLabel; 
 Label3: TLabel; 
 Label4: TLabel; 
 Label5: TLabel; 
 Label6: TLabel; 
 Label7: TLabel; 
 Label8: TLabel; 
 CmdBit8: TButton; 
 CmdBit9: TButton; 
 CmdBitA: TButton; 
 CmdBitB: TButton; 
 CmdBitC: TButton; 
 CmdBitD: TButton; 
 CmdBitE: TButton; 
Tác giả: TS Nguyễn Đức Thành Trang 149 
Thành phố Hồ Chí Minh, tháng 4 năm 2006 
 CmdBitF: TButton; 
 txtDiValue: TEdit; 
 cmdRead: TButton; 
 procedure CmdExitClick(Sender: TObject); 
 procedure CmdBitClick(Sender: TObject); 
 procedure FormCreate(Sender: TObject); 
 procedure PictureClick(Sender: TObject); 
 procedure cmdReadClick(Sender: TObject); 
 private 
 { Private declarations } 
 DoValue, DiValue : Word; 
 procedure UpdateLED(Bit : Integer ; Mode : Boolean); 
 public 
 { Public declarations } 
 end; 
var 
 frmrun: Tfrmrun; 
implementation 
uses formstar; 
const 
 LedON = True; 
 LedOFF = False; 
var 
 Response: Integer; 
{$R *.DFM} 
Function DoBit(bit : Integer) : Word; 
var 
 temp, i : Integer; 
begin 
 temp := 1; 
 If bit >= 1 Then 
 For i := 1 To bit do 
 temp := temp * 2; 
 DoBit := temp; 
end; 
procedure Tfrmrun.UpdateLED(Bit : Integer; Mode : Boolean); 
begin 
 if Mode then 
 DoValue := DoValue + DoBit(Bit) 
 else 
 DoValue := DoValue - DoBit(Bit); 
CHƯƠNG 5: CARD THU THẬP TÍN HIỆU VÀ ĐIỀU KHIỂN TRANG 150 
 ErrCde := DRV_outpw(dwDeviceNum, gwPort, DoValue); 
 If (ErrCde 0) Then 
 begin 
 DRV_GetErrorMessage(ErrCde, pszErrMsg); 
 Response := Application.MessageBox(pszErrMsg, 'Error!!', MB_OK); 
 Exit; 
 end; 
end; 
procedure Tfrmrun.CmdExitClick(Sender: TObject); 
begin 
 frmRun.Close; 
 Formstar.frmstart.Show; 
end; 
procedure Tfrmrun.CmdBitClick(Sender: TObject); 
var 
 tempBit : Integer; 
begin 
 tempBit := (Sender as TButton).Tag; 
 UpdateLED(tempBit, LedON); 
 (Sender as TButton).Visible := False; 
 case tempBit of 
 0 : PictureBit0.Visible := True; 
 1 : PictureBit1.Visible := True; 
 2 : PictureBit2.Visible := True; 
 3 : PictureBit3.Visible := True; 
 4 : PictureBit4.Visible := True; 
 5 : PictureBit5.Visible := True; 
 6 : PictureBit6.Visible := True; 
 7 : PictureBit7.Visible := True; 
 8 : PictureBit8.Visible := True; 
 9 : PictureBit9.Visible := True; 
 10 : PictureBitA.Visible := True; 
 11 : PictureBitB.Visible := True; 
 12 : PictureBitC.Visible := True; 
 13 : PictureBitD.Visible := True; 
 14 : PictureBitE.Visible := True; 
 15 : PictureBitF.Visible := True; 
 end; 
end; 
procedure Tfrmrun.PictureClick(Sender: TObject); 
var 
Tác giả: TS Nguyễn Đức Thành Trang 151 
Thành phố Hồ Chí Minh, tháng 4 năm 2006 
 tempBit : Integer; 
begin 
 tempBit := (Sender as TImage).Tag; 
 UpdateLED(tempBit, LedOFF); 
 (Sender as TImage).Visible := False; 
 case tempBit of 
 0 : CmdBit0.Visible := True; 
 1 : CmdBit1.Visible := True; 
 2 : CmdBit2.Visible := True; 
 3 : CmdBit3.Visible := True; 
 4 : CmdBit4.Visible := True; 
 5 : CmdBit5.Visible := True; 
 6 : CmdBit6.Visible := True; 
 7 : CmdBit7.Visible := True; 
 8 : CmdBit8.Visible := True; 
 9 : CmdBit9.Visible := True; 
 10 : CmdBitA.Visible := True; 
 11 : CmdBitB.Visible := True; 
 12 : CmdBitC.Visible := True; 
 13 : CmdBitD.Visible := True; 
 14 : CmdBitE.Visible := True; 
 15 : CmdBitF.Visible := True; 
 end; 
end; 
procedure Tfrmrun.FormCreate(Sender: TObject); 
begin 
 DoValue := 0; 
end; 
procedure Tfrmrun.cmdReadClick(Sender: TObject); 
var 
 DiStr : string[4]; 
begin 
 ErrCde := DRV_inpw(dwDeviceNum, gwPort, DiValue); 
 If (ErrCde 0) Then 
 begin 
 DRV_GetErrorMessage(ErrCde, pszErrMsg); 
 Response := Application.MessageBox(pszErrMsg, 'Error!!', MB_OK); 
 Exit; 
 end; 
 Str(DiValue, DiStr); 
 txtDiValue.Text := DiStr; 
CHƯƠNG 5: CARD THU THẬP TÍN HIỆU VÀ ĐIỀU KHIỂN TRANG 152 
end; 
end. 
unit Global; 
interface 
uses Driver; 
type 
 lpDevList = ^PT_DEVLIST; 
 const MaxEntries = 255; 
var 
 DeviceHandle : Longint; 
 ptDevGetFeatures : PT_DeviceGetFeatures; 
 DeviceList : array [0..MaxEntries] of PT_DEVLIST; 
 SubDeviceList : array [0..MaxEntries] of PT_DEVLIST; 
 ErrCde : Longint; 
 szErrMsg : string; 
 pszErrMsg : Pchar = @szErrMsg; 
 bRun : Boolean; 
 gwPort : Smallint; 
 dwDeviceNum : Longint; 
implementation 
end. 
5.5 CARD PCI 1710 
Card PCI1710 có chức năng tương tự card PCLl818 nhưng gắn 
vào slot pci. Sơ đồ khối trình bày ở hình 5.5, lập trình card thực 
hiện thông qua driver Adsapi32 do hãng cung cấp. 
5.6 GIAO DIỆN ĐỒ HỌA 
Thay vì phải dùng ngôn ngữ lập trình để lập trình cho card, ta 
có thể dùng các phần mềm chuyên dụng của hãng, có đặc tính 
• giảm thời gian lập trình, 
• trình bày dử liệu dưới dạng bảng biểu, đồ thị, 
• lưu trữ dữ liệu trong file, 
• kết nối với các phần mềm khác. 
Các phần mềm thông dụng: LabVIEW (Laboratory Virtual 
Instrument Engineering Workbench), VISA của National 
Instruments, GenieDAQ, VisiDAQ của Advantech… 
Tác giả: TS Nguyễn Đức Thành Trang 153 
Thành phố Hồ Chí Minh, tháng 4 năm 2006 
Card PCL818 
Card PCI 1710 
Hình 5.4 Hình ảnh hai card DAS 
CHƯƠNG 5: CARD THU THẬP TÍN HIỆU VÀ ĐIỀU KHIỂN TRANG 154 
Hình 5.5 Sơ đồ khối card PCI 1710 Advantech 
Tác giả: TS Nguyễn Đức Thành Trang 155 
Thành phố Hồ Chí Minh, tháng 4 năm 2006 
Hình 5.6: Hai giao diện phần mềm thu thập số liệu 

File đính kèm:

  • pdfGiáo trình Đo lường và điều khiển bằng máy tính - Chương 5 Card thu thập tín hiệu và điều khiển.pdf
Tài liệu liên quan