Affected version: Version 2.9.8 or later versions


About the OverflowException


The previous sample code converted the output of Marshal.ReadInt32 to a UInt32. Because Marshal.ReadInt32 returns a signed 32-bit value, IDs with the most-significant bit set are interpreted as negative. Converting a negative int via Convert.ToUInt32 is range-checked and throws an OverflowException. The sample now uses unchecked to reinterpret the same 32 bits as an unsigned value, avoiding the exception.


From Device SDK version 2.9.8 onward, users can search for Wiegand devices without requiring additional code modifications.


In the SlaveControl sample code, the conversion method for wiegandDeviceID was changed from


UInt32 wiegandDeviceID = Convert.ToUInt32(Marshal.ReadInt32(wiegandDeviceObj, (int)idx * sizeof(UInt32)));


to


UInt32 wiegandDeviceID = unchecked((UInt32)Marshal.ReadInt32(wiegandDeviceObj, (int)idx * sizeof(UInt32)));



Affected version: Version 2.9.6 or earlier versions


If you've tried searching Wiegand devices with the SDK sample Wiegand Control, you may have run into the error below.


image  

[screenshot is of an altered version of Slave control where I added the Wiegand control code] 


This occurs because if the Convert.ToUInt32 value is less than 0 an error occurs. 


In that case, change the code

UInt32 wiegandDeviceID = Convert.ToUInt32(Marshal.ReadInt32(wiegandDeviceObj, (int)idx * sizeof(UInt32)));


to below to resolve the issue


UInt32 wiegandDeviceID = unchecked((UInt32)Marshal.ReadInt32(wiegandDeviceObj, (int)idx * sizeof(UInt32)));



image

image