INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

Prueba asi:

msginfo( CChex_Update( Anviz_handle, iDx, tipo, aDatos, nLen ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Pg_cts
Posts: 32
Joined: Thu Dec 07, 2017 10:26 am

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Pg_cts »

Sigue igual. Se sale del programa sin indicar ningun error.

Creo que el problema esta en los parámetros.

esta seria la llamada a la función según la documentación.

Code: Select all | Expand


int CChex_Update(IntPtr CchexHandle, int[] DevIdx, int[] Type, IntPtr Buff, int Len)
 


int[] --> ¿Es un array?

Estas son las variable que envía a la funcion el ejemplo de c#

Code: Select all | Expand


            int ret = 0;
            int[] Type = new int[1];
            int[] dev_idx = new int[1];
            IntPtr pBuff;
            int len = 32000;
            pBuff = Marshal.AllocHGlobal(len);
           CChex_Update(anviz_handle, dev_idx, Type, pBuff, len);
 


la variable pBuff --> Marshal.AllocHGlobal(len);

Gracias
User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

Esta declaración:

int CChex_Update(IntPtr CchexHandle, int[] DevIdx, int[] Type, IntPtr Buff, int Len)

no es una declaración de lenguaje C, sino de C#, lo cual significa que puede ser una DLL para .Net

De ser asi, no podemos usarla directamente desde Harbour

Puedes preguntarle al fabricante que te confirme si esa DLL es para ser usada desde .Net ? Y si tienen una DLL para lenguaje C ?
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

Si buscamos en Google por IntPtr mira lo que aparece:

https://docs.microsoft.com/en-us/dotnet/api/system.intptr?view=net-6.0

En donde se confirma que es para C# y .Net
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

Buscando en github he encontrado esto:
https://github.com/alebianky/aNVIZ

y ahi aparece un fichero de cabecera para C:
API_EXTERN int CChex_Update(void *CchexHandle, int *DevIdx, int *Type, char *Buff, int Len);

prueba asi:

Code: Select all | Expand

HB_FUNC( CCHEX_UPDATE )
{
   int DevIdx = hb_parni( 2 );
   int Type = hb_parni( 3 );

   hb_retnl( CChex_Update( ( void * ) hb_parnl( 1 ), &DevIdx, &Type, ( char * ) hb_parc( 4 ), hb_parni( 5 ) ) );
}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Pg_cts
Posts: 32
Joined: Thu Dec 07, 2017 10:26 am

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Pg_cts »

Antonio, ante todo muchas gracias por la ayuda que me estas prestando.

Actualmente ya no dá error y la cadena aDatos recibe información.

El nuevo problema es que creo que la cadena que devuelve es una estructura (¿array?).

Code: Select all | Expand


 {
                                AnvizNew.CCHEX_RET_RECORD_INFO_STRU_CARD_ID_LEN_7 record_info;
                                record_info = (AnvizNew.CCHEX_RET_RECORD_INFO_STRU_CARD_ID_LEN_7)Marshal.PtrToStructure(pBuff, typeof(AnvizNew.CCHEX_RET_RECORD_INFO_STRU_CARD_ID_LEN_7));

                                DateTime date = new DateTime(2000, 1, 2).AddSeconds(swapInt32(BitConverter.ToUInt32(record_info.Date, 0)));
                                string dateStr = date.ToString("yyyy-MM-dd HH:mm:ss");

                                string info_buff = "Record Info ----[ Mid:" + record_info.MachineId
                                    + " Date:" + dateStr
                                    + "PersonID: " + CardId_array_to_string(record_info.CardId)
                                    + " RecType:" + record_info.RecordType.ToString()
                                    + " ]" + "(" + record_info.CurIdx.ToString() + "/" + record_info.TotalCnt.ToString() + ")";
                                log_add_string(info_buff);
                            }
 


record_info = (AnvizNew.CCHEX_RET_RECORD_INFO_STRU_CARD_ID_LEN_7)Marshal.PtrToStructure(pBuff, typeof(AnvizNew.CCHEX_RET_RECORD_INFO_STRU_CARD_ID_LEN_7));


¿Hay alguna función que nos haga lo mismo?

Gracias
User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

Guarda todo lo que recibes en un fichero de texto y enviamelo
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

hb_memoWrit( "datos.txt", aDatos )

y me envias datos.txt por email, gracias
regards, saludos

Antonio Linares
www.fivetechsoft.com
Pg_cts
Posts: 32
Joined: Thu Dec 07, 2017 10:26 am

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Pg_cts »

Este es el enlace de la descarga:

https://we.tl/t-SQSDwupP1l

los he creado de la siguiente forma:

Code: Select all | Expand


    vRet:=CChex_DownloadAllRecords(Anviz_handle,1)
    syswait(2) 
    vCual:=0
    do while .t.
        aDatos:=space(32000)
        nLen:=len(aDatos)
        vRet:=(CChex_Update(Anviz_handle,iDx,tipo,aDatos,32000))   
        syswait(2)         
        if vRet > 0
           vCual++
           nomf = "Fichero"+strzero(vCual,3)+".txt"
           handle = fcreate(nomf)         
           for x=1 to len(aDatos)
              fwrite(handle,substr(aDatos,x,1),1)
           next x
           fclose(handle)         
        else
           exit
        end if
   end do
 


Gracias
User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

Hay 45 empleados ?

Esta es la estructura CCHEX_RET_RECORD_INFO_STRU_CARD_ID_LEN_7:

Code: Select all | Expand

       public struct CCHEX_RET_RECORD_INFO_STRU_CARD_ID_LEN_7
        {
            public uint MachineId;         //机器号
            public byte NewRecordFlag;    //是否是新记录
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 7)]
            public byte[] CardId;    //
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 4)]
            public byte[] Date;          //日期时间
            public byte BackId;           //备份号
            public byte RecordType;       //记录类型
            [MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst = 3)]
            public byte[] WorkType;      //工种        (ONLY use 3bytes )
            public byte Rsv;

            public uint CurIdx;             //add  VER 22
            public uint TotalCnt;           //add  VER 22
        }

localizado aqui:
https://github.com/TashchCoder/AnvizFaceDeep3/blob/b113b3539974fb17824948a998f47bf8d6c698b9/TC_AnvizFaceDeep3/TC_AnvizFaceDeep3/Anviz.cs

Lo próximo es pasar esa estructura a lenguaje C y devolverla como un array. Envíame un email a alinares@fivetechsoft.com y hablamos
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

Comenzamos a analizar el primer fichero:

Code: Select all | Expand

#include "FiveWin.ch"

function Main()

   local aInfo := StructToArray( hb_memoRead( "Fichero001.txt" ) )

   MsgInfo( StructLen(), "CardId struct length" )

   MsgInfo( aInfo[ 1 ], "MachineId" )
   MsgInfo( aInfo[ 2 ], "NewRecordFlag" )
   MsgInfo( hb_hexToNum( hb_strToHex( aInfo[ 3 ] ) ), "CardId" )
   MsgInfo( hb_strToHex( aInfo[ 4 ] ), "Date" )
   MsgInfo( aInfo[ 5 ], "BackId" )
   MsgInfo( aInfo[ 6 ], "RecordType" )
   MsgInfo( hb_hexToNum( hb_strToHex( aInfo[ 7 ] ) ), "WorkType" )
   MsgInfo( aInfo[ 8 ], "Rsv" )
   MsgInfo( aInfo[ 9 ], "CurIdx" )
   MsgInfo( aInfo[ 10 ], "TotalCnt" )
   
return nil

#pragma BEGINDUMP

#include <hbapi.h>

typedef struct CCHEX_RET_RECORD_INFO_STRU_CARD_ID_LEN_7
{
   unsigned int MachineId;
   unsigned char NewRecordFlag;
   unsigned char CardId[ 7 ];  // ademas en el nombre de la estructura se especifica CARD_ID_LEN_7
   unsigned char Date[ 4 ];
   unsigned char BackId;
   unsigned char RecordType;
   unsigned char WorkType[ 3 ];
   unsigned char Rsv;
   unsigned int CurIdx;
   unsigned int TotalCnt;
} CARDINFO;

HB_FUNC( STRUCTLEN )
{
   hb_retnl( sizeof( CARDINFO ) );
}

HB_FUNC( STRUCTTOARRAY )
{
   CARDINFO * data = ( CARDINFO * ) hb_parc( 1 );

   hb_reta( 10 );
   hb_storvni( data->MachineId, -1, 1 );      
   hb_storvni( data->NewRecordFlag, -1, 2 );      
   hb_storvclen( ( const char * ) data->CardId, 7, -1, 3 );      
   hb_storvclen( ( const char * ) data->Date, 4, -1, 4 );      
   hb_storvni( data->BackId, -1, 5 );
   hb_storvni( data->RecordType, -1, 6 );
   hb_storvclen( ( const char * ) data->WorkType, 3, -1, 7 );      
   hb_storvni( data->Rsv, -1, 8 );
   hb_storvni( data->CurIdx, -1, 9 );
   hb_storvni( data->TotalCnt, -1, 10 );
}  

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Pg_cts
Posts: 32
Joined: Thu Dec 07, 2017 10:26 am

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Pg_cts »

Antonio,

Muchas gracias por tu ayuda.

Ya tengo todo lo que pretendia hacer solucionado.

Cuando lo tenga todo solucionado lo subiré por si puede ayudar a alguien a conectar con los dispositivos biométricos de ANVIZ.

De nuevo, Gracias y un saludo.
User avatar
Antonio Linares
Site Admin
Posts: 42649
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 62 times
Been thanked: 93 times
Contact:

Re: INTEGRACION CON DLL PARA CONECTAR CON DISPOSITIVOS ANVIZ

Post by Antonio Linares »

Muy bien!

muchas gracias
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply