C#LPT inpout32.dll [英] C# LPT inpout32.dll
本文介绍了C#LPT inpout32.dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我没有得到任何错误或异常。
按钮在一个窗口:
私人无效的button1_Click(对象发件人,EventArgs的)
{
ControlPort.Output(的0x378,为0xFF);
}
和inpout.dll接口:
类ControlPort
{
[的DllImport(inpout32.dll,入口点=Out32)]
公共静态外部无效输出(INT联系地址,int值);
}
什么是错的? D2上的LED是在所有的时间。
我的Windows 7 64位旗舰版。
修改
如果有人需要它工作code。
使用系统;
使用了System.Runtime.InteropServices;
命名空间ParallelPort
{
公共类PortAccess
{
//inpout.dll
[的DllImport(inpout32.dll)]
私人静态外部UInt32的IsInpOutDriverOpen();
[的DllImport(inpout32.dll)]
私人静态外部无效Out32(短PortAddress,短数据);
[的DllImport(inpout32.dll)]
私人静态外部焦炭Inp32(短PortAddress);
[的DllImport(inpout32.dll)]
私人静态外部无效DlPortWritePortUshort(短PortAddress,USHORT数据);
[的DllImport(inpout32.dll)]
私人静态外部USHORT DlPortReadPortUshort(短PortAddress);
[的DllImport(inpout32.dll)]
私人静态外部无效DlPortWritePortUlong(INT PortAddress,uint数据);
[的DllImport(inpout32.dll)]
私人静态外部UINT DlPortReadPortUlong(INT PortAddress);
[的DllImport(inpoutx64.dll)]
私人静态外部布尔GetPhysLong(REF INT PortAddress,裁判uint数据);
[的DllImport(inpoutx64.dll)]
私人静态外部布尔SetPhysLong(REF INT PortAddress,裁判uint数据);
//inpoutx64.dll
[的DllImport(inpoutx64.dll,入口点=IsInpOutDriverOpen)]
私人静态外部UInt32的IsInpOutDriverOpen_x64();
[的DllImport(inpoutx64.dll,入口点=Out32)]
私人静态外部无效Out32_x64(短PortAddress,短数据);
[的DllImport(inpoutx64.dll,入口点=Inp32)]
私人静态外部焦炭Inp32_x64(短PortAddress);
[的DllImport(inpoutx64.dll,入口点=DlPortWritePortUshort)]
私人静态外部无效DlPortWritePortUshort_x64(短PortAddress,USHORT数据);
[的DllImport(inpoutx64.dll,入口点=DlPortReadPortUshort)]
私人静态外部USHORT DlPortReadPortUshort_x64(短PortAddress);
[的DllImport(inpoutx64.dll,入口点=DlPortWritePortUlong)]
私人静态外部无效DlPortWritePortUlong_x64(INT PortAddress,uint数据);
[的DllImport(inpoutx64.dll,入口点=DlPortReadPortUlong)]
私人静态外部UINT DlPortReadPortUlong_x64(INT PortAddress);
[的DllImport(inpoutx64.dll,入口点=GetPhysLong)]
私人静态外部布尔GetPhysLong_x64(REF INT PortAddress,裁判uint数据);
[的DllImport(inpoutx64.dll,入口点=SetPhysLong)]
私人静态外部布尔SetPhysLong_x64(REF INT PortAddress,裁判uint数据);
私人布尔_X64;
私人短_PortAddress;
公共PortAccess(短PortAddress)
{
_X64 = FALSE;
_PortAddress = PortAddress;
尝试
{
UINT nResult = 0;
尝试
{
nResult = IsInpOutDriverOpen();
}
赶上(BadImageFormatException)
{
nResult = IsInpOutDriverOpen_x64();
如果(nResult!= 0)
_X64 =真;
}
如果(nResult == 0)
{
抛出新的ArgumentException(无法打开InpOut32驱动程序);
}
}
赶上(DllNotFoundException)
{
抛出新的ArgumentException(无法找到InpOut32.dll);
}
}
//公共方法
公共无效写入(短数据)
{
如果(_X64)
{
Out32_x64(_PortAddress,数据);
}
其他
{
Out32(_PortAddress,数据);
}
}
公共字节读取()
{
如果(_X64)
{
返回(字节)Inp32_x64(_PortAddress);
}
其他
{
返回(字节)Inp32(_PortAddress);
}
}
}
}
解决方案
对于x64你应该使用InpOutx64.dll。
请访问:<一href="http://www.highrez.co.uk/Downloads/InpOut32/default.htm">http://www.highrez.co.uk/Downloads/InpOut32/default.htm 在那里,你可以阅读更多,找到样本。
I don't get any error or exception.
Button in one Window:
private void button1_Click(object sender, EventArgs e)
{
ControlPort.Output(0x378, 0xff);
}
and inpout.dll interface:
class ControlPort
{
[DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int adress, int value);
}
What is wrong? LED on D2 is on all the time.
I have Windows 7 x64 Ultimate.
Edit
Working code if somebody needs it.
using System;
using System.Runtime.InteropServices;
namespace ParallelPort
{
public class PortAccess
{
//inpout.dll
[DllImport("inpout32.dll")]
private static extern UInt32 IsInpOutDriverOpen();
[DllImport("inpout32.dll")]
private static extern void Out32(short PortAddress, short Data);
[DllImport("inpout32.dll")]
private static extern char Inp32(short PortAddress);
[DllImport("inpout32.dll")]
private static extern void DlPortWritePortUshort(short PortAddress, ushort Data);
[DllImport("inpout32.dll")]
private static extern ushort DlPortReadPortUshort(short PortAddress);
[DllImport("inpout32.dll")]
private static extern void DlPortWritePortUlong(int PortAddress, uint Data);
[DllImport("inpout32.dll")]
private static extern uint DlPortReadPortUlong(int PortAddress);
[DllImport("inpoutx64.dll")]
private static extern bool GetPhysLong(ref int PortAddress, ref uint Data);
[DllImport("inpoutx64.dll")]
private static extern bool SetPhysLong(ref int PortAddress, ref uint Data);
//inpoutx64.dll
[DllImport("inpoutx64.dll", EntryPoint = "IsInpOutDriverOpen")]
private static extern UInt32 IsInpOutDriverOpen_x64();
[DllImport("inpoutx64.dll", EntryPoint = "Out32")]
private static extern void Out32_x64(short PortAddress, short Data);
[DllImport("inpoutx64.dll", EntryPoint = "Inp32")]
private static extern char Inp32_x64(short PortAddress);
[DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUshort")]
private static extern void DlPortWritePortUshort_x64(short PortAddress, ushort Data);
[DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUshort")]
private static extern ushort DlPortReadPortUshort_x64(short PortAddress);
[DllImport("inpoutx64.dll", EntryPoint = "DlPortWritePortUlong")]
private static extern void DlPortWritePortUlong_x64(int PortAddress, uint Data);
[DllImport("inpoutx64.dll", EntryPoint = "DlPortReadPortUlong")]
private static extern uint DlPortReadPortUlong_x64(int PortAddress);
[DllImport("inpoutx64.dll", EntryPoint = "GetPhysLong")]
private static extern bool GetPhysLong_x64(ref int PortAddress, ref uint Data);
[DllImport("inpoutx64.dll", EntryPoint = "SetPhysLong")]
private static extern bool SetPhysLong_x64(ref int PortAddress, ref uint Data);
private bool _X64;
private short _PortAddress;
public PortAccess(short PortAddress)
{
_X64 = false;
_PortAddress = PortAddress;
try
{
uint nResult = 0;
try
{
nResult = IsInpOutDriverOpen();
}
catch (BadImageFormatException)
{
nResult = IsInpOutDriverOpen_x64();
if (nResult != 0)
_X64 = true;
}
if (nResult == 0)
{
throw new ArgumentException("Unable to open InpOut32 driver");
}
}
catch (DllNotFoundException)
{
throw new ArgumentException("Unable to find InpOut32.dll");
}
}
//Public Methods
public void Write(short Data)
{
if (_X64)
{
Out32_x64(_PortAddress, Data);
}
else
{
Out32(_PortAddress, Data);
}
}
public byte Read()
{
if (_X64)
{
return (byte)Inp32_x64(_PortAddress);
}
else
{
return (byte)Inp32(_PortAddress);
}
}
}
}
解决方案
For x64 you should use "InpOutx64.dll".
Visit: http://www.highrez.co.uk/Downloads/InpOut32/default.htm There you can read more and find samples.
这篇关于C#LPT inpout32.dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文