1

I am writing a listener which takes input payment data, processes it and then interacts with a device connected as COM device (pinpad vx805). in each machine this device may be assigned to a different Com port (i.e. COM3, COM5 etc...)

after reading this post: Find serial port where my device is connected

i came up with this piece of code that does the work:

Private Shared Function isVX805PinPadConnected2() As Boolean
    Dim query = "SELECT DeviceID FROM Win32_SerialPort WHERE PNPDeviceID LIKE """ + "%VID_11CA&PID_0220%" + """"
    Console.WriteLine(query)
    Output.mainLog("startQuery")
    Dim resp = New ManagementObjectSearcher("root\cimv2", query).Get
    Output.mainLog("endQuery")
    Try
        Output.mainLog("aftertry")
        com = resp(0)("DeviceID").ToString
        Output.mainLog("after extracting com")
        Console.WriteLine("PinPad on " + com)
        Return True
    Catch ex As Exception
        Throw New ConstraintException("Pin Pad Com Port could not be located")
        Output.mainLog(ex)
    End Try
    Return False
End Function

But his line : com = resp(0)("DeviceID").ToString takes about 4 sec to execute as shown in the log:

2017/02/02 13:50:51 --> EMV Listener Started

2017/02/02 13:53:10 --> Start locating pinpad

2017/02/02 13:53:11 --> startQuery

2017/02/02 13:53:11 --> endQuery

2017/02/02 13:53:11 --> aftertry

2017/02/02 13:53:15 --> after extracting com

2017/02/02 13:53:15 --> End locating pinpad

2017/02/02 13:53:15 --> EMV Listener Started

Any ideas how to make this with better performance? Thanks a lot

Community
  • 1
  • 1
Tal Aruety
  • 23
  • 5

0 Answers0