WINDOWS 参数
using System;
using System.Collections.Generic;
class Program
{
static void Main()
{
List<string> 设备列表 = new List<string>();
设备列表 = GClient.GetUsbHidList();
if (设备列表 != null && 设备列表.Count > 0)
{
foreach (var 设备 in 设备列表)
{
Console.WriteLine(设备);
}
GClient 客户端连接 = new GClient();
eConnectionAttemptEventStatusType 状态;
if (客户端连接.OpenUsbHid(设备列表[0], IntPtr.Zero, 3000, out 状态))
{
// 订阅事件
客户端连接.OnEncapedTagEpcLog += new delegateEncapedTagEpcLog(标签Epc日志回调);
客户端连接.OnEncapedTagEpcOver += new delegateEncapedTagEpcOver(标签Epc结束回调);
// 停止
停止消息基类 停止消息 = new 停止消息基类();
客户端连接.SendSynMsg(停止消息);
if (停止消息.RtCode == 0)
{
Console.WriteLine("停止成功。");
}
else
{
Console.WriteLine("停止失败。");
}
// 4 天线读取库存、EPC 和 TID
库存Epc消息基类 库存Epc消息 = new 库存Epc消息基类();
库存Epc消息.天线启用 = (uint)(eAntennaNo._1 | eAntennaNo._2 | eAntennaNo._3 | eAntennaNo._4);
库存Epc消息.库存模式 = (byte)eInventoryMode.Inventory;
库存Epc消息.读取Tid = new ParamEpcReadTid(); // tid 参数
库存Epc消息.读取Tid.模式 = (byte)eParamTidMode.Auto;
库存Epc消息.读取Tid.长度 = 6;
客户端连接.SendSynMsg(库存Epc消息);
if (库存Epc消息.RtCode == 0)
{
Console.WriteLine("库存 Epc 读取成功。");
}
else
{
Console.WriteLine("库存 Epc 读取失败。");
}
Console.WriteLine("正在读取....");
Console.WriteLine("按任意键停止循环读卡(按任意字符停止)。");
Console.ReadKey();
// 停止
客户端连接.SendSynMsg(停止消息);
if (停止消息.RtCode == 0)
{
Console.WriteLine("停止成功。");
}
else
{
Console.WriteLine("停止失败。");
}
}
}
Console.ReadKey();
}
#region API事件
public static void 标签Epc日志回调(EncapedLogBaseEpcInfo 消息)
{
// 回调里面的任何阻塞或者效率过低,都会影响API的正常使用 !
if (消息 != null && 消息.logBaseEpcInfo.Result == 0)
{
Console.WriteLine(":天线[" + 消息.logBaseEpcInfo.AntId + "]" + 消息.logBaseEpcInfo.Epc + "|" + 消息.logBaseEpcInfo.Tid);
}
}
public static void 标签Epc结束回调(EncapedLogBaseEpcOver 消息)
{
if (消息 != null)
{
Console.WriteLine("Epc 日志结束。");
}
}
#endregion
}
TcpServer sdk
namespace 东方仙盟
{
static class 示例Tcp服务器
{
private static GClient 客户端连接 = null;
private static object 等待客户端对象 = new object();
static void Main()
{
GServer 服务器 = new GServer();
服务器.OnGClientConnected += new delegateGClientConnected(客户端连接事件处理);
服务器.Open(8160);
Console.WriteLine("请将设备设置成客户端模式!(Please set the device to client mode!)");
Console.WriteLine("已监听8160端口,等待客户端连接...");
lock (等待客户端对象)
{
Monitor.Wait(等待客户端对象);
}
客户端连接.OnEncapedTagEpcLog += new delegateEncapedTagEpcLog(标签Epc日志回调);
客户端连接.OnEncapedTagEpcOver += new delegateEncapedTagEpcOver(标签Epc结束回调);
// 停止
停止消息基类 停止消息 = new 停止消息基类();
客户端连接.SendSynMsg(停止消息);
if (停止消息.RtCode == 0)
{
Console.WriteLine("停止成功。");
}
else
{
Console.WriteLine("停止失败。");
}
// 4 天线读取库存、EPC 和 TID
库存Epc消息基类 库存Epc消息 = new 库存Epc消息基类();
库存Epc消息.天线启用 = (uint)(eAntennaNo._1 | eAntennaNo._2 | eAntennaNo._3 | eAntennaNo._4);
库存Epc消息.库存模式 = (byte)eInventoryMode.Inventory;
库存Epc消息.读取Tid = new ParamEpcReadTid(); // tid 参数
库存Epc消息.读取Tid.模式 = (byte)eParamTidMode.Auto;
库存Epc消息.读取Tid.长度 = 6;
客户端连接.SendSynMsg(库存Epc消息);
if (库存Epc消息.RtCode == 0)
{
Console.WriteLine("库存 Epc 读取成功。");
}
else
{
Console.WriteLine("库存 Epc 读取失败。");
}
Console.WriteLine("正在读取....");
Console.WriteLine("按任意键停止循环读卡(按任意字符停止)。");
Console.ReadKey();
// 停止
客户端连接.SendSynMsg(停止消息);
if (停止消息.RtCode == 0)
{
Console.WriteLine("停止成功。");
}
else
{
Console.WriteLine("停止失败。");
}
Console.WriteLine("按任意键关闭(按任意字符关闭)。");
Console.ReadKey();
客户端连接.Close();
服务器.Close();
}
#region API事件
public static void 客户端连接事件处理(GClient 客户端)
{
if (客户端连接 != null)
{
客户端连接.Close();
}
客户端连接 = 客户端;
Console.WriteLine("发现新设备连接(find device).");
lock (等待客户端对象)
{
Monitor.Pulse(等待客户端对象);
}
}
public static void 标签Epc日志回调(EncapedLogBaseEpcInfo 消息)
{
// 回调里面的任何阻塞或者效率过低,都会影响API的正常使用 !
if (消息 != null && 消息.logBaseEpcInfo.Result == 0)
{
Console.WriteLine(消息.serialNo + ":天线[" + 消息.logBaseEpcInfo.AntId + "]" + 消息.logBaseEpcInfo.Epc + "|" + 消息.logBaseEpcInfo.Tid);
}
}
public static void 标签Epc结束回调(EncapedLogBaseEpcOver 消息)
{
if (消息 != null)
{
Console.WriteLine("Epc 日志结束。");
}
}
#endregion
}
}
阿雪技术观
在科技发展浪潮中,我们不妨积极投身技术共享。不满足于做受益者,更要主动担当贡献者。无论是分享代码、撰写技术博客,还是参与开源项目维护改进,每一个微小举动都可能蕴含推动技术进步的巨大能量。东方仙盟是汇聚力量的天地,我们携手在此探索硅基生命,为科技进步添砖加瓦。
Hey folks, in this wild tech - driven world, why not dive headfirst into the whole tech - sharing scene? Don't just be the one reaping all the benefits; step up and be a contributor too. Whether you're tossing out your code snippets, hammering out some tech blogs, or getting your hands dirty with maintaining and sprucing up open - source projects, every little thing you do might just end up being a massive force that pushes tech forward. And guess what? The Eastern FairyAlliance is this awesome place where we all come together. We're gonna team up and explore the whole silicon - based life thing, and in the process, we'll be fueling the growth of technology.