Skip to content

C# ​

命名空间 W6E.Sdk,目标框架 net8.0。示例在 sdk/csharp/examples/:EncoderStatus、SetOpenPct、OpenClose、GestureOk、HomeAndWatchFaults。

WPF 控制面板是 net8.0-windows,只在 Windows 10/11 上打开。Ubuntu 可以编译库和命令行,窗口打不开。

Windows 面板 ​

安装 .NET 8 SDK 后:

powershell
cd sdk/csharp
powershell -File scripts/run_ui.ps1

也可以打开 sdk/csharp/W6E.sln 编译运行。

命令行 ​

bash
export PATH="$HOME/.dotnet:$PATH"
cd sdk/csharp
dotnet build W6E.Sdk/W6E.Sdk.csproj -c Release
dotnet run --project examples/EncoderStatus -c Release -- --port /dev/ttyACM0
dotnet run --project examples/SetOpenPct -c Release -- --port /dev/ttyACM0 --pct 0,0,0,0,0,0

--pct 用逗号分隔。张开写成 100,100,100,100,100,100。can0 已挂好时把端口换成 can0,并加上 --transport socketcan。

只编译类库不会让手指动。OpenClose 里的全合走协议 0x13,不含虎口。要虎口一起动,用 SetOpenPct 发六个 0。

最短示例 ​

csharp
using W6E.Sdk;

using var hand = new HandClient { AckTimeoutSeconds = 1.0 };
hand.Connect("/dev/ttyACM0", "can_slcan");
try
{
    Console.WriteLine(hand.GetVersionString());
    hand.SetOpenPct(new[] { 100, 100, 100, 100, 100, 100 });
    Thread.Sleep(1500);
    hand.SetOpenPct(new[] { 0, 0, 0, 0, 0, 0 });
    hand.PlayGesture("ok");
    hand.StopAll();
}
catch (HandError ex)
{
    Console.WriteLine(ex.Message);
}
finally
{
    hand.Disconnect();
}

失败时抛出 HandError。SetOpenPct 有手指被跳过时返回 false,原因在 LastError。HandClient 实现 IDisposable。

常用接口 ​

接口作用
ListPorts()串口名
Connect(port, transport, verify)传输可用枚举,或字符串 can_slcan / socketcan
Disconnect() / Connected关闭连接
SetOpenPct / GetOpenPct / GetPositions六个开合度。未归零的那一路 GetPositions 为 null
OpenAll / CloseAll / StopAll前两个不含虎口
SetFinger / StopFinger / SetFingerActions极限动作,或六路 0 / 1 / 2
PlayGesture / PlayFixed / ListGestures预设手势
GetVersionString / GetSerialNumber点分版本和序列号
Home / WaitHome / GetEncoderStatus归零期间手指会动

峦启机器人(天津)有限公司