Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have a project of finger print device.
I am new in .net. If some one can help me out my.

My problem is "device is turned off automatically when i jump to another method of same controller".



Code is here

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SecuGen.FDxSDKPro.Windows;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;
using System.Web.Mvc;
using System.Data;

using System.Drawing.Drawing2D;

namespace MvcApplication2.Models
{
    public class Dis
    {
        private bool m_useAnsiTemplate = false;
        public bool m_DeviceOpened;
        public Byte[] m_StoredTemplate = null;
        public Int32 m_ImageWidth = 300;
        public Int32 m_ImageHeight = 400;
        public Int32 m_Dpi = 500;
        public SGFingerPrintManager m_FPM = new SGFingerPrintManager();
        public Byte[] m_RegMin1 = null;
        public Byte[] m_RegMin2 = null;
        public Byte[] m_VrfMin;
        Int32 device_id;
        Int32 error = 0;
     
        private SGFPMSecurityLevel m_SecurityLevel = SGFPMSecurityLevel.NORMAL;

        SGFPMDeviceName device_name = SGFPMDeviceName.DEV_UNKNOWN;
        public void initialize()
        {
            m_DeviceOpened = false;
            Int32 error;
            
            device_id = (Int32)SGFPMPortAddr.USB_AUTO_DETECT;

            device_name = SGFPMDeviceName.DEV_AUTO;
            if (device_name != SGFPMDeviceName.DEV_UNKNOWN)
            {
                error = m_FPM.Init(device_name);

                if (error == (Int32)SGFPMError.ERROR_NONE)
                {
                    m_FPM.CloseDevice();
                    error = m_FPM.OpenDevice(device_id);
                }

                if (error == (Int32)SGFPMError.ERROR_NONE)
                {
                    SGFPMDeviceInfoParam pInfo = new SGFPMDeviceInfoParam();
                    m_FPM.GetDeviceInfo(pInfo);
                    m_ImageWidth = pInfo.ImageWidth;
                    m_ImageHeight = pInfo.ImageHeight;
                }
            }
            else
                error = m_FPM.InitEx(m_ImageWidth, m_ImageHeight, m_Dpi);

            error = m_FPM.SetTemplateFormat(SGFPMTemplateFormat.ISO19794);


            // Get Max template size
            Int32 max_template_size = 0;
            error = m_FPM.GetMaxTemplateSize(ref max_template_size);

            m_RegMin1 = new Byte[max_template_size];
            m_RegMin2 = new Byte[max_template_size];
            m_VrfMin = new Byte[max_template_size];


            HttpContext.Current.Session["data1"] = m_RegMin1;

            // OpenDevice if device is selected
            if (device_name != SGFPMDeviceName.DEV_UNKNOWN)
            {
                error = m_FPM.OpenDevice(device_id);
                if (error == (Int32)SGFPMError.ERROR_NONE)
                {
                    m_DeviceOpened = true;
                    HttpContext.Current.Session["deviceStatus"] = m_DeviceOpened;
                }
            }
            error = m_FPM.OpenDevice(device_id);
        }


        public Image BtnCapture1_Click(Image nq)
        {
            
            var dS = HttpContext.Current.Session["deviceStatus"];
            Byte[] fp_image = new Byte[m_ImageWidth * m_ImageHeight];
            error = (Int32)SGFPMError.ERROR_NONE;
            Int32 img_qlty = 0;
            if(m_DeviceOpened == false)
            initialize();

            // Get Max template size
            if (m_DeviceOpened)
                error = m_FPM.GetImage(fp_image);
            if (error == (Int32)SGFPMError.ERROR_NONE)
            {
                m_FPM.GetImageQuality(m_ImageWidth, m_ImageHeight, fp_image, ref img_qlty);
            }

            Image nt = DrawImage(fp_image, nq);
            SGFPMFingerInfo finger_info = new SGFPMFingerInfo();

            finger_info.ImageQuality = (Int16)img_qlty;
            finger_info.ImpressionType = (Int16)SGFPMImpressionType.IMPTYPE_LP;
            finger_info.ViewNumber = 1;

            error = m_FPM.CreateTemplate(finger_info, fp_image,m_RegMin1);
            HttpContext.Current.Session["reg1"] = m_RegMin1;
            return nt;
        }



        public Image BtnCapture2_Click(Image nq)
        {
            Byte[] fp_image = new Byte[m_ImageWidth * m_ImageHeight];
            error = (Int32)SGFPMError.ERROR_NONE;
            Int32 img_qlty = 0;
            if (m_DeviceOpened == false)
            initialize();

            // Get Max template size
            if (m_DeviceOpened)
                error = m_FPM.GetImage(fp_image);


            if (error == (Int32)SGFPMError.ERROR_NONE)
            {
                m_FPM.GetImageQuality(m_ImageWidth, m_ImageHeight, fp_image, ref img_qlty);
            }

            Image nt = DrawImage(fp_image, nq);
            SGFPMFingerInfo finger_info = new SGFPMFingerInfo();

            finger_info.ImageQuality = (Int16)img_qlty;
            finger_info.ImpressionType = (Int16)SGFPMImpressionType.IMPTYPE_LP;
            finger_info.ViewNumber = 1;

            error = m_FPM.CreateTemplate(finger_info, fp_image, m_RegMin2);
            HttpContext.Current.Session["reg2"] = m_RegMin2;

            return nt;
        }


        public void register(string Usernm, string password1, string password2)
        {
            var RegMin1= HttpContext.Current.Session["reg1"];
            var RegMin2 = HttpContext.Current.Session["reg2"];
           
            bool matched = false;
            Int32 err = 0;
            err = m_FPM.MatchTemplate(RegMin1 as Byte[], RegMin2 as Byte[], m_SecurityLevel, ref matched);


            if ((err == (Int32)SGFPMError.ERROR_NONE))
            {
                if (matched)
                {
                    // Save template after merging two template - m_FetBuf1, m_FetBuf2
                    Byte[] merged_template;
                    Int32 buf_size = 0;

                    if (m_useAnsiTemplate)
                    {
                        m_FPM.GetTemplateSizeAfterMerge(m_RegMin1, m_RegMin2, ref buf_size);
                        merged_template = new Byte[buf_size];
                        m_FPM.MergeAnsiTemplate(m_RegMin1, m_RegMin2, merged_template);
                    }
                    else
                    {
                        m_FPM.GetIsoTemplateSizeAfterMerge(m_RegMin1, m_RegMin2, ref buf_size);
                        merged_template = new Byte[buf_size];
                        m_FPM.MergeIsoTemplate(m_RegMin1, m_RegMin2, merged_template);
                    }

                    if (m_StoredTemplate == null)
                    {
                        m_StoredTemplate = new Byte[buf_size];
                        merged_template.CopyTo(m_StoredTemplate, 0);
                    }
                    else
                    {
                        Int32 new_size = 0;

                        if (m_useAnsiTemplate)
                        {
                            err = m_FPM.GetTemplateSizeAfterMerge(m_StoredTemplate, merged_template, ref new_size);
                        }
                        else
                        {
                            err = m_FPM.GetIsoTemplateSizeAfterMerge(m_StoredTemplate, merged_template, ref new_size);
                        }

                        Byte[] new_enroll_template = new Byte[new_size];

                        if (m_useAnsiTemplate)
                        {
                            err = m_FPM.MergeAnsiTemplate(merged_template, m_StoredTemplate, new_enroll_template);
                        }
                        else
                        {
                            err = m_FPM.MergeIsoTemplate(merged_template, m_StoredTemplate, new_enroll_template);
                        }

                        m_StoredTemplate = new Byte[new_size];

                        new_enroll_template.CopyTo(m_StoredTemplate, 0);
                    }
                    // Let's display ANSI/ISO template Info
                }
            }
        }


        private Image DrawImage(Byte[] imgData, Image picBox)
        {
            int colorval;
            Bitmap bmp = new Bitmap(m_ImageWidth, m_ImageHeight);
            picBox = (Image)bmp;

            for (int i = 0; i < bmp.Width; i++)
            {
                for (int j = 0; j < bmp.Height; j++)
                {
                    colorval = (int)imgData[(j * m_ImageWidth) + i];
                    bmp.SetPixel(i, j, Color.FromArgb(colorval, colorval, colorval));
                }
            }
            Image nt = picBox;
            return nt;
        }
    }
}


This Is The Controller

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SecuGen.FDxSDKPro.Windows;
using MvcApplication2.Models;
using System.IO;

using System.Windows.Forms;

using System.Drawing;

using System.ComponentModel;

using System.Data;
using System.IO;
using System.Drawing.Imaging;//.StreamReader;

namespace MvcApplication2.Controllers
{
    public class NewController : Controller
    {
        public ActionResult Index()
        {
           
            return View();
        }
    
        public string capture()
        {
            string a = Url.Action("SomeImage", "Image");
            return a;
        }
        public string capture1()
        {
            string b = Url.Action("SomeImage1", "Image");
            
            return b;
        }
        [HttpPost]
        public ActionResult reg(string Usernm, string password1, string password2)
        {
            Dis dis = new Dis();
            dis.register(Usernm,password1,password2);
          
            return View("Index");
        }
    }
}


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication2.Models;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace MvcApplication2.Controllers
{
    public class ImageController : Controller
    {

        public ActionResult SomeImage()
        {

            Dis dis = new Dis();
            Image nq = null;
            Image a = dis.BtnCapture1_Click(nq);
            string filepath = @"E:\SourceCode\MvcApplication2\MvcApplication2\Models\Images\1.bmp";
            a.Save(@"E:\SourceCode\MvcApplication2\MvcApplication2\Models\Images\1.bmp");
            return File(filepath, "image/bmp");
        }

        public ActionResult SomeImage1()
        {

            Dis dis = new Dis();
            Image nq = null;
            Image a = dis.BtnCapture2_Click(nq);
            string filepath = @"E:\SourceCode\MvcApplication2\MvcApplication2\Models\Images\2.bmp";
            a.Save(@"E:\SourceCode\MvcApplication2\MvcApplication2\Models\Images\2.bmp");          
            return File(filepath, "image/bmp");
        }

    }
}


This Is my View

C#
@{
    Layout = null;
}
@using MvcApplication2.Models;
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>New User</title>
    <script src="../../Script/script.js" type="text/javascript"></script>
    <script src="../../Script/jquery-1.11.2.js" type="text/javascript"></script>
    <script src="../../Script/filter.js" type="text/javascript"></script>
    <link href="../../StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>

    <div class="mydiv1">
       <div id="Aut">
        <label>Enter Branch Code </label>
        @Html.TextBox("BrnCd","")  <br />
  

        <label>Password</label>
        @Html.TextBox("password", "");
        
        </div>
        <div id="login">
        <div id="login1">
         <label>User Name </label>
        @Html.TextBox("Usernm","")<br />
         <label>Password </label>
        @Html.TextBox("password1", "")<br />
        <label>Confirm Password</label>
        @Html.TextBox("password2", "");
        </div>
        <table>
        <tr>
        <td>
       <div class="im" id="im1">
        
            @*<img id="cap2" src="@ViewBag.imge" alt="" />  *@    
        </div>
        <button id ="C1" class="capture"@* onclick="location.href='@Url.Action("capture", "New")'"*@>Capture Image 1</button>
        </td>
        <td>
        <div class="im" id="im2">
        
            @*<img id="cap2" src="@ViewBag.imge" alt="" />  *@    
        </div>
        <button id="C2" class="capture" @*onclick="location.href='@Url.Action("capture1", "New")'"*@>Capture Image 2</button>
        </td>
        </tr>
            </table>
       <div id="sub">
     <button id="R" class="capture" @*onclick="location.href='@Url.Action("capture1", "New")'"*@>Register</button>
    </div>
    <label>@ViewBag.status</label>

    </div>
   </body>
   
  
   
</html>
<script type="text/javascript">
$("#C1").click(function(){

$.ajax({
  type: "GET",
 url:  '@Url.Action("capture", "New")',
  contentType: "string",
  
  
  success: function(data){
      $('#im1').html('<img id="cap1" src="' + data + '" />');
  }
 } );
});


$("#C2").click(function () {

    $.ajax({
        type: "GET",
        url: '@Url.Action("capture1", "New")',
        contentType: "string",


        success: function (data) {
            $('#im2').html('<img id="cap2" src="' + data + '" />');
        }
    });
});

$("#R").click(function () {

    $.ajax({
        type: "POST",
        url: '@Url.Action("Reg", "New")',
        contentType: "string",


        success: function (data) {
            $('#im2').html('<img id="cap2" src="' + data + '" />');
        }
    });
});
</script></div>
Posted
Updated 9-Mar-15 19:32pm
v2
Comments
Member 12003400 27-Apr-17 10:38am    
could you solve your this query?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900