当前位置: 首页 > news >正文

C# .aspx网页获取RFID读卡器HTTP协议提交的访问文件Request获得卡号、机号,Response回应驱动读卡器显示响声

 

本示例使用的设备:RFID网络WIFI无线TCP/UDP/HTTP可编程二次开发读卡器POE供电语音-淘宝网 (taobao.com)

服务端代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Web.Services;
using Newtonsoft.Json;public partial class HttpReader : System.Web.UI.Page
{public string RepStr = "";protected void Page_Load(object sender, EventArgs e){//Request方式:直接以对象索引的方式获取参数值,不受POST或GET方式影响。//Request.QueryString方式:在客户端使用GET方式进行提交时可以使用此方式获取。高效//Request.Form方式:在客户端使用POST方式进行提交时可以使用此方式进行获取。高效//Request.Params方式:该方式属于多种获取数据的一个集合,包括Cookie,此方式同样不受POST和GET方式影string info = "";string jihao = "";string cardtype = "";string card = "";string Data = "";string dn = "";string Status = "";Int16 cardtype16 = 0;int cardtypecode = 0;int pushortake = 0;string dispstr = "";string ChineseVoice = "[v8]";    //[v8]表示本次播报语音音量,取值范围v1 到 v16try             {   //GET、POST提交方式下解析获取提交的各项参数if (Request.Params["info"] != null) { info = Request.Params["info"]; }             //信息序号if (Request.Params["jihao"] != null) { jihao = Request.Params["jihao"]; }          //设备机号(可自编)if (Request.Params["cardtype"] != null){cardtype = Request.Params["cardtype"];}    //卡类型,卡状态if (Request.Params["card"] != null) { card = Request.Params["card"]; }             //卡序列号if (Request.Params["data"] != null) { Data = Request.Params["data"]; }             //扇区内容if (Request.Params["dn"] != null) { dn = Request.Params["dn"]; }                   //设备硬件序列号,出厂时已固化,全球唯一if (Request.Params["status"] != null) { Status = Request.Params["status"]; }       //读卡状态,如密码认证失败为12if (info != "" && jihao != "" && cardtype != "" && card != ""){                cardtype16 = Convert.ToInt16(cardtype, 16);pushortake = cardtype16 / 128;       //pushortake=0 表示读卡,>0表示卡离开感应区cardtypecode = cardtype16 % 16;      // cardtypecode=1 ID卡,2 HID卡,3 T5557卡,4 EM4305卡,5 IC卡,6 二代身份证,7 是15693卡,IClass"                }else    //如未获取到有效参数,使用JSON方式解析获取提交的参数{StreamReader sr = new StreamReader(Request.GetBufferlessInputStream());string response = sr.ReadToEnd();RootObject rb = JsonConvert.DeserializeObject<RootObject>(response);info = rb.info;            //接收到的数据包号,需回应该包号jihao = rb.jihao;          //设备机号(可自编)cardtype = rb.cardtype;    //卡类型,卡状态card = rb.card;            //接收到的原始16进制卡号,可根据需要自行转换成其他卡号Data = rb.data;            //扇区内容dn = rb.dn;                //设备硬件序列号,出厂时已固化,全球唯一Status = rb.status;        //读卡状态,如密码认证失败为12if (info != "" && jihao != "" && cardtype != "" && card != ""){cardtype16 = Convert.ToInt16(cardtype, 16);pushortake = cardtype16 / 128;       //pushortake=0 表示读卡,>0表示卡离开感应区cardtypecode = cardtype16 % 16;      // cardtypecode=1 ID卡,2 HID卡,3 T5557卡,4 EM4305卡,5 IC卡,6 二代身份证,7 是15693卡,IClass"         }}if (info != ""  && card != "")    //通过解析获取到了有效的参数,回应驱动读卡器显示文字、蜂鸣响声或播报语音{dispstr = "{" + getChinesecode("卡号") + ":}" + (card + "      ").Substring(0, 12) + DateTime.Now.ToString("yy-MM-dd HH:mm:ss"); //显示信息,注意中文汉字一定要转换为设备能显示的编码,其它字母数字符号不需要转换,{}内的信息反白显示if (pushortake > 0){ChineseVoice = ChineseVoice + getChinesecode("卡号") + "[n1]" + card + getChinesecode("离开感应区!");     //TTS语音,注意中文汉字一定要转换为设备能识别的编码,[n1]表示数字播报方式,其它字母数字符号不需要转换              }else{ChineseVoice = ChineseVoice + getChinesecode("读取卡号") + "[n1]" + card;}RepStr = "Response=1";                    //Response=1 固定前缀,我们的设备以此来检索返回信息,表示 驱动设备显示和响声RepStr = RepStr + "," + info;             //提交的信息序号,一定要对应RepStr = RepStr + "," + dispstr;          //读卡器上显示文字RepStr = RepStr + ",20";                  //显示时长20秒RepStr = RepStr + ",2";                   //蜂鸣器发声种类,取值范围0-12RepStr = RepStr + "," + ChineseVoice;     //播报的TTS语音Response.Write(RepStr);    //将回应信息传送到读卡器Response.End();}}catch { }}public static string getChinesecode(string inputip)   //获取中文编码,显示汉字、TTS中文语音都要转换编码{byte[] Chinesecodearry = System.Text.Encoding.GetEncoding(936).GetBytes(inputip);int codelen = (byte)Chinesecodearry.Length;string hexcode = "";for (int i = 0; i < codelen; i++){if (i % 2 == 0) { hexcode = hexcode + "\\x"; }hexcode = hexcode + Chinesecodearry[i].ToString("X2");}return hexcode;}public class RootObject  //json类{public string info { get; set; }public string jihao { get; set; }public string cardtype { get; set; }public string card { get; set; }public string data { get; set; }public string dn { get; set; }public string status { get; set; }}}
前端脚本 :
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HttpReader.aspx.cs" Inherits="HttpReader" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Http读卡器Demo</title>
</head><body><form id="form1" runat="server"><div style="height: 96px"></div></form>
</body>
</html>

http://www.lryc.cn/news/138902.html

相关文章:

  • Kali Linux 2023.3 发布
  • 如何用Python实现从pdf文件精准抓取数据生成数据库!
  • 科技资讯|苹果Apple Watch新专利,可根据服装、表带更换表盘颜色
  • 猜数游戏-Rust版
  • 从零起步:学习数据结构的完整路径
  • 如何在浏览器中启用 WebGL 以使用 HTML5 3D 查看器
  • 【计算机协议】第一章——HTTP协议详解
  • 【FAQ】安防监控视频汇聚平台EasyCVR接入GB国标设备,无法显示通道信息的排查方法
  • Matlab 生成一定信噪比的信号
  • [国产MCU]-W801开发实例-定时器
  • 基于 CentOS 7 构建 LVS-DR 群集,配置nginx负载均衡。
  • 大数据——spark一文全知道
  • Linux命令200例:telnet用于远程登录的网络协议(常用)
  • 使用 eBPF 在云中实现网络可观测性
  • linux安装部署gitlab全教程,包含配置中文
  • 软考高级系统架构设计师系列论文八十:论企业信息化战略规划技术
  • 使用ChatGPT构建一个AIML聊天机器人是什么体验
  • [JavaWeb]【九】web后端开发-SpringBootWeb案例(菜单)
  • vue 主组件把日期选择器给子组件props传obj值, 与子组件监听 watch对象或对象属性
  • WebDAV之π-Disk派盘 + 一刻日记
  • springboot aop实现接口防重复操作
  • ubuntu18.04复现yolo v8环境配置之CUDA与pytorch版本问题以及多CUDA版本安装及切换
  • Yaml配置文件读取方法
  • Python3 lambda 函数入门示例 Python lambda 函数
  • 【计算机网络】HTTPs 传输流程
  • 【Linux】国产深度系统装机必备(开发、日常使用)
  • 动态规划入门:斐波那契数列模型以及多状态(C++)
  • LeetCode438.找到字符串中所有字母异位词
  • 【微服务】03-HttpClientFactory与gRpc
  • iOS开发之查看静态库(.a/.framework)中包含的.o文件和函数符号(ar,nm命令)