Hi,
Application talks to a chip & pin terminal on serial port COM1. Sends commands from PC to terminal
& should display the encrypted responses back. However, I can capture the response to the 1st command only. All subsequent commands, although are transmitted to the terminal, fail to be
captured & hence cannot be displayed. There is definitely a response from the terminal as confirmed by a serial port monitor application running in the back ground.
So the question is what is wrong with the following code & how can I repair it so that I can capture all the responses to all the commands.
private void initialize_com_ports()
{
init_ip_serialport();
init_op_serialport();
}
private void init_op_serialport()
{
op_serialport.PortName = def_ip_portname;
op_serialport.BaudRate = def_baudrate;
op_serialport.DataBits = def_databits;
op_serialport.Handshake = def_handshake;
op_serialport.Parity = def_parity;
op_serialport.StopBits = def_stopbits;
}
private void init_ip_serialport()
{
ip_serialport.PortName = def_ip_portname;
ip_serialport.BaudRate = def_baudrate;
ip_serialport.DataBits = def_databits;
ip_serialport.Handshake = def_handshake;
ip_serialport.Parity = def_parity;
ip_serialport.StopBits = def_stopbits;
}
private void test_harness()
{
display_messages("Start Test Script.", 3);
display_messages("Reset Device.", 3);
byte[] op_data1 = new byte[] { 0x01, 0x00, 0x04, 0xD0, 0x00, 0x00, 0x00, 0xD5 };
op_serialport.Write(op_data1, 0, op_data1.Length);
TX_Box.Items.Add(BitConverter.ToString(op_data1));
op_serialport.Close();
MySerialReader();
byte[] op_data2 = new byte[] { 0x01, 0x00, 0x04, 0xD2, 0x01, 0x01, 0x01, 0xD6 };
write_read_op(op_data2);
display_messages("Reset Display.", 3);
byte[] op_data3 = new byte[] { 0x01, 0x00, 0x04, 0xD0, 0x60, 0x1F, 0x00, 0xAA };
write_read_op(op_data3);
display_messages("Monitor Card status.", 3);
byte[] op_data4 = new byte[] { 0x01, 0x00, 0x04, 0xD0, 0x61, 0x03, 0x00, 0xB7 };
write_read_op(op_data4);
display_messages("Monitor Keyboard status.", 3);
byte[] op_data5 = new byte[] { 0x01, 0x00, 0x04, 0xD2, 0x01, 0x0D, 0x01, 0xDA };
write_read_op(op_data5);
display_messages("Insert Test Card.", 3);
display_messages("Start Transaction Data.", 2);
byte[] op_data = new byte[] { 0x01, 0x00, 0x37, 0xDE, 0xD1, 0x00, 0x00, 0x32,
0xE0, 0x30, 0x9F, 0x02, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x9C, 0x01, 0x00, 0x9F, 0x21,
0x03, 0x01, 0x01, 0x01, 0x9A, 0x03, 0x11, 0x01,
0x01, 0x9F, 0x41, 0x02, 0x00, 0x01, 0xDF, 0xA2,
0x04, 0x01, 0x01, 0x5F, 0x2A, 0x02, 0x08, 0x26,
0xDF, 0xA2, 0x18, 0x01, 0x00, 0xDF, 0xA2, 0x04,
0x01, 0x01, 0x09};
write_read_op(op_data);
display_messages("Press Cancel", 3);
op_data = new byte[] { 0x01, 0x00, 0x46, 0xDE, 0xD2, 0x00, 0x00, 0x41,
0xE0, 0x3F, 0xC0, 0x01, 0x01, 0xC2, 0x02, 0x36,
0x35, 0xDF, 0xA2, 0x18, 0x01, 0x00, 0xDF, 0xA3,
0x07, 0x02, 0x03, 0xE8, 0x8A, 0x02, 0x59, 0x32,
0x91, 0x0A, 0x37, 0xDD, 0x29, 0x75, 0xC2, 0xB6,
0x68, 0x2D, 0x00, 0x12, 0x9F, 0x1B, 0x04, 0x00,
0x00, 0x10, 0x00, 0x9F, 0x02, 0x06, 0x00, 0x00,
0x00, 0x04, 0x99, 0x99, 0x5F, 0x2A, 0x02, 0x09,
0x78, 0x9F, 0x1A, 0x02, 0x09, 0x78, 0xC3, 0x01,
0x01, 0xF1};
write_read_op(op_data);
display_messages("Enter PIN no.", 3);
op_data = new byte[] { 0x01, 0x00, 0x0E, 0xDE, 0xD2, 0x00, 0x00, 0x09,
0xE0, 0x07, 0xC0, 0x01, 0x00, 0x8A, 0x02, 0x30,
0x30, 0xA4 };
write_read_op(op_data);
display_messages("Remove Test Card", 3);
op_data = new byte[] { 0x01, 0x00, 0x04, 0xD2, 0x01, 0x0E, 0x01, 0xD9 };
write_read_op(op_data);
display_messages("Reset Display.", 2);
op_data = new byte[] { 0x01, 0x00, 0x04, 0xD2, 0x01, 0x01, 0x01, 0xD6 };
write_read_op(op_data);
display_messages("Reset Device.", 2);
op_data = new byte[] { 0x01, 0x00, 0x04, 0xD0, 0x00, 0x00, 0x00, 0xD5 };
write_read_op(op_data);
display_messages("End of Script.", 3);
}
private void write_read_op(byte[] command)
{
if (ip_serialport.IsOpen)
{
ip_serialport.Close();
}
op_serialport.Open();
op_serialport.Write(command, 0, command.Length);
TX_Box.Items.Add(BitConverter.ToString(command));
op_serialport.Close();
MySerialReader();
}
private void display_messages(string message, int how_many)
{
if (how_many > 2)
{
MessageBox.Show(message);
}
RX_Box.Items.Add(message);
TX_Box.Items.Add(message);
}
private void MySerialReader()
{
ip_serialport.Open();
ip_serialport.DataReceived += serialPort_DataReceived;
}
public string RxString;
private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
RxString = ip_serialport.ReadExisting();
this.Invoke(new EventHandler(DisplayText_RX));
}
private void DisplayText_RX(object sender, EventArgs e)
{
RX_Box.Items.Add(RxString);
}
Bit long, but hope the above makes some sense. Thanks in advance for all your assistance.
Regards
KM