Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm using proximity card reader to read card number.
Using producer software, when I read I'm getting this number:

BF 1C 08 04 01

But using my application this one:

3F-1C-08-04-01

Code:

C#
void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
                _received += sp.ReadExisting();
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] bytes = encoding.GetBytes(_received);
                bytes = SubArray(bytes, 5, 5);//to get only that I need
                string s2 = BitConverter.ToString(bytes);
             
    
                _received = s2.Replace("-", "");
    
                string result = SocketSendReceive(host, port);
    
                _received = "";
        }


Any ideas?
Posted
Comments
trucha13657 23-Jan-15 5:09am    
Also Encoding.Default returns the same wrong value.
Jochen Arndt 23-Jan-15 5:36am    
It seems that the MSB get lost somewhere.
This may be sourced by using ASCIIEncoding() because ASCII uses only valus from hex 0 to 7F.
trucha13657 23-Jan-15 5:48am    
byte[] bytes = Encoding.Default.GetBytes(_received);
returns the same values, but shouldn't, right?
Jochen Arndt 23-Jan-15 6:07am    
If you use the 'Reply' button right of a comment, the poster of the comment gets an email notification. So I saw your comment only by re-visiting.

See https://msdn.microsoft.com/library/system.text.encoding.default(v=vs.110).aspx.
Overall you should not apply any encoding.

You may try to use GetEncoding(1252) because that is an 8-bit encoding. Or just copy the string as is to a byte array.
CPallini 23-Jan-15 6:21am    
What is SubArray?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900