我正在尝试使用Synaptics SDK(特别是使用SYNCTRLLib中的方法)在Synaptics触摸板上抓取设备句柄。
但是,SYNCTRL方法找不到它,返回-1

Syn.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SYNCOMLib;
using SYNCTRLLib;

namespace TP_Test1
{
    class Syn
    {
        SynAPICtrl SynTP_API = new SynAPICtrl();
        SynDeviceCtrl SynTP_Dev = new SynDeviceCtrl();
        SynPacketCtrl SynTP_Pack = new SynPacketCtrl();
        int DeviceHandle;

        //Constructor
        public Syn ()
        {
            SynTP_API.Initialize();
            SynTP_API.Activate();

            //DeviceHandle == -1 ? Can't find device?
            DeviceHandle = SynTP_API.FindDevice(new SynConnectionType(), new SynDeviceType(), 0);
            //Below line causing Unhandled Exception
            SynTP_Dev.Select(DeviceHandle);
            SynTP_Dev.Activate();
            SynTP_Dev.OnPacket += SynTP_Dev_OnPacket;
        }

        public void SynTP_Dev_OnPacket()
        {
                Console.WriteLine(SynTP_Pack.FingerState);
                Console.WriteLine(SynTP_Pack.X);
                Console.WriteLine(SynTP_Pack.Y);
        }
    }
}

Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SYNCOMLib;
using SYNCTRLLib;

namespace TP_Test1
{
    class Program
    {
        static void Main(string[] args)
        {
            Syn mySyn = new Syn();
            mySyn.SynTP_Dev_OnPacket();
        }
    }
}

最佳答案

我看到您正在使用Synaptics SDK的C#包装器。即使CPP代码对您来说可能并不简单,您也可能要看一下Samples/ComTest.cpp文件。它包含一些示例逻辑,以便查找设备,更具体地说,在第66-76行:

  // Find a device, preferentially a TouchPad or Styk.
  ISynDevice *pDevice = 0;
  long lHandle = -1;
  if ((pAPI->FindDevice(SE_ConnectionAny, SE_DeviceTouchPad, &lHandle) &&
       pAPI->FindDevice(SE_ConnectionAny, SE_DeviceStyk, &lHandle) &&
       pAPI->FindDevice(SE_ConnectionAny, SE_DeviceAny, &lHandle)) ||
      pAPI->CreateDevice(lHandle, &pDevice))
  {
    printf("Unable to find a Synaptics Device.\n");
    exit(-1);
  }

另外,请确保您已经注册了dll。根据ReadSynSDK.txt文件:

10-08 03:00