0
當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。
我試圖使用do while循環哪種工作,但對話框永遠不會關閉,除非我打了X.我認爲它會保持打開雖然X = 1 – Tim