Fanuc 协议驱动
包: Snet.Fanuc | 类: FanucOperate | 类型: 1
提供通过以太网上的 FOCAS(Fanuc 开放式 CNC API 规范)协议连接发那科 CNC 控制器和机器人的能力。
安装
dotnet add package Snet.Fanuc
快速开始
using Snet.Fanuc;
var op = new FanucOperate(new FanucData.Basics
{
IpAddress = "192.168.1.100",
Port = 8193
});
var address = new Address(new List<AddressDetails>
{
new("读数", "macro.100", DataType.Float),
new("读数2", "macro.102", DataType.Float)
});
var result = await op.ReadAsync(address);
if (result.Status)
{
var data = result.GetSource<ConcurrentDictionary<string, AddressValue>>();
foreach (var kv in data)
Console.WriteLine($"{kv.Key} = {kv.Value.ResultValue}");
}
else
{
Console.WriteLine($"读取失败: {result.Message}");
}
// 订阅之前 绑定数据事件
op.OnDataEventAsync += async (sender, e) =>
{
if (e.Status)
{
var data = e.GetSource<ConcurrentDictionary<string, AddressValue>>();
foreach (var kv in data)
Console.WriteLine($"{kv.Key} = {kv.Value.ResultValue}");
}
else
{
Console.WriteLine($"{e.Message}");
}
};
var subAddr = new Address(new List<AddressDetails>
{
new("读数", "macro.100", DataType.Float)
});
await op.SubscribeAsync(subAddr);
// 后续:取消订阅
// await op.UnSubscribeAsync(subAddr);
await op.DisposeAsync();
配置
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
IpAddress |
string | — | CNC 控制器 IP 地址 |
Port |
int | 8193 | FOCAS 端口 |
ConnectTimeOut |
int | 1000 | 连接超时(毫秒) |
ReceiveTimeOut |
int | 1000 | 接收超时(毫秒) |
支持的类型
FOCAS2/以太网协议,适用于 Fanuc Series 0i/30i/31i/32i、PMC 数据、宏变量、刀具偏置和报警/诊断数据。
FanucInterfaceNet— Fanuc Interface Net 通信
支持的操作
| 操作 | 方法 |
|---|---|
| 连接 | OnAsync() |
| 断开 | OffAsync() |
| 读取 | ReadAsync(address) |
| 写入 | WriteAsync(values) |
| 订阅 | SubscribeAsync(address) |
