C盘太小如何重新分盘:C# 引脚焊盘设备的线程和事件(pin pad)

我是 C # 的新手,目前正在处理后端代码以支持 PIN pad。基本上,我的代码

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(),在RequestPIN()GetResult()之间,系统至少会等待我从 PIN PAD 输入 PIN(通过 USB 连接到计算机,不会从键盘上的 0)

因此,理想情况下,所有方法将一起流动。打开设备后,RequestPIN()应显示在 PIN Pad 屏幕上,要求输入 PIN 号,有人可以键入并按下 PIN Pad 上的回车键,然后自然流向GetResultPIN()并读取结果,然后在控制台上打印 PIN...'

如果用户没有输入 PIN,设备将等待 30s,然后直接转到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 ociated with this function is 
//OnPINRequestCompleteEvent. 

waitTime:设备应等待用户开始输入 PIN 的时间

pinMsg:显示为用户提示的消息,例如“输入 PIN”,“重新输入 PIN”,“验证 PIN”等

minLen 和 maxLen:PIN 的最小长度和最大长度

提示音:提示音选项

选项:验证 PIN,而不是验证 PIN 、 ISO0 FOrmat 、 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()返回一个随机代码字符串,例如:当 PIN 成功时:9A00030000047A2000AB,AD781711481B08A2,0。如果跳过 pin-input 部分,它将返回,,0

2

真的很难知道这是否会工作或没有硬件玩...

这是我设想它的工作方式:

    static void Main()
    {
        OpenDevice();
        RequestPIN();
        if (GetResultPIN())
        {
            // do something with the PIN:
            var pin = mIPAD.pin.EPB;
            // ...
        }
        else
        {
            Console.WriteLine("0000");
        }
    }
    public static bool GetResultPIN()
    {
        TimeSpan timeout = TimeSpan.FromSeconds(30);
        System.Diagnostics.Stopwatch SW = new System.Diagnostics.Stopwatch();
        SW.Start();
        while (mIPAD.getStatusCode() != 0 && SW.Elapsed < timeout)
        {
            System.Threading.Thread.Sleep(50); // small call to prevent CPU usage ramping to 100%
        }
        return (mIPAD.getStatusCode() == 0);
    }
1

你可以重写你的 API:

使GetResultPIN()返回一个值

使用此值作为ConsolePrintOutPIN()的输入

GetResultPIN中,你需要做一个任务来读取你的引脚并等待它。

See:https://msdn.microsoft.com/en-us/library/dd537610(v=vs.110).aspx

你可以这样做:

public string 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");
    Thread.Sleep(20*1000);  // it is in milliseconds
    return sb.ToString();
}
0

感谢您的发布...解决方案仍然不理想....我还做了一些关于函数RequestPIN()的测试,我有以下四种情况:

用户在waitTime消失之前完成 PIN 的键入。 onPINRequestComplete : OpStatus:0 KSN:9A00030000047A2000C8 EPB:39DED176D3EA40B9 ..............................

waitTime输出时,用户无法完成 PIN 的键入。
onPINRequestComplete : OpStatus:2 KSN:00000000000000000000 EPB:0000000000000000 ..............................

用户通过按 PIN 键盘上的“取消 X”键取消 PIN 键盘选项。

onPINRequestComplete: OpStatus:1 KSN:00000000000000000000 EPB:0000000000000000 ..............................

用户在 waitTime 期间根本不输入 PIN,然后 waitTime 熄灭。

onPINRequestComplete : OpStatus:2 KSN:00000000000000000000 EPB:0000000000000000 .............................. 因此,场景 1 和 3 需要线程立即唤醒,而 2 和 4 需要线程在 waiTime 结束时唤醒。因此,在GetResultPIN()中使用Thread.sleep(20*1000)将非常适合场景 2 和 4。至于 1 和 3,用户必须等待很长时间....

另一方面,我发现了一些关于Event的代码

Car.cs范围内:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WaitOnTasksToComplete
{
    cl Car
    {
        public event Action OnChange;
        private double speed;
        public double Speed
        {
            get { return speed; }
            set { speed = value;
                if (speed >= 60)
                {
                    if (OnChange != null)
                    {
                        OnChange();
                    }
                }
            }
        }
    }
}

Program.cs中:

using System;
namespace WaitOnTasksToComplete
{
    cl Program
    {
        static void Main(string[] args)
        {
            Car c = new Car();
            c.OnChange += C_OnChange;
            c.Speed = 5;
            c.Speed = 55;
            c.Speed = 65;
            c.Speed = 75;
        }
        private static void C_OnChange()
        {
            Console.WriteLine("Event fired: Car goes higher than 60 MPH.");
        }
    }
}

所以,基本上一旦Car.speed跳到 60 以上,警报就会显示。我正在考虑借用条件到我的情况:初始化OpStatus = -999。当OpStatus=0 or 1时,继续执行GetResultPIN()PrintMessagePIN()。如果OpStatus=2 or others,继续等待...

这只是我的想法....仍然不知道如何实现它....任何相关的想法或建议将不胜感激.....

0

啊,我想通了。我基本上在这里使用线程。主要流程是OpenDevice()->RequestPIN()->Thread(()=>CheckOpStatus(getResultPIN)) -> Thread.Start()。在 Thread 中,设置了一个循环,每半秒检查一次OpStatus是什么。根据我以前的帖子,OpStatus是 PIN Pad 的输出参数,zero- success; non-zero: failure因此,循环将在bool condition_WithinWaitTime之后中断。

这是我的源代码,因为 PIN 输入是我的功能之一,其余的在编程方面具有非常相似的行为(请求-手动操作-反馈),所以我还包括一个代表所有功能的委托变量(刷卡,PIN,签名 bla bla)。

    static void Main(string[] args)
    {
        OpenDevice();
        EventGetPIN();
    }
    static void EventGetPIN()
    {
        myDel getResult = new myDel(GetResultPIN);
        Thread thread1 = new Thread(() => CheckOpStatus(getResult));
        myDel requestDel = new myDel(RequestPIN); requestDel();
        thread1.Start();
    }
    static void CheckOpStatus(Delegate getResult)
    {
        int count = 0;
        int checkingPeriod = 500;
        int totalWaitTime = waitTime * 1000 + offsetTime;
        string OpStatus;
        string ksnStart = mIPAD.getKSN();
        string ksn = ksnStart;
        bool condition_WithinWaitTime = true;
        bool condition_NoKeyEvent = true;
        while (condition_WithinWaitTime & condition_NoKeyEvent)
        {
            count++;
            OpStatus = mIPAD.getStatusCode().ToString();
            ksn = mIPAD.getKSN();
            //Console.WriteLine(OpStatus);
            condition_WithinWaitTime = (count * checkingPeriod) < totalWaitTime;
            condition_NoKeyEvent = (ksn == ksnStart);
            Thread.Sleep(checkingPeriod);
        }
        getResult.DynamicInvoke();
    }

本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处

(19)
股大师软件:将道琼斯30股(所有30股)下载到R(list of dow jones stock)
上一篇
依然爱你吉他谱c调:谱聚类(matlab code for spectral clustering)
下一篇

相关推荐

  • win10更新c盘满了:解决Win10更新导致C盘空间不足的方法

    查看C盘空间:右键点击“计算机”,选择“管理”,在左侧窗口中找到“磁盘管理”,可以查看C盘的使用情况。清理C盘:可以通过清理系统垃圾、删除多余文件、释放系统空间等方式来清理C盘。…

    2023-01-25 13:12:34
    0 93 69
  • cf win10烟雾头怎么调:如何调整CF Win10烟雾头以获得最佳效果

    在游戏中,打开控制台,输入“mat_depth_blur_scale 0.5”,这会使烟雾效果减少50%;输入“mat_depth_blur_falloff 0.5”,这会使烟雾效果的衰减率减少50%;…

    2023-01-11 12:59:10
    0 24 17
  • melogin cn登录:【登录melogin cn,轻松获取个性化服务】

    Melogin cn是一个支持多种登录方式的登录框架,可以让用户使用常用的社交账号快速登录网站。以下是使用 Melogin cn 登录的代码示例:…

    2023-02-14 01:08:50
    0 98 35
  • 学习c4d去哪里好:将动画从 cinema4d导出到搅拌机

    关于学习c4d去哪里好的问题,在animation c4d中经常遇到,我一直在尝试将一些动画模型从 c4d 转换为 Blender。这些模型传输正常,但动画没有。我已经使用了 COLLADA,3ds 和 obj 文件类型,但没有成功。我需要将文件放入 Blender,因为我试图将它们放入 three.js。我已经查看了http://disturbmedia.com/blog/tag/threejs/for c4d & gt;threejs,但 python 抛出错误…

    2022-11-23 08:41:29
    0 35 29
  • Phishing:Facebook网络钓鱼检测

    关于Phishing的问题,在facebook phishing site中经常遇到,我正在做一个关于计算机安全的小任务,我目前正在进行网络钓鱼。…

    2022-11-23 08:31:23
    0 59 21
  • 辅助cf:自动cf登录刷新(cf login)

    关于辅助cf的问题,在cf login中经常遇到,CloudFoundry UAA 是否支持登录用户的令牌刷新。我目前使用“cf-cli”通过 SSO 密码登录。大约一周后,会话到期,我必须再次登录。是否可以在到期时刷新 $HOME /.cf / config_json 中的令牌?根据此https://www.rfc-editor.org/rfc/rfc6749#section-6,我们应该能够通过传递 grant_refresh 来刷新令牌。…

    2022-11-23 08:30:12
    0 99 85
  • cv糖醋排骨是弯的吗弯曲的美味

    cv糖醋排骨不是弯的,它是一种制作方法,通常用来制作排骨。代码:…

    2023-04-01 13:03:36
    0 52 26
  • android 视频编码深入理解MediaCodec API

    Android 视频编码是指将原始视频数据经过压缩编码后,生成新的视频数据,以便减少视频文件的体积,提高传输速度,以及更好地在 Android 设备上播放。…

    2023-01-13 10:58:18
    0 97 53

发表评论

登录 后才能评论

评论列表(37条)