C# 通过tcp读取基恩士扫码枪条码_基恩士750扫码枪以太网设置

C# 通过tcp读取基恩士扫码枪条码_基恩士750扫码枪以太网设置

编码文章call10242025-09-03 22:13:238A+A-
  1. 首先安装:SampleTcp 库; Install-Package SampleTcp
  2. 废话不多说,直接上代码:

连接扫码枪

try
{
    string ip = "192.168.1.100";
    int port = 9004; //默认端口
    tcpClient = new SimpleTcpClient();
    tcpClient.Delimiter = 0x0D; //终端代码
    tcpClient.StringEncoder = Encoding.UTF8;
    tcpClient.Connect(ip, port);
    setLog(#34;连接:{ip}:{port}成功");
} catch (Exception ex) {
	setLog(#34;连接失败:{ex.Message}");
}

读取条码:

if (tcpClient != null)
{
    SimpleTCP.Message msg = tcpClient.WriteLineAndGetReply("LON", TimeSpan.FromMilliseconds(200));
    setLog(#34;读码信息:{msg?.MessageString}");
    tcpClient.Write("LOFF");
}

Game Over!

其他的就自己去丰富了。如果扫码枪没有开keep alive功能,可以每次读到条码销毁掉Tcp连接:

if(tcpClient!=null)
{
	tcpClient.Disconnect();
	tcpClient= null;
}
点击这里复制本文地址 以上内容由文彬编程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

文彬编程网 © All Rights Reserved.  蜀ICP备2024111239号-4