【问题标题】:Dll device connected for first time but it won't connect againdll设备第一次连接但它不会再次连接
【发布时间】:2019-05-08 01:07:33
【问题描述】:

DLL 方法:

[DllImport("SBXPCDLL.dll", CallingConvention = CallingConvention.Winapi)]
static extern byte _ConnectTcpip(Int32 dwMachineNumber, ref IntPtr lpszIPAddress, Int32 dwPortNumber, Int32 dwPassWord);
public static bool ConnectTcpip(Int32 dwMachineNumber, string lpszIPAddress, Int32 dwPortNumber, Int32 dwPassWord)
{
    if (lpszIPAddress == null)
        return false;
    IntPtr string_in = Marshal.StringToBSTR(lpszIPAddress);
    try
    {
        byte ret = _ConnectTcpip(dwMachineNumber, ref string_in, dwPortNumber, dwPassWord);
        return ret > 0;
    }
    catch (Exception)
    {
        return false;
    }
    finally
    {
        Marshal.FreeBSTR(string_in);
    }
}

按钮点击事件:

protected void Button_click(object sender, EventArgs e)
{
    try
    {
        bool status = sbxpc.SBXPCDLL.ConnectTcpip(1, ip, 5005, 0);
        if (status)
        {
            bool ss = sbxpc.SBXPCDLL.GetSerialNumber(1, out ip);
            Button1.Text = "connected";
            Response.Write("success" + ip);
        }
    }
    catch (Exception ee)
    {
        Response.Write(ee);
    }
}

我使用 SBXPCDLL.dll 连接生物识别设备。代码仅适用于第一次,设备已连接,但再次运行时将无法再次连接。我不知道为什么?谁能帮帮我?

【问题讨论】:

  • _ConnectTcpip 的返回值是什么?
  • @Belurd 刚刚我发现当我停止服务器并再次运行时它会连接。上面的代码第一次工作正常我现在该怎么办?

标签: c# asp.net dll biometrics


【解决方案1】:

我想,您在第一次运行后已连接到设备。为了能够再次连接,您必须先断开连接(正如我从“SBXPC 参考手册”中了解到的那样,有Disconnect() 功能)。

否则,您可以在应用程序中控制您的状态,即您是否已连接/断开连接并根据它运行GetSerialNumber()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-26
    • 2020-07-06
    • 1970-01-01
    • 2016-12-19
    • 1970-01-01
    • 2016-05-25
    • 2016-06-26
    • 1970-01-01
    相关资源
    最近更新 更多