資源簡介
c#訪問研華PCI1716 代碼程序,通過線程讀取PCI板卡 A/D數(shù)據(jù)轉換結果

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.Text;
using?System.Runtime.InteropServices;
namespace?BogieTest
{
????public??partial?class?Ads1716
????{
????????private?Int32?_DriverHandle;
????????public?unsafe?static?string?DRV_GetErrorMessage(Int32?ErrorCode)
????????{
????????????byte[]?buff?=?new?byte[200];
????????????string?f;
????????????fixed?(byte*?p?=?buff)
????????????{
????????????????DRV_GetErrorMessage(ErrorCode?ref??buff[0]);
????????????????f?=?Marshal.PtrToStringAnsi((IntPtr)(p));
????????????}
????????????return?f;
????????}
???????
????????unsafe?static?public?int?DRV_SelectDevice(IntPtr?hCaller?bool?GetModule?ref???Int32?DeviceNum?out?string?Description)
????????{
????????????byte[]?dec?=?new?byte[200];
????????????int?r;
????????????fixed?(byte*?p?=?dec)
????????????{
????????????????r?=?DRV_SelectDevice(hCaller?false?ref?DeviceNum?ref?dec[0]);
????????????????if?(r?==?0)
????????????????????Description?=?Marshal.PtrToStringAnsi((IntPtr)(p));
????????????????else
????????????????????Description?=?null;
????????????}
????????????return?r;
????????}
????????unsafe?public?string?DRV_DeviceOpen()
????????{
????????????int?dwErrCdei;
????????????PT_AIConfig?ptAIConfig?=?new?PT_AIConfig();
????????????try
????????????{
????????????????dwErrCde?=?Ads1716.DRV_DeviceOpen(0?ref?_DriverHandle);
????????????????if?(dwErrCde?!=?0)
????????????????{
????????????????????return?““;
????????????????}
????????????????else
????????????????{
????????????????????DRV_MAIConfig();
????????????????}
????????????????//配置增益
????????????????return?““;
????????????}
????????????catch?(System.Exception?ex)
????????????{
????????????????return?ex.Message.ToString();
????????????}
????????????return?““;
????????}
????????unsafe?public?string?DRV_DeviceClose()
????????{
????????????try
????????????{
????????????????int?result?=?Ads1716.DRV_DeviceClose(ref?_DriverHandle);
????????????????if?(result?==?0)
????????????????{
????????????????????return?““;
????????????????}
????????????????return?DRV_GetErrorMessage(result);
????????????}
????????????catch?(System.Exception?ex)
????????????{
????????????????return?ex.Message.ToString();
????????????}
????????????return?““;
????????}
????????unsafe?public?string?DRV_AIVoltageIn(ushort?chanref?float?data)
????????{
????????????PT_AIVoltageIn?ptAIVoltageIn?=?new?PT_AIVoltageIn();
????????????IntPtr?pVoltage=?Marshal.AllocHGlobal(sizeof(float));//為輸入模擬電壓指針分配內(nèi)存,其大小為一個float型變量的大小。;
????????????float[]?fVoltage?=?new?float[1];??
????????????try
????????????{
????????????????ptAIVoltageIn.chan?=?chan;
????????????????ptAIVoltageIn.gain?=?16;
????????????????ptAIVoltageIn.TrigMode?=?0;
????????????????ptAIVoltageIn.voltage?=?pVoltage;
????????????????PT_AIConfig?ptAIConfig?=?new?PT_AIConfig();
????????????????ptAIConfig.DasChan?=?chan;????????????????????????????????//設置通道
????????????????ptAIConf
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7036??2011-12-20?07:41??Ads1716Sample.cs
?????文件???????7219??2011-12-16?14:26??Ads1716Api.cs
?????文件???????2689??2011-12-16?10:39??Ads1716H.cs
-----------?---------??----------?-----??----
????????????????16944????????????????????3
評論
共有 條評論