java tcp门禁_立方门禁TCP二次开发

private static voidReceiveMessage()

{while (!cancelTokenSource.IsCancellationRequested)

{try{byte[] buffer = new byte[1024];int length =client.Receive(buffer);if (length > 0)

{

StringBuilder sOutput= newStringBuilder(buffer.Length);for (int i = 0; i< buffer.Length; i++)

{

sOutput.Append(buffer[i].ToString("X2"));

}var result =ByteArrayToHexString(buffer);if (result.Contains("00 00 00 13 01 00 12"))

{

Console.WriteLine("登录成功");

}else if (result.Contains("00 00 00 13 01 00 03"))

{

Console.WriteLine("接收心跳");

}else if (result.Contains("00 00 00 18 00 02 00"))

{

Console.WriteLine("门状态变化");

}else if (result.Contains("00 00 00 18 00 02 01"))

{

Console.WriteLine("控制器状态");

}else if (result.Contains("00 00 00 18 00 02 02"))

{

Console.WriteLine("刷卡记录");

}else if (result.Contains("00 00 00 18 00 03 00"))

{

Console.WriteLine("访客刷卡");

}else{string datapacket = "00000013010200000000000000000101C46AF0";byte[] array =HexStringToByteArray(datapacket);

client.Send(array);byte[] newByte =LongToShort(buffer);string res =Encoding.UTF8.GetString(newByte);

LiFangMsg lf= JsonConvert.DeserializeObject(res);

Console.WriteLine(res);

}

}

}catch(Exception e)

{

Console.WriteLine("发生错误:" +e.Message);

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值