101 lines
5.2 KiB
C#
101 lines
5.2 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using System.Runtime.InteropServices ;
|
||
|
||
namespace Sys
|
||
{
|
||
public partial class PCI2312
|
||
{
|
||
|
||
//######################## 常量定义 #################################
|
||
// CreateFileObject所用的文件操作方式控制字(可通过或指令实现多种方式并操作)
|
||
public const Int32 PCI2312_modeRead = 0x0000; // 只读文件方式
|
||
public const Int32 PCI2312_modeWrite = 0x0001; // 只写文件方式
|
||
public const Int32 PCI2312_modeReadWrite = 0x0002; // 既读又写文件方式
|
||
public const Int32 PCI2312_modeCreate = 0x1000; // 如果文件不存可以创建该文件,如果存在,则重建此文件,并清0
|
||
public const Int32 PCI2312_typeText = 0x4000; // 以文本方式操作文件
|
||
|
||
//######################## 常规通用函数 #################################
|
||
// 适用于本设备的最基本操作
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern IntPtr PCI2312_CreateDevice(Int32 DeviceID); // 创建设备对象
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_GetDeviceCount(IntPtr hDevice); // 取得设备总台数
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_GetDeviceCurrentID(IntPtr hDevice); // 取得当前设备相应的ID号
|
||
|
||
[DllImport("PCI23112_64.DLL")]
|
||
public static extern Int32 PCI2312_ListDeviceDlg(IntPtr hDevice); // 列表系统当中的所有的该PCI设备
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_ReleaseDevice(IntPtr hDevice); // 关闭设备,禁止传输,且释放资源
|
||
|
||
|
||
|
||
//####################### 数字I/O输入输出函数 #################################
|
||
// 用户可以使用WriteRegisterULong和ReadRegisterULong等函数直接控制寄存器进行I/O
|
||
// 输入输出,但使用下面两个函数更省事,它不需要您关心寄存器分配和位操作等,而只
|
||
// 需象VB等语言的属性操作那么简单地实现各开关量通道的控制。
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_SetDeviceDO( // 输出开关量状态
|
||
IntPtr hDevice, // 设备句柄
|
||
Byte[] bDOSts); // 开关状态
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_GetDeviceDI( // 取得开关量状态
|
||
IntPtr hDevice, // 设备句柄
|
||
Byte[] bDISts); // 开关状态
|
||
//####################### 中断函数 #################################
|
||
// 它由硬件信号的状态变化引起CPU产生中断事件hEventInt。
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_InitDeviceInt( // 初始化中断
|
||
IntPtr hDevice, // 设备句柄
|
||
IntPtr hEventInt); // 中断事件句柄,它由CreateSystemEvent创建
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_GetDeviceIntCount(IntPtr hDevice); // 在中断初始化后,用它取得中断服务程序产生的次数
|
||
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_ReleaseDeviceInt(IntPtr hDevice); // 释放中断资源
|
||
|
||
//################# 内存映射寄存器直接操作及读写函数 ########################
|
||
// 适用于用户对本设备更直接、更特殊、更低层、更复杂的控制。比如根据特殊的
|
||
// 控制对象需要特殊的控制流程和控制效率时,则用户可以使用这些接口予以实现。
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_GetDeviceBar( // 取得指定的指定设备寄存器组BAR地址
|
||
IntPtr hDevice, // 设备对象句柄
|
||
Int64[] pbPCIBar); // 返回PCI BAR所有地址,具体PCI BAR中有多少可用地址请看硬件说明书
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_WritePortByte(IntPtr hDevice, Int64 pPort, Byte Value);
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_WritePortWord(IntPtr hDevice, Int64 pPort, UInt16 Value);
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_WritePortULong(IntPtr hDevice, Int64 pPort, UInt32 Value);
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Byte PCI2312_ReadPortByte(IntPtr hDevice, Int64 pPort);
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern UInt16 PCI2312_ReadPortWord(IntPtr hDevice, Int64 pPort);
|
||
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern UInt32 PCI2312_ReadPortULong(IntPtr hDevice, Int64 pPort);
|
||
|
||
|
||
//############################ 线程操作函数 ################################
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern IntPtr PCI2312_CreateSystemEvent(); // 创建内核系统事件对象
|
||
[DllImport("PCI2312_64.DLL")]
|
||
public static extern Int32 PCI2312_ReleaseSystemEvent(IntPtr hEvent); // 释放内核事件对象
|
||
|
||
|
||
}
|
||
}
|