0

我正在用 C# 更新一些最初用 VC++ V1.0 for DOS6 编写的软件。

该软件的一个方面是检查并行端口,其中连接了一个简单的按钮开关。我目前不知道开关连接到哪两个引脚,但我有旧程序的源代码,其相关部分如下...

#define switch_mask        0x10

void main(int argc, char *argv[])
{
    int NewState = 0, OldState = 0;

    /* Check switch */
    NewState = _bios_printer (_PRINTER_STATUS, 0, 0);

    if (NewState != OldState)
    {
    checkParallelPort (NewState);
    OldState = NewState;
    }    
}

void checkParallelPort (int portState)
{
    int SwitchState;
    /* Switch bit is Active LOW */
    SwitchState = (portState & switch_mask) ? 1 : 0;
}

现在 _bios_printer(在 bios.h 中)显然在 C# 中对我不可用,但我正在努力寻找可以完成这项简单任务的替代方案。

_bios_printer 的信息在这里。我已经在 .Net 中对并行端口的读/写进行了大量搜索,但似乎没有任何东西可以为我提供端口状态。

此外,您能否从这段代码(以及它如何检查“状态”)中得出结论,两条开关线连接在 DB25 插头上的位置?

如果有人对此有帮助/建议,我将不胜感激。非常感谢

4

2 回答 2

1

它似乎在检查“错误”,针脚 15。IIRC,这是在内部上拉的,所以你的开关应该下拉针脚 15。将它连接在针脚 15 和 18 之间。

有一些可用的驱动程序允许读取 I/O 映射端口。您将必须导入并进行 DLL 调用,然后几乎可以肯定会轮询 pin :((

我真希望这个界面已经死了,被埋没了!

于 2011-12-14T09:26:25.910 回答
0

谢谢回复。这就是我最终得到的......

我在 CodeProject 上使用了本教程... http://www.codeproject.com/KB/vb/Inpout32_read.aspx 当转换为 C# 时,我使用了类似于下面的内容。(如果有错误,我深表歉意——我从我最终得到的代码中“解释”了下面的代码——它对我有用!)

private void button1_Click(object sender, EventArgs e)
{

        short InReg = 0x379;    // Location of Port Status register
        int NewState;           // int named NewState

        NewState = InpOut32_Declarations.Inp(InReg);   //Now NewState has the values in 'Status port'

        MessageBox.Show(NewState);   //A popup will indicate the current value of NewState 

}

static class InpOut32_Declarations
{
    [DllImport("inpout32.dll", EntryPoint = "Inp32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]

    //Inp and Out declarations for port I/O using inpout32.dll.

    public static extern int Inp(ushort PortAddress);
    [DllImport("inpout32.dll", EntryPoint = "Out32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]

    public static extern void Out(ushort PortAddress, short Value);

}

有趣的是,由于我的并行端口从 0xE800 而不是 0x378 开始,所以我不得不修改 inpout32.dll 的源代码,因为 out32 方法只接受一个短路,而 0xE800 对一个短路来说太大了!将其更改为无符号短。

谢谢你的帮助

于 2011-12-20T09:32:48.700 回答