gpt4 book ai didi

c# - Synaptics SDK 找不到设备

转载 作者:可可西里 更新时间:2023-11-01 08:48:42 39 4
gpt4 key购买 nike

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

同步.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);
}
}
}

程序.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 文件:

For certain purposes it may be necessary to register the dlls that are provided with the SDK. This can be done with the windows regsvr32 utility.

关于c# - Synaptics SDK 找不到设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32767527/

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com