尝试在 IDTECH 卡写入器等待刷卡时显示一个新表单,上面写着“请刷卡”。
private void writecard(string track1) //string track2)
{
SerialPort sp1 = new SerialPort(encoderport, 9600, Parity.None, 8, StopBits.One);
sp1.ReadTimeout = 10000;
if (sp1.IsOpen == true)
{
sp1.Close();
}
sp1.Open();
sp1.Write(new byte[] { 0x1B, 0x77 }, 0, 2);
Thread.Sleep(100);
sp1.Write(new byte[] { 0x1B, 0x73 }, 0, 2);
Thread.Sleep(100);
sp1.Write(new byte[] { 0x1B, 0x01 }, 0, 2);
Thread.Sleep(100);
sp1.Write(track1); // Track 1
Thread.Sleep(100);
sp1.Write(new byte[] { 0x3f, 0x1c }, 0, 2);
swipeform swipepop = new swipeform();
swipepop.ShowDialog(); // **Problem**
Thread.Sleep(100);
try
{
swipepop.Close(); // **Problem**
int firstChar = sp1.ReadChar();
Thread.Sleep(500);
string data = String.Concat(Convert.ToChar(firstChar), sp1.ReadExisting());
//textBox3.Text = String.Format(data);
if (data != "")
{
char result = data[1];
if (result == '0')
MessageBox.Show("Encoding Successful");
else
MessageBox.Show("Encoding Failed - Please try again");
}
}
catch (System.TimeoutException)
{
MessageBox.Show("Timed out. Please try again.");
sp1.Write(new byte[2] { 0x1b, 0x61 }, 0, 2);
}
sp1.Close();
}
我遇到的问题是,一旦调用 writecard 方法,就会弹出 swipeform 并且设备要您滑动。但是,一旦您滑动表单,表单就会停留并且不会关闭,并且该方法不会继续,直到您关闭 swipeform。