我是 C# 新手,目前正在开发支持 PIN 键盘的后端代码。基本上,我的代码
OpenDevice() -> RequestPIN()
-> key in PIN on PIN PAD -> GetResultPIN()
-> ConsolePrintOutPIN() -> Print keyed PIN on the Console
我不知道如何为此编写线程,这样一旦在 PIN 后在设备上按下“Enter 键”,系统就会自动滚动运行GetResultPIN()
。因此,根据我的基本知识,我编写了以下代码Console.ReadLine()
来分隔每个过程:
static void Main(string[] args)
{
// 1. Open PIN Pad device
OpenDevice();
Console.ReadLine();// to hold up from the previous procedure, it is *not* for input data purpose
// 2. Request PIN from PIN Pad device.
// On the PIN Pad device, it reads:
// "Key in the PIN: "
RequestPIN();
Console.ReadLine();// to hold up from the previous procedure, it is *not* for input data purpose
// 3. get PIN from the device
GetResultPIN();
// 4. Print out on the Console
ConsolePrintOutPIN();
Console.ReadLine();// to hold up from the previous procedure, it is *not* for input data purpose
}
问题:谁能给我任何关于如何使用可以避免使用的线程/事件/委托的建议Console.ReadLine()
?
如上所述,Console.ReadLine()
仅用于停止程序(抱歉我以这种方式使用它的天真......)一旦我使用Console.ReadLine()
, between RequestPIN()
and GetResult()
,系统至少会等待我从 PIN PAD 输入 PIN (通过 USB 连接到计算机,而不是从键盘),然后我会按键盘上的任何键通过Console.ReadLine()
,并且GetResultPIN()
能够从 PIN Pad 获取我的 PIN 码.....整个程序现在可以工作了,它没有客户准备好,因为它非常波涛汹涌,由于我添加而不会流动Console.ReadLine()
......
所以理想情况下,所有的方法都会一起流动。一旦设备打开,RequestPIN()
应该在PIN Pad屏幕上显示询问PIN号码,有人可以在PIN Pad上键入并按Enter键,它自然会流入GetResultPIN()
并读取结果,然后在控制台上打印PIN。 .`
或者
如果此人没有输入 PIN 码,设备将等待 30 秒,然后直接GetResultPIN()
在控制台上打印出“0000”
我已经查看了踩踏和委托,但不知道在这种情况下如何使用它们....谢谢!
参考: RequestPin() 和 GetResultPIN 如下所列:
mIPAD.requestPIN(waitTime, pinMsg, minLen, maxLen, tone, option, ",");
//This function wraps device command 0x04.
//It directs the device to prompt the user to enter a PIN
//by displaying one of five predetermined messages and playing
// a specified sound.
//The messages on the device’s screen look like the figures below.
//The event associated with this function is
//OnPINRequestCompleteEvent.
waitTime:设备应等待用户开始输入 PIN 的时间
pinMsg:作为用户提示显示的消息,例如“输入 PIN”、“重新输入 PIN”、“验证 PIN”等
minLen 和 maxLen:PIN 的最小长度和最大长度
音调:提示音选项
选项:验证 PIN,不验证 PIN,ISO0 格式,ISO3 格式
输出为:整数,0:成功,非零:错误
public void GetResultPIN()
{
StringBuilder sb = new StringBuilder();
sb.Append(mIPAD.pin.KSN);
// Key Serial Number:
//a given number from the device, unique for each device
sb.Append("," + mIPAD.pin.EPB);
// EPB: encryption of PIN after Dubpt TripleDES,
// essentially, EPB is PIN
sb.Append("," + mIPAD.getStatusCode());
//status code: Zero is good/done
// None-Zero is Error
sb.Append("\r\n");
result = sb.ToString();
}
基本上,GetResultPIN() 返回一串随机码,例如:
9A00030000047A2000AB,AD781711481B08A2,0
当 PIN 成功时。如果引脚输入部分被跳过,它将返回,,0
.