C# 通过tcp读取基恩士扫码枪条码_基恩士750扫码枪以太网设置
- 首先安装:SampleTcp 库; Install-Package SampleTcp
- 废话不多说,直接上代码:
连接扫码枪
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;
} 相关文章
- Spring Boot中对接Twilio以实现发送验证码和验证短信码
- Spring Boot 3.5:这次更新让你连配置都不用写了,惊不惊喜?
- Spring Boot+Pinot实战:毫秒级实时竞价系统构建
- SpringBoot敏感配置项加密与解密实战
- SpringBoot 注解最全详解,建议收藏!
- Spring Boot 常用注解大全:从入门到进阶
- SpringBoot启动之谜:@SpringBootApplication如何让配置化繁为简
- Springboot集成Kafka原理_spring集成kafka的原理
- Spring Boot中@Data注解的深度解析与实战应用
- 大佬用1000字就把SpringBoot的配置文件讲的明明白白!
