In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Integracion LaPOS+Cargar DLL

Foro público de Xailer en español
Responder
ryder1912
Mensajes: 29
Registrado: Jue Jul 09, 2015 8:17 pm

Integracion LaPOS+Cargar DLL

Mensaje por ryder1912 »

Buenas a todos. Necesito ayuda para poder usar una DLL de POS prisma paywey (VpiPc.dll) en Xailer.
https://www.google.com/search?client=fi ... gQ76ug3jdM

Por ahora solo pude programar los procedimientos básicos (conectarse, testear la conexión y cerrar la conexión) en C# (sharp) pero la idea es pasarlo a Xailer.
Por lo que pude ver hay que programarlo con Wrappers? pero no tengo idea si lo estoy haciendo bien.

Con respecto a la estructura de datos para conectarse y abrir el puerto (función vpiOpenPort devuelve un entero, 0 o 11)

Código: Seleccionar todo

typedef struct COM_PARAMS{
LPSTR com;         // Nombre del puerto. Ej.: "COM1", etc.
WORD baudRate; // Velocidad de transmisión: Ej.: 19200
WORD byteSize; // Largo del byte. Ej.: 7, 8
BYTE parity;       // Paridad. Ej: 'N' ninguna, 'E' par, 'O' impar
WORD stopBits; // Bits de parada. Ej.: 1, 2
}comParams_t;
Prototipo: WORD __stdcall vpiOpenPort (comParams_t* params);
params: Parámetros de configuración del puerto serial

Retorna un entero. Si es 0 entonces se abrió el puerto, si es 11 no pudo abrirlo.

Este es un ejemplo sencillo en C sharp que pude programar, abre el puerto con la función vpiOpenPort

Código: Seleccionar todo

	
        public struct comParams_t
        {
            [MarshalAs(UnmanagedType.LPStr)]
            public string com;
            public ushort baudRate;
            public ushort byteSize;
            public char parity;
            public ushort stopBits;
        }

        [DllImport("VpiPc.dll", CallingConvention = CallingConvention.StdCall)] // Cargo la DLL
        public static extern ushort vpiOpenPort(ref comParams_t portParams); // Declaro una función externa  
        
         // Declaro la variable paramsStruct de tipo comParams_t , y le paso los valores de conexión al puerto  
 	 comParams_t paramsStruct;
         paramsStruct.com = "COM7";
         paramsStruct.baudRate = 19200;
         paramsStruct.byteSize = 8;
         paramsStruct.parity = 'N';
         paramsStruct.stopBits = 1;

         ushort result = vpiOpenPort(ref paramsStruct); // Llamo a la funcion y devuelve un entero, que puede ser 0 si esta todo OK, o 11 si fallo la conexion
         Console.WriteLine("Resultado de la configuración: " + result);

Me gustaría traducir eso a Xailer
El siguiente código no se si va en un Archivo h o Archivo ch?

Código: Seleccionar todo


#define VPI_OK				0	// Operacion exitosa
#define VPI_FAIL			   11	// El comando no pudo ser enviado

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

// No se si esta bien esto, en la parte de arriba la función recibe un parámetro de referencia con los 5 valores de conexión, aquí no tengo idea como se hace esa parte.
typedef __stdcall int (*AbrirPuerto)(LPTSTR cCOM, int nBaudRate, int nByteSize, LPTSTR cParity,  int nStopBits);

static HINSTANCE  hLib = NULL;

HB_FUNC( TEST )
{
   int result ;
   static AbrirPuerto pFunction = NULL;

   result = -2000 ;
   if( !hLib )
      hLib = LoadLibrary( "VpiPc.dll" );

   if( hLib )
   {
      if( !pFunction )
         pFunction = (AbrirPuerto) GetProcAddress( hLib, "vpiOpenPort" );
   }

   if( pFunction )
      result = (pFunction)( (LPSTR) hb_parni( 1 ), (WORD) hb_parni( 2 ), (WORD) hb_parni( 3 ), (LPSTR) hb_parni( 4 ), (WORD) hb_parni( 5 ) );
   else
      result = -2000;

   hb_retni(result);
}

#pragma ENDDUMP

En archivo.prg

Código: Seleccionar todo

METHOD pruebaClick( oSender ) CLASS TMenuPrincipal

local nHandle
nHandle:=Test("COM4",19200, 8, 'N', 1)

RETURN Nil

La idea es poder ir haciendo de a uno los procedimientos basicos.
Desde ya, gracias. Saludos
ryder1912
Mensajes: 29
Registrado: Jue Jul 09, 2015 8:17 pm

Re: Integracion LaPOS+Cargar DLL

Mensaje por ryder1912 »

Buenas. No me sale la conexión a la terminal. Me tira error cuando quiero usar la dll

#1: [VPIPC_DLL] #################APIENTRY DllMain######################
#2: [VPIPC_DLL] [vpiOpenPort] debug file enabled = 1
#3: [VPIPC_DLL] #################vpiOpenPort######################
#4: GPF (Code = c0000005):
Access violation

TEST (0)
TMENUPRINCIPAL:PRUEBA2CLICK (50)
TBTNBMP:ONCLICK (0)
TBTNBMP:CLICK (100)
(b)XCONTROL (156)
TBTNBMP:COMMAND (0)
TBEVEL:WMCOMMAND (275)
RUNFORM (0)
TAPPLICATION:RUN (289)
MAIN (23)

Este es el programa

Código: Seleccionar todo

METHOD prueba2Click( oSender ) CLASS TMenuPrincipal

local nHandle
nHandle:=Test("COM4",19200, 8, 'N', 1)

RETURN Nil

//------------------------------------------------------------------------------

#pragma BEGINDUMP

#include "Windows.h"
#include "hbapi.h"
#include "Xailer.h"


typedef __stdcall int (*TestConexion)(LPTSTR cCOM, int nBaudRate, int nByteSize, LPTSTR cParity,  int nStopBits);

static HINSTANCE  hLib = NULL;

HB_FUNC( TEST )
{
   int result ;
   static TestConexion pFunction = NULL;

   result = -2000 ;
   if( !hLib )
      hLib = LoadLibrary( "VpiPc.dll" );

   if( hLib )
   {
      if( !pFunction )
         pFunction = (TestConexion) GetProcAddress( hLib, "vpiOpenPort" );
   }

   if( pFunction )
      result = (pFunction)( (LPSTR) hb_parni( 1 ), (WORD) hb_parni( 2 ), (WORD) hb_parni( 3 ), (LPSTR) hb_parni( 4 ), (WORD) hb_parni( 5 ) );
   else
      result = -2000;

   hb_retni(result);
}

#pragma ENDDUMP
Que estoy haciendo mal? Desde ya, gracias.
Saludos
ryder1912
Mensajes: 29
Registrado: Jue Jul 09, 2015 8:17 pm

Re: Integracion LaPOS+Cargar DLL

Mensaje por ryder1912 »

Buenas pude avanzar en algo, pero nose como seguir. Cambie el codigo pero
Me tira error, ya que no se como enviar el struct como argumento y que devuelva algo en el Result.
Cualquier sugerencia,y/o ayuda, gracias. Saludos.

Código: Seleccionar todo

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

typedef struct
{
     char *com;
     unsigned short baudRate;
     unsigned short byteSize;
     char parity;
     unsigned short stopBits;

} ComParams_t;
 
typedef unsigned short ( __stdcall *__vpiOpenPort)(ComParams_t Param);
 
static HINSTANCE  hLib = NULL;

HB_FUNC( OPENPORTPAYWAY )
{
   unsigned short result ;
   ComParams_t *ConfParam;
   static __vpiOpenPort pFunction = NULL;

   ConfParam->com="COM4";
   ConfParam->baudRate=19200 ;
   ConfParam->byteSize=8 ;
   ConfParam->parity='N' ;
   ConfParam->stopBits=1 ;

   if( !hLib )
      hLib = LoadLibrary( "VpiPc.dll" );

   if( hLib )
   {
      if( !pFunction )
         pFunction = (__vpiOpenPort)GetProcAddress( hLib, "vpiOpenPort");
   }

   if( pFunction )
      result = (pFunction)( hb_parni( 1 ), hb_parni( 2 ), hb_parni( 3 ), hb_parni( 4 ) , hb_parni( 5 ) ); // Aqui me tira error, supongo que espera el struct como argumento pero como lo envio?????
   else
      result = -2000;

   hb_retni(result);
}

#pragma ENDDUMP
ryder1912
Mensajes: 29
Registrado: Jue Jul 09, 2015 8:17 pm

Re: Integracion LaPOS+Cargar DLL

Mensaje por ryder1912 »

Buenas, alguien que me pueda dar una mano? Tira error incompatible type for argument 1 of 'pFunction' y una advertencia.
Como puedo enviar los datos de conexión para abrir el puerto?

Compilando Funciones_C.prg...
C:\Proyects Xailer\Proyectos Xailer\sistema_Payway_C\Source\Funciones_C.prg:59:29: error: incompatible type for argument 1 of 'pFunction'
C:Proyects Xailer\Proyectos Xailer\sistema_Payway_C\Source\Funciones_C.prg:59:29: note: expected 'ComParams_t {aka struct <anonymous>}' but argument is of type 'ComParams_t * {aka struct <anonymous> *}'

Desde ya, gracias.

Código: Seleccionar todo

#pragma BEGINDUMP

#include "windows.h"
#include "hbapi.h"

typedef struct
{
     char *com;
     unsigned short baudRate;
     unsigned short byteSize;
     char parity;
     unsigned short stopBits;

} ComParams_t;

typedef unsigned short ( __stdcall *__vpiOpenPort)(ComParams_t Param );
 
static HINSTANCE  hLib = NULL;
 
HB_FUNC( OPENPORTPAYWAY )
{
   unsigned short result ;
   ComParams_t *ConfParam ;//= malloc(sizeof(struct ComParams_t));

   static __vpiOpenPort pFunction = NULL;

   ConfParam->com="COM5";
   ConfParam->baudRate=19200 ;
   ConfParam->byteSize=8;
   ConfParam->parity='N';
   ConfParam->stopBits=1;

   if( !hLib )
      hLib = LoadLibrary( "VpiPc.dll" );

   if( hLib )
   {
      if( !pFunction )
         pFunction = (__vpiOpenPort)GetProcAddress( hLib, "vpiOpenPort");
   }

   if( pFunction )
      result = (pFunction)( ConfParam );
   else
      result = -2000;

   hb_retni(result);
}
#pragma ENDDUMP

Responder