Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a MSR206 card reader device, and I wrote an application to write data on it in C#:
SerialPort sp = new SerialPort(driveletter);
List<byte> bytes = new List<byte>();
            bytes.Add(0x1B);
            bytes.Add(0x77);
            bytes.Add(0x1B);
            bytes.Add(0x73);
            bytes.Add(0x1B);
            bytes.Add(0x01);
            bytes.AddRange(Encoding.ASCII.GetBytes(u));
            bytes.Add(0x1B);
            bytes.Add(0x02);
            bytes.AddRange(Encoding.ASCII.GetBytes(p));
            bytes.Add(0x1B);
            bytes.Add(0x03);
            bytes.AddRange(Encoding.ASCII.GetBytes(o));
            bytes.Add(0x3F);
            bytes.Add(0x1C);
SendBytes(sp, bytes.ToArray());

static void SendBytes(SerialPort sp, byte[] bytes)
        {
            try
            {
                if (!sp.IsOpen)
                    sp.Open();
                sp.Write(bytes, 0, bytes.Length);

                Console.WriteLine("Bytes sent...");
            }
            catch (Exception ee)
            {
                Console.WriteLine(ee.Message);
            }
        }


This should write 3 strings on the 3 tracks, but when I try to read the datas from the card it gives back meaningless informations. (the device sends back a "WRITE OK", so the writing was succesful)
Posted
Updated 4-Aug-12 23:30pm
v4
Comments
OriginalGriff 5-Aug-12 5:25am    
The code fragment you supplied writes nothing to the card - it purely puts data into a List.
Edit your question, and show the data write fragment as well.
Use the "Improve question" widget to edit your question and provide better information.
velvet7 5-Aug-12 5:29am    
Updated.

1 solution

Without the actual hardware it is difficult to tell what the problem is, but a quick look at the manual suggests that it uses 5 bit data - so lowercase values are not going to work (Page 9-2 of the PDF version) as they don't exist.
Have you tried numeric values? Or checking what the test program they supply does?
 
Share this answer
 
Comments
velvet7 5-Aug-12 5:52am    
I checked the test program too, but same thing. Though I tried with numeric values, and they were just working fine. But when I tried to read the card the text appeared like this:%123? So how could I write on the card without the start and the end characters? I mean, I don't want the % and ? character to appear after reading.
OriginalGriff 5-Aug-12 6:19am    
Look like from the manual that the data is always enclosed in '%' and '?' or ';' and '?' characters - so strip them off when you read them back - I don't think you can suppress that.
velvet7 5-Aug-12 6:22am    
Yeah, but the point of this whole thing is to directly write this data to an application on another computer. So this '%' and '?' would screw the whole thing up.
OriginalGriff 5-Aug-12 7:13am    
So encapsulate it.
Create a class which conmtains teh connection, and has a "WriteString" and "ReadString", or "WriteData" and "ReadData" methods.
They can talk to the reader, and encode date and strip data as necessary. Your external progamms talk to your class rather than the reader itself.

Much tidier approach anyway!
velvet7 5-Aug-12 7:18am    
I don't really understand you, the start character and the end character would stay there.

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