M
M
mr-Slink2016-03-12 17:19:14
Programming
mr-Slink, 2016-03-12 17:19:14

How can I implement reading and writing CRT-591 cards?

Good afternoon, please give an example code (C#)
For reading and writing data to the card.
On the Internet I came across an example of reading, which by no means wants to work for me

...
               byte Addr;
                byte Cm, Pm;
                UInt16 TxDataLen, RxDataLen;
                byte[] TxData = new byte[1024];
                byte[] RxData = new byte[1024];
                byte ReType = 0;
                byte St0, St1, St2;

                Cm = 0x30;
                Pm = 0x30;
                St0 = St1 = St2 = 0;
                TxDataLen = 0;
                RxDataLen = 0;

                Addr = (byte)(byte.Parse("00", NumberStyles.Number));
...

When you try to use this code, the device does not even try to pick up the card for reading.
At the moment, all standard functions work, except for reading and writing ...
Program code (Part cut out):
...
using CRT591TESTDLL;
...
UInt32 Hdle = 0;
...
private void button1_Click(object sender, EventArgs e)
        {
            Hdle = DllClass.CommOpen("COM1");
            if (Hdle != 0)
            {
                CommPortStatusLabel.Text = "Open Comm.";
            }
            else
            {
                CommPortStatusLabel.Text = "Open Comm. Port Error";
            }
        }
...
private byte command(byte Cm, byte Pm)
        {
            byte Addr;
            UInt16 TxDataLen, RxDataLen;
            byte[] TxData = new byte[1024];
            byte[] RxData = new byte[1024];
            byte ReType = 0;
            byte St0, St1, St2;

            Cm = 0x30;
            Pm = 0x30;
            St0 = St1 = St2 = 0;
            TxDataLen = 0;
            RxDataLen = 0;

            Addr = (byte)(byte.Parse("00", NumberStyles.Number));
            int i = DllClass.ExecuteCommand(Hdle, Addr, Cm, Pm, TxDataLen, TxData, ref ReType, ref St0, ref St1, ref St2, ref RxDataLen, RxData);
            if (i == 0)
            {
                return ReType;
            } else
            {
                return 0;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (command(0x30, 0x30) == 0x50)
            {
                MessageBox.Show("INITIALIZE OK");
            }
            else
            {
                MessageBox.Show("INITIALIZE ERROR");
            }
        }
...

Used library
Documentation for it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TyzhSysAdmin, 2016-03-12
@POS_troi

I don’t consider myself a genius in C#, but in the command function I see only the return of "StatusCode", but I don't see that the data that falls into "RxData" is read.
Also, I don't understand why you take values ​​into the function if there hardcode them

Cm = 0x30;
Pm = 0x30;

Although, as I already said, I'm not a C# specialist, so maybe I don't understand what Finn :)
Yes, and
TxDataLen = 0;
RxDataLen = 0;

You have zeros, why should you give something when you don't ask for anything :)

M
mr-Slink, 2016-03-12
@mr-Slink

Found instructions

"C" 37H PM
"P" 37H PM st0 st1 st2 Result_data(n byte)
"N" 37H PM e0 e1 e2
Result_data(n byte)
PM=39H: All three tracks simultaneous write
ICRW write data to the card from the buffer.
Before writing operation, ICRW need to write data to the buffer.
If there is no data in buffer, ICRW sends back error code"02".
As for the write of data, a card move is performed in the state of reaching the front of MAG. head, and then ICRW moves card through MAG. head backward, and makes verify write (done by read operation), the verify write is performed only time in back read.
For example:
If card is in back of ICRW with card holding, ICRW carries it to front position of MAG. head, then moves it through MAG. head to rear to write card, and makes the verify read by the reverse direction.
If writing is done correctly, ICRW sends positive response with three results including verify read (VF=30H)
When write error occur, ICRW retries 2 times.
When write error still occurs, ICRW sends negative response with three results including verify read, in this case, error code E1 and E0 are “22”.
In case of card jamming, ICRW sends a negative response.
Result structure:
Good write: “P”+“0”+ VF (3 characters)
Bad write: “N”+“2X”(“20”“24”“25”“26”“27”“28”“29 ”)
No write*: “X”+“00”
(* This track is not designated by the parameter.)
Ex)
(1)#1 good, #2 good, #3 good
Positive response “P0”+ “0” + 7EH +“P0”+“0”+ 7EH + “P0”+“0”
(2) #1 good, #2 bad, #3 no write
Negative response “P0”+ “0” + 7EH +“N”+“2X”+ 7EH + “X00”
(Error code E1 and E0 : “22”)
PM=40H: without writing, but clear the buffer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question