简体   繁体   English

使用Winforms应用程序向MSR606 Magstripe读/写器发送命令

[英]Sending commands to a MSR606 Magstripe Reader/Writer with Winforms application

I am trying to use an MSR606 Magstripe Reader/Writer with an Application I am coding in .NET Winforms. 我正在尝试将MSR606 Magstripe读/写器与我在.NET Winforms中编码的应用程序一起使用。

After a significant amount of research and a few days of trial and error this is where I'm at. 经过大量的研究和几天的反复试验,这就是我要面对的问题。

*The reader is working through a COM port, I am able to create a reference to it in the application. *读者正在通过COM端口工作,我可以在应用程序中创建对此的引用。

*According to the Manual it expects ANSI encoding *根据手册,它需要ANSI编码

*Commands are listed with a Command Code such as " <ESC><82> " and a hex code such as " 1B 82 " *列出的命令带有命令代码,例如“ <ESC><82> ”和十六进制代码,例如“ 1B 82

This is the code so far 这是到目前为止的代码

CardReader = new SerialPort("COM4");
        CardReader.DataReceived += new SerialDataReceivedEventHandler(DataRecivedHandler);
        CardReader.Encoding = System.Text.Encoding.GetEncoding(28591);
        CardReader.Handshake = Handshake.None;
        CardReader.RtsEnable = true;
        CardReader.Open();

I haven't managed to successfully send a command to the reader. 我还没有成功地向读者发送命令。 I've primarily tested by entering "CardReader.Write()" with commands as strings or byte arrays. 我主要通过使用字符串或字节数组命令输入“ CardReader.Write()”来进行测试。

I have never worked with anything through a COM Port before so I've basically been blindly stumbling through this by looking up any guides I can. 我以前从未通过COM端口进行过任何工作,因此我基本上是通过查找任何我能做的指南来盲目地踏过它。 Any info on how to send commands of that format properly or just explaining where I've gone wrong here would be greatly appreciated. 非常感谢您提供有关如何正确发送该格式命令的任何信息,或者只是解释我在哪里出错的信息。

I eventually figured out that I was formatting the commands wrong. 我最终发现我在格式化命令时出错。 Sending them as hex codes was simply appending "0x" to the code and sending it as a byte[] 将它们作为十六进制代码发送只需在代码后附加“ 0x”并将其作为字节发送[]

CardReader.Write(new byte[] { 0x1b, 0x82 }, 0, 2);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM