C#LPT input 32.dll

C#LPT input 32.dll,c#,.net,parallel-port,lpt,C#,.net,Parallel Port,Lpt,我没有收到任何错误或异常 一个窗口中的按钮: private void button1_Click(object sender, EventArgs e) { ControlPort.Output(0x378, 0xff); } 和input.dll接口: class ControlPort { [DllImport("inpout32.dll", EntryPoint = "Out32")] public static extern void Output(int a

我没有收到任何错误或异常

一个窗口中的按钮:

private void button1_Click(object sender, EventArgs e)
{
    ControlPort.Output(0x378, 0xff);
}
和input.dll接口:

class ControlPort
{
    [DllImport("inpout32.dll", EntryPoint = "Out32")]
    public static extern void Output(int adress, int value);
}
怎么了? D2上的LED一直亮着

我有Windows7x64Ultimate。

对于x64,您应该使用“inputx64.dll”

访问:
在那里,您可以阅读更多内容并找到样本。

当您出错时,不会出现异常,最多只会出现一个蓝屏。选择以下选项之一:

  • 您使用了错误的地址(0x3bc、0x2f8)
  • 你把指示灯接错了
  • 你闯入了错误的博物馆去拿硬件

这个问题的文档太少,无法帮助您解决这个问题。

如果有人需要,可以使用代码

 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);
            }
        }
    }
}

我解决了旧笔记本电脑Windows 2000上的LPT端口问题,无法设置数据端口(pin2-pin9)

使用此导入函数:

[DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Out32(int address, int value);
每次重新启动或重新启动Windows后,我必须拨打以下电话:

Out32(0x378 + 2, 0x00);

以便端口正常工作。我认为问题在于双向设置(0x37A上第6位的控制端口)。

这些都没有。第一个答案是正确的。我使用了错误的dll版本。嗯,在64位进程中使用32位dll总是会产生异常。我得到
System.EntryPointNotFoundException:在dll“InputX64.dll”中找不到名为“IsInputDriveRopen”的入口点。
当试图调用
IsInputDriveRopen\u x64()
时。现在他们有了这个
BOOL\u stdcall IsXP64Bit();//如果操作系统是64位(x64)Windows,则返回TRUE。
这是两个dll文件的一部分。