You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
3.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace USB2XXX
{
class USB2ADS1256
{
//定义函数返回错误代码
public const Int32 ADS1256_SUCCESS = (0); //函数执行成功
public const Int32 ADS1256_ERR_NOT_SUPPORT = (-1); //适配器不支持该函数
public const Int32 ADS1256_ERR_USB_WRITE_FAIL = (-2); //USB写数据失败
public const Int32 ADS1256_ERR_USB_READ_FAIL = (-3); //USB读数据失败
public const Int32 ADS1256_ERR_CMD_FAIL = (-4); //命令执行失败
public const Int32 ADS1256_ERR_CH_NO_INIT = (-5); //该通道未初始化
//定义ADS采样率
public const Byte ADS1256_DRATE_30000SPS = 0xF0;
public const Byte ADS1256_DRATE_15000SPS = 0xE0;
public const Byte ADS1256_DRATE_7500SPS = 0xD0;
public const Byte ADS1256_DRATE_3750SPS = 0xC0;
public const Byte ADS1256_DRATE_2000SPS = 0xB0;
public const Byte ADS1256_DRATE_1000SPS = 0xA1;
public const Byte ADS1256_DRATE_500SPS = 0x92;
public const Byte ADS1256_DRATE_100SPS = 0x82;
public const Byte ADS1256_DRATE_60SPS = 0x72;
public const Byte ADS1256_DRATE_50SPS = 0x63;
public const Byte ADS1256_DRATE_30SPS = 0x53;
public const Byte ADS1256_DRATE_25SPS = 0x43;
public const Byte ADS1256_DRATE_15SPS = 0x33;
public const Byte ADS1256_DRATE_10SPS = 0x23;
public const Byte ADS1256_DRATE_5SPS = 0x13;
public const Byte ADS1256_DRATE_2_5SPS = 0x03;
//定义初始化ADS1256的数据类型
public struct ADS1256_CONFIG
{
UInt16 SampleRate; //采样率
Byte PGA; //内部增益2^n
Byte BufferEn; //1使能Buffer,0禁止Buffer
UInt32 SampleMode; //两个bit控制一个通道00不使用该通道01该通道为单端模式10该通道为差分负极11该通道为差分正极
}
/**
* @brief ADS1256
* @param DevHandle
* @param Channel ADS01
* @param pConfig ADS1256
* @retval 0
*/
[DllImport("USB2XXX.dll")]
public static extern Int32 ADS1256_Init(Int32 DevHandle,Byte Channel,ref ADS1256_CONFIG pConfig);
/**
* @brief ADSADS
* @param DevHandle
* @param Channel ADS01
* @retval 0
*/
[DllImport("USB2XXX.dll")]
public static extern Int32 ADS1256_Start(Int32 DevHandle,Byte Channel);
/**
* @brief ADC
* @param DevHandle
* @param Channel ADS01
* @param pData
* @retval 00ADC
*/
[DllImport("USB2XXX.dll")]
public static extern Int32 ADS1256_Read(Int32 DevHandle,Byte Channel,Int32[] pData);
/**
* @brief ADSADS
* @param DevHandle
* @param Channel ADS01
* @retval 0
*/
[DllImport("USB2XXX.dll")]
public static extern Int32 ADS1256_Stop(Int32 DevHandle,Byte Channel);
}
}