@mr-Slink

Как мне реализовать чтение и запись карт CRT-591?

Добрый день, дайте пожалуйста пример кода (C#)
Для чтения и записи данных на карту.

В интернете наткнулся на пример чтения, который ну никак не хочет у меня работать
...
               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));
...

При попытке использовать этот код, устройство даже не пытается забрать карту для чтения.

На данный момент работают все стандартные функции, кроме чтения и записи...
Код программы (Часть вырезал):
...
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");
            }
        }
...


Используемая библиотека
Документация к ней
  • Вопрос задан
  • 265 просмотров
Пригласить эксперта
Ответы на вопрос 2
POS_troi
@POS_troi
СадоМазо Админ, флудер, троль.
Не считаю себя гением в C# но я в функции command вижу только возврат "СтатусКод"-а но не вижу что-бы читались данные которые падают в "RxData"
Так-же я не понимаю к чему вы принимаете в функцию значения если тут-же жестко их переопределяете
Cm = 0x30;
Pm = 0x30;

Хотя как уже сказал, я не спец по C# так что может какой фин я не понимаю :)

Да и
TxDataLen = 0;
RxDataLen = 0;

У вас по нулям, зачем вам что-то отдавать когда вы ничего не просите :)
Ответ написан
@mr-Slink Автор вопроса
Нашел инструкцию
"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 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
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы