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

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

时间:2023-10-31 10:32:04浏览次数:36  
标签:机号 string C# Request System Params using 读卡器 card


 

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

本示例使用的设备:

服务端代码:
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 到 v16

        try             
        {   //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"]; }       //读卡状态,如密码认证失败为12

            if (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;        //读卡状态,如密码认证失败为12

                if (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-12
                RepStr = 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>

标签:机号,string,C#,Request,System,Params,using,读卡器,card
From: https://blog.51cto.com/RongShi/8102218

相关文章

  • VbScript脚本Request获取RFID读卡器以HTTP提交的访问文件中的参数Response回应驱动读
    本示例使用的设备:<%@LANGUAGE="VBSCRIPT"CODEPAGE="65001"%><%Functionbin2str(bindata)DimrsStream,strlsSetrsStream=Server.CreateObject("ADODB.Stream")rsStream.Type=2rsStream.OpenrsStream.Wri......
  • access 进度条
    请在[布局视图]下设置,效果如下 OptionCompareDatabaseDimsAsIntegerPrivateSubForm_Load()'初始化变量Me.TimerInterval=10Command4.Width=0EndSubPrivateSubForm_Timer()Ifs<100Thens=s+1'自增量,可以设置自己的自......
  • sql server Compute、Compute by
    1、原始表 2、Compute和ComputeByselect*fromAwhere数量>8computemax(数量),min(数量),avg(数量)执行结果如下: select*fromAwhere数量>8orderby类别computemax(数量),min(数量),avg(数量)by类别 ......
  • AT_abc326_d ABC Puzzle 题解
    AT_abc326_dABCPuzzle题解看题事实上,即使在\(N=5\)的情况下,也只有\(66240\)个网格满足「每行/每列恰好包含一个A、B和C」。——官方题解其实看到这道题,就感觉是搜索,这很显然。但是我们会发现,最最最native的搜索,是\(4^{5\times5}=2^{50}\)的。感觉不大可过,但是......
  • AT_abc326_e Revenge of "The Salary of AtCoder Inc." 题解
    AT_abc326_eRevengeof"TheSalaryofAtCoderInc."题解一道简单的概率论+动态规划题目(然而我赛时没看这道题题意有一个长度为\(n\)的序列\(A\)、一个\(n\)面骰子,掷若干次骰子,如果这一次掷骰子的点数小于等于上一次的点数,则结束。定义这若干次掷骰子的总的结果为,每次......
  • AT_abc326_f Robot Rotation 题解
    AT_abc326_fRobotRotation题解经典问题,以前遇到过一个类似的问题:[ABC082D]FTRobot。建议对比着看一看这两道题,是两种不同的思路。(那一道题不用输出方案,因此可以用bitset优化;而此题需要输出方案,因此需要双向搜索。思路注意到每次只能「左转」和「左转」。所以,偶数次走......
  • AT_abc325_f Sensor Optimization Dilemma 题解
    AT_abc325_fSensorOptimizationDilemma题解Date20231025:修复手滑公式\(\min\)、\(\max\)写反了。动态规划。类似背包问题。朴素算法记\((x,y)\)表示使用\(x\)个(1)传感器、\(y\)个(2)号传感器。设\(f(t,i,j)\)表示覆盖前\(t\)个区间,使用\((i,j)\)传感......
  • AT_abc325_g offence 题解
    AT_abc325_goffence题解一道不难但是需要想一想的区间DP。有一个比较复杂的例子:ooofofxxx,简单的分析可知,一个of后面删除多少,与其前、后都有关,于是考虑区间DP。想到这里,其实问题已经解决一半了。状态设计设\(f(l,r)\)为闭区间\([l,r]\)经过操作之后的最小长度。注......
  • VSCode如何把代码转换成一行
    或者mac直接ctrl+j,可以把选中的代码转成一行。https://www.fengnayun.com/news/content/314947.html......
  • TypeScript入门到精通——泛型
    泛型 泛型程序设计是一种编程风格或编程范式,它允许在程序中定义形式类型参数,然后在泛型实例化时使用实际类型参数来替换形式类型参数。通过泛型,我们能够定义通用的数据结构或类型,这些数据结构或类型仅在它们操作的实际类型上有差别。泛型程序设计是实现可重用组件的一种手段。......