Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从usb rfid读取器读取数据?

如何从usb rfid读取器读取数据?
EN

Stack Overflow用户
提问于 2014-03-19 19:58:41
回答 3查看 30.4K关注 0票数 5

我买了一个usb rfid阅读器。当用户将rfid标签放在设备前面时,我如何读取数据?

我的计算机将该设备识别为人机接口设备。如果它将其识别为com设备,则从带有serialPort对象的设备读取要容易得多,但我不知道如何读取usb设备。

有什么帮助吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-02-24 17:04:02

这就是当我遇到同样的问题时我所做的。

代码语言:javascript
运行
AI代码解释
复制
using System;
using System.Text;
using LibUsbDotNet;
using LibUsbDotNet.Main;

namespace Examples
{
internal class ReadPolling
{
    public static UsbDevice MyUsbDevice;

    #region SET YOUR USB Vendor and Product ID!

    public static UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(1234, 1);

    #endregion

    public static void Main(string[] args)
    {
        ErrorCode ec = ErrorCode.None;

        try
        {
            // Find and open the usb device.
            MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

            // If the device is open and ready
            if (MyUsbDevice == null) throw new Exception("Device Not Found.");

            // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
            // it exposes an IUsbDevice interface. If not (WinUSB) the 
            // 'wholeUsbDevice' variable will be null indicating this is 
            // an interface of a device; it does not require or support 
            // configuration and interface selection.
            IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
            if (!ReferenceEquals(wholeUsbDevice, null))
            {
                // This is a "whole" USB device. Before it can be used, 
                // the desired configuration and interface must be selected.

                // Select config #1
                wholeUsbDevice.SetConfiguration(1);

                // Claim interface #0.
                wholeUsbDevice.ClaimInterface(0);
            }

            // open read endpoint 1.
            UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);


            byte[] readBuffer = new byte[1024];
            while (ec == ErrorCode.None)
            {
                int bytesRead;

                // If the device hasn't sent data in the last 5 seconds,
                // a timeout error (ec = IoTimedOut) will occur. 
                ec = reader.Read(readBuffer, 5000, out bytesRead);

                if (bytesRead == 0) throw new Exception(string.Format("{0}:No more bytes!", ec));
                Console.WriteLine("{0} bytes read", bytesRead);

                // Write that output to the console.
                Console.Write(Encoding.Default.GetString(readBuffer, 0, bytesRead));
            }

            Console.WriteLine("\r\nDone!\r\n");
        }
        catch (Exception ex)
        {
            Console.WriteLine();
            Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
        }
        finally
        {
            if (MyUsbDevice != null)
            {
                if (MyUsbDevice.IsOpen)
                {
                    // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
                    // it exposes an IUsbDevice interface. If not (WinUSB) the 
                    // 'wholeUsbDevice' variable will be null indicating this is 
                    // an interface of a device; it does not require or support 
                    // configuration and interface selection.
                    IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                    if (!ReferenceEquals(wholeUsbDevice, null))
                    {
                        // Release interface #0.
                        wholeUsbDevice.ReleaseInterface(0);
                    }

                    MyUsbDevice.Close();
                }
                MyUsbDevice = null;

                // Free usb resources
                UsbDevice.Exit();

            }

            // Wait for user input..
            Console.ReadKey();
        }
    }
  }
}

按供应商和产品id打开USB设备。

打开要读取的UsbEndpointReader类。

从Ep01读取并显示usb设备输出,直到5秒内没有接收到数据。

票数 5
EN

Stack Overflow用户

发布于 2014-03-19 20:03:41

请参阅:How do I read input from a USB HID device?

该设备可能枚举为通用HID,但行为可能类似于键盘。如果是这样,它应该只输入它读取的字符。如果不是,则必须从驱动程序中进行轮询。这个链接应该会有帮助。

票数 1
EN

Stack Overflow用户

发布于 2014-08-02 11:55:39

如果他们为你的阅读器提供了SDK,那么就使用它。否则,您必须知道reader.Send命令的十六进制命令才能读取和获取响应

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22516812

复制
相关文章
python将日期转换为时间戳_python – 将日期时间转换为时间戳,然后再返回
>>> local = datetime(2014, 1, 30, 23, 59, 40, 1999)
用户7886150
2021/01/19
3.7K0
JS将日期转换为时间戳
1.getTime() 精确到毫秒 let date = new Date() let timeStamp = date.getTime() console.log(timeStamp) // 1606704849115 2.valueOf() 精确到毫秒 let date = new Date() let timeStamp = date.valueOf() console.log(timeStamp) // 1606704906237 3.parse() 精确到秒,毫秒会用000替代 let date
peng_tianyu
2022/12/15
13.7K0
js将字符串时间转换为date对象_js转换日期格式
var s =’2018-10-09 10:23:12′; s = s.replace(/-/g,”/”); var date = new Date(s );
全栈程序员站长
2022/11/09
12.8K0
qt将毫秒级时间戳转换为日期(js把对象变成字符串)
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/128759.html原文链接:https://javaforall.cn
全栈程序员站长
2022/07/28
6.8K0
jquery 时间戳转换为日期
1.转换为年月日 new Date(data.createDate).toLocaleDateString()//将json中的时间戳转换为年月日 2.精确到秒 function getMyDate
用户5899361
2020/12/07
4.4K0
Python如何将GrADs常用文件转换为NetCDF格式?
测试数据分享 链接:https://pan.baidu.com/s/1mj1-YpvQN414crNz32f8GA 提取码:wmfr
气象学家
2022/01/18
1.9K0
Python如何将GrADs常用文件转换为NetCDF格式?
javascript中如何正确将日期(Date)字符串转换为日期(Date)对象?
因近日一个项目中要在客户端判断用户输入的日期字符串的大小,所以对日期字符串转日期对象研究了一下,测试代码如下: <script. type="text/javascript"> var sDate1 = "2008/04/02"; var sDate2 = "2005/03/01"; var oDate1 = new Date(sDate1); var oDate2 = new Date(sDate2); if (oDate1 > oDate2)//输出 2008/04/
菩提树下的杨过
2018/01/22
6K0
Javascript日期时间总结(转)
从后台返回的C#时间为:/Date(-62135596800000)/,这个是C#的DateTime.MinValue; 要在html页面展示,一个方法是后端先处理成yyyy-MM-dd HH:mm:ss的格式,前端直接展示。 如果后端不做处理,就需要前端来做处理了,下面就是看前端处理的这种情况。
山河木马
2019/03/05
4.9K0
Javascript日期时间总结(转)
Python如何将GrADs常用文件转换为NetCDF格式?
首先需要确保xgrads库的安装: pip install xgrads Install from github 或者 git clone https://github.com/miniufo/xgrads.git cd xgrads python setup.py install 链接https://github.com/miniufo/xgrads , 有提供示例ctl和dat文件,下面我们是使用的ctl和grd文件转换的,方法类似: #import sys #sys.path.append('/home/gavin/miniconda3/envs/atmpy/lib/python3.8/site-packages') #sys.path from xgrads import CtlDescriptor, open_CtlDataset ds = open_CtlDataset('lst.ctl') ctl = CtlDescriptor(file='lst.ctl') ds.attrs['pdef' ] = 'None' ds.to_netcdf('lst.nc') data = ds.ro1 data.where(data!=ctl.undef).plot(figsize=(9,5), cmap='jet') 以上需要注意两点: 1.如果在jupyter-lab中无法加载xgrads需要手动添加其路径,使用到的是:import sys 2. xgrads存在bug,如果不添加语句ds.attrs['pdef' ] = 'None'会一直报错,无法生成nc文件!
郭好奇同学
2021/08/26
2.9K0
Python如何将GrADs常用文件转换为NetCDF格式?
MySQL时间戳转日期
FROM_UNIXTIME(unix_timestamp,format) 返回表示 Unix 时间标记的一个字符串,根据format字符串格式化。format可以包含与DATE_FORMAT()函数列出的条目同样的修饰符。下列修饰符可以被用在format字符串中: %M 月名字(January……December) %W 星期名字(Sunday……Saturday) %D 有英语前缀的月份的日期(1st, 2nd, 3rd, 等等。) %Y 年, 数字, 4 位 %y 年, 数字, 2 位 %a 缩写的星期名字(Sun……Sat) %d 月份中的天数, 数字(00……31) %e 月份中的天数, 数字(0……31) %m 月, 数字(01……12) %c 月, 数字(1……12) %b 缩写的月份名字(Jan……Dec) %j 一年中的天数(001……366) %H 小时(00……23) %k 小时(0……23) %h 小时(01……12) %I 小时(01……12) %l 小时(1……12) %i 分钟, 数字(00……59) %r 时间,12 小时(hh:mm:ss [AP]M) %T 时间,24 小时(hh:mm:ss) %S 秒(00……59) %s 秒(00……59) %p AM或PM %w 一个星期中的天数(0=Sunday ……6=Saturday ) %U 星期(0……52), 这里星期天是星期的第一天 %u 星期(0……52), 这里星期一是星期的第一天 %% 一个文字“%”。
全栈程序员站长
2022/06/24
6K0
jQuery 将时间戳转换为时间
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>时间戳转换为时间</title> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no"> </head> <body> <div id="rightalar
王小婷
2021/11/24
2K0
jQuery 将时间戳转换为时间
sql中时间戳转日期
需求: 我将博客和 typecho 后台结合起来,打算做一个在线说说的功能,在 typecho 中输入内容,然后调用接口,实现在我的博客查看说说功能的功能。是不是有点绕?我也这么觉得,但是折腾一下也挺好的。
子舒
2022/06/09
4.5K0
sql中时间戳转日期
如何用python将中文日期转换为数字日期 | 答疑
大家好,这篇文章是在交流群的群友解疑过程中诞生的。 没想到黄同学在帮助群友后还记录了下来,所以就把这篇文章发出来。 问题 他有一个需求,就是对于日期的录入都是中文形式的,需要转换为数字形式的。 由于
朱小五
2020/03/09
3.2K0
Stata | 字符串转日期变量
Stata 将日期、时间以及日期和时间以 1960-01-01 00:00:00.000 为开始时间的整数存储。比如1960-01-01 为 0,1959-12-31 为 -1 , 1960-01-02 为 1 。
PyStaData
2021/03/06
13.3K0
Android 获取时间戳 和时间戳转日期
获取系统时间戳 public String getTime(){ long time=System.currentTimeMillis()/1000;//获取系统时间的10位的时间戳 String str=String.valueOf(time); return str; } 、获取系统时间 long currentTime = System.currentTimeMillis(); SimpleDateFormat formatter = new SimpleDateForma
程思扬
2022/01/10
7.1K0
spring boot 时间戳转日期格式
第一种方式:默认的json处理是 jackson 也就是对configureMessageConverters 没做配置时
全栈程序员站长
2022/06/25
4.6K0
将时间序列转换为分类问题
来源:DeepHub IMBA本文约1900字,建议阅读5分钟在本文中,我们将遵循 CRISP-DM 流程模型,以便我们采用结构化方法来解决业务案例。CRISP-DM 特别适用于潜在分析,通常在行业中用于构建数据科学项目。 本文将以股票交易作为示例。我们用 AI 模型预测股票第二天是涨还是跌。在此背景下,比较了分类算法 XGBoost、随机森林和逻辑分类器。文章的另外一个重点是数据准备。我们必须如何转换数据以便模型可以处理它。 在本文中,我们将遵循 CRISP-DM 流程模型,以便我们采用结构化方法来解决业
数据派THU
2023/05/11
7260
将时间序列转换为分类问题
将tensor转换为图像_tensor转int
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
全栈程序员站长
2022/11/07
12.5K0
jackson将json转换为json对象
高久峰
2023/07/02
6280
点击加载更多

相似问题

如何使用R将Grib1转换为Netcdf?

31

将日期时间格式从RFC1123转换为日期时间对象

13

将1 20转换为日期时间

13

用R将NetCDF转换为SpatialGridDataFrame

13

SQL:将20071117183011转换为日期/时间(MySQL)

12
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档