How to Enroll a new Users to a BioLite Net Terminal using C#?

-2

I have made this method based of the examples provided by Suprema. When i execute this code it gives me the error "Cannot enroll the user" and the returns error code -105.

The handle = 1, deviceType = 2, _TemplateData = null and TEMPLATE_SIZE = 384 the are all variable asigned ate top of the script.

int handle = Recursos.handle;

//BS_RET_CODE BS_EnrollUserBEPlus( int handle, BEUserHdr* hdr, unsigned char* templateData )
if (txtInicioData.Value.Year < 2020)
{
    MessageBox.Show("Data de inicio não deve ser inferior a 2020.");
    return;
}
if (txtInicioData.Value.Year > 2020)
{
    MessageBox.Show("Data de inicio não deve ser inferior a 2030.");
    return;
}
//
if (txtDataFim.Value.Year < 2020)
{
    MessageBox.Show("Data de Caducidade não deve ser inferior a 2030.");
    return;
}
if (txtDataFim.Value.Year > 2030)
{
    MessageBox.Show("Data de Caducidade não deve ser superior a 2030.");
    return;
}
//
switch (_DeviceType)
{
    case BSSDK.BS_DEVICE_BIOENTRY_PLUS:
    case BSSDK.BS_DEVICE_BIOENTRY_W:
    case BSSDK.BS_DEVICE_BIOLITE:
    case BSSDK.BS_DEVICE_XPASS:
    case BSSDK.BS_DEVICE_XPASS_SLIM:
    case BSSDK.BS_DEVICE_XPASS_SLIM2:
        {
            MessageBox.Show("BS_DEVICE_BIOLITE->" + BSSDK.BS_DEVICE_BIOLITE);
            int numOfUser = 5;
            //
            BSSDK.BEUserHdr[] userHdr = new BSSDK.BEUserHdr[numOfUser];
            //
            for (int i = 0; i < numOfUser; i++)
            {
                userHdr[i].fingerChecksum = new ushort[2];
                userHdr[i].isDuress = new byte[2];
                userHdr[i].numOfFinger = (ushort)0;
                //
                userHdr[i].fingerChecksum[0] = (ushort)0;
                userHdr[i].fingerChecksum[1] = (ushort)0;
                //
                userHdr[i].password = new byte[17];
                MessageBox.Show("password" + password );
                byte[] tmppw = Encoding.Unicode.GetBytes("1234");
                Buffer.BlockCopy(tmppw, 0, userHdr[i].password, 0, 4);
                //
                uint ID = (uint)(i + 1) * 1000;
                userHdr[i].userID = ID;
                userHdr[i].adminLevel = (ushort)userLevel.SelectedIndex;
                userHdr[i].securityLevel = (ushort)securityLevel.SelectedIndex;
                //userHdr[i].cardFlag = (byte)cardType.SelectedIndex;
                userHdr[i].startTime = (int)((txtInicioData.Value.Ticks - new DateTime(2020, 1, 1).Ticks) / 10000000);
                userHdr[i].expiryTime = (int)((txtDataFim.Value.Ticks - new DateTime(2020, 1, 1).Ticks) / 10000000);
                userHdr[i].isDuress[0] = (duress1.Checked) ? (byte)1 : (byte)0;
                userHdr[i].isDuress[1] = (duress2.Checked) ? (byte)1 : (byte)0;
                userHdr[i].opMode = (ushort)authMode.SelectedIndex;
                //
                try
                {
                    userHdr[i].accessGroupMask = UInt32.Parse(accessGroup.Text, System.Globalization.NumberStyles.HexNumber);
                }
                catch (Exception)
                {
                    userHdr[i].accessGroupMask = 0xffffffff;
                }
                //
                IntPtr userInfo = Marshal.AllocHGlobal(numOfUser * Marshal.SizeOf(typeof(BSSDK.BEUserHdr)));
                IntPtr ptrRunner = userInfo;
                for (int j = 0; j < numOfUser; j++)
                {
                    Marshal.StructureToPtr(userHdr[j], ptrRunner, true);
                    ptrRunner = (IntPtr)((int)ptrRunner + Marshal.SizeOf(typeof(BSSDK.BEUserHdr)));
                }
                //
                Cursor.Current = Cursors.WaitCursor;
                int result = BSSDK.BS_EnrollMultipleUserBEPlus( handle, numOfUser, userInfo, _TemplateData );
                Cursor.Current = Cursors.Default;
                //
                Marshal.FreeHGlobal(userInfo);
                //
                if (result != BSSDK.BS_SUCCESS)
                {
                    MessageBox.Show("Cannot enroll the user", "Error");
                    return;
                }
                MessageBox.Show("Erroled with success", "Error");
                //
                //ReadUserInfo();
                //
            }
        }
        break;
}

I'am using the BS_EnrollMultipleUserBEPlus function and this is my UI User Interface

c#
asked on Stack Overflow Jul 22, 2020 by lea.co.ao • edited Jul 23, 2020 by lea.co.ao

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0