ayuda con sdk de ThermalServiceLibrary

ayuda con sdk de ThermalServiceLibrary

Postby carlos vargas » Wed Oct 12, 2011 11:39 pm

Estimados, he desarrollado esto, al compilarlo todo ok.
pero al ejecutarlo da gpf, aparte tengo una duda, con respecto a
aparte, de que si el enfoque de programacion y la tecnica es la correcta, son mis primeros pinitos en esto.
a esos guru de c con harbour, please una ayudita.
gracias.-

...
#define tEXTERNAL_NUMERIC unsigned long /*POR QUE ACA*/
...
typedef struct
{
tTYPE_TRANSL_FUNC TypeTranslFuncPtr;
LPVOID ParamValuePtr;
} tEXTERNAL_NUMERIC; /*SI YA ESTA ACA*/




Code: Select all  Expand view  RUN

PROCEDURE Main()
   ?"Begin Test..."
   ?"Open Port...:", MYTSL_PortOpen( "COM1", 9600 )
   ?"Lines.......:", MYTSL_LBTRSHDR(1)  
   ?"N/D.........:", MYTSL_LBTRSLN( { 1, 1, "Not Defined", 2, "A", 10.5, 21, 0 } )
   ?"Close Port..:", MYTSL_PortClose()
RETURN
   
#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"
#include "hbapiitm.h"

#define BYTE unsigned char
#define tEXTERNAL_NUMERIC unsigned long              

#define SOK         0
#define SERROR     -1
#define DLL_NAME    "thermalservicelibrary.dll"

typedef int ( *tTYPE_TRANSL_FUNC )( LPVOID, char * );

typedef struct
{
   tTYPE_TRANSL_FUNC TypeTranslFuncPtr;
   LPVOID            ParamValuePtr;
} tEXTERNAL_NUMERIC;                                

typedef struct
{
   BYTE                   Pi;
   BYTE                   Pr;
   char *                 Name;
   tEXTERNAL_NUMERIC      Quantity;
   char                   Vat;
   tEXTERNAL_NUMERIC      Price;
   tEXTERNAL_NUMERIC      Gross;
   tEXTERNAL_NUMERIC      Discount;
} tLBTRSLN_PARAMS;

HINSTANCE hDllHandle = 0;

typedef LONG (WINAPI *TSL_OPEN)(LPSTR szComPuerto, USHORT usBaudRate);
typedef LONG (WINAPI *TSL_CLOSE)(VOID);
typedef LONG (WINAPI *TSL_LBTRSHDR)(USHORT usNumLine);
typedef LONG (WINAPI *TSL_LBTREXITCAN)(LPSTR szParam1, LPSTR szParam2);
typedef LONG (WINAPI *TSL_LBTRSLN)(tLBTRSLN_PARAMS aSLN_Par);
typedef LONG (WINAPI *TSL_LBCASREP)(VOID);
                       
HB_FUNC( MYTSL_PORTOPEN )
{
   LPSTR  szComPort  = (char *) hb_parc( 1  );
   USHORT usBaudRate = hb_parni( 2 );
   SHORT sReturn;
   
   hDllHandle = LoadLibrary( DLL_NAME );
   
   if( hDllHandle )
   {
      TSL_OPEN pFunc = (TSL_OPEN) GetProcAddress( hDllHandle, "p_Port_Open" );
      if( pFunc )
      {        
         sReturn = pFunc( szComPort, usBaudRate );
         
         if( sReturn == SERROR )
         {
            FreeLibrary( hDllHandle );        
         }        
         hb_retni( sReturn );
         return;
      }      
   }  
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_PORTCLOSE )
{
   if( hDllHandle )
   {
      TSL_CLOSE pFunc = (TSL_CLOSE) GetProcAddress( hDllHandle, "p_Port_Close" );
      if( pFunc )
      {
         hb_retni( pFunc() );
         FreeLibrary( hDllHandle );            
         return;
      }
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBTRSHDR )
{  
   USHORT usNumLine = (SHORT) hb_parni( 1 );
   
   if( hDllHandle )
   {
      if( usNumLine >= 1 && usNumLine <= 80 )
      {        
         TSL_LBTRSHDR pFunc = (TSL_LBTRSHDR) GetProcAddress( hDllHandle, "p_LBTRSHDR" );
         if( pFunc )
         {
            hb_retni( pFunc( usNumLine ) );      
            return;
         }
      }        
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBTREXITCAN )
{
   LPSTR szParam1 = (char *) hb_parc(1);  
   LPSTR szParam2 = (char *) hb_parc(2);      

   if( hDllHandle )
   {
      TSL_LBTREXITCAN pFunc = (TSL_LBTREXITCAN) GetProcAddress( hDllHandle, "p_LBTREXITCAN" );
      if( pFunc )
      {
         hb_retni( pFunc( szParam1, szParam2 ) );      
         return;
      }    
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBTRSLN )
{

   tLBTRSLN_PARAMS aSLN_Par;
   
   aSLN_Par.Pi       = (BYTE)                    hb_parvni( 1, 1 );
   aSLN_Par.Pr       = (BYTE)                    hb_parvni( 1, 2 );
   aSLN_Par.Name     = (LPSTR)             hb_parvc(  1, 3 );
   aSLN_Par.Quantity = (tEXTERNAL_NUMERIC) hb_parvnd( 1, 4 );
   aSLN_Par.Vat      = (char)              hb_parvc( 1, 5 );
   aSLN_Par.Price    = (tEXTERNAL_NUMERIC) hb_parvnd( 1, 6 );
   aSLN_Par.Gross    = (tEXTERNAL_NUMERIC) hb_parvnd( 1, 7 );
   aSLN_Par.Discount = (tEXTERNAL_NUMERIC) hb_parvnd( 1, 8 );
   
   if( hDllHandle )
   {
      TSL_LBTRSLN pFunc = (TSL_LBTRSLN) GetProcAddress( hDllHandle, "p_LBTRSLN" );
      if( pFunc )
      {
         hb_retni( pFunc( aSLN_Par ) );      
         return;
      }        
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBCASREP )
{
   if( hDllHandle )
   {
      TSL_LBCASREP pFunc = (TSL_LBCASREP) GetProcAddress( hDllHandle, "p_LBCASREP" );
      if( pFunc )
      {
         hb_retni( pFunc() );
         return;
      }      
   }
   hb_retni( SERROR );
}

#pragma ENDDUMP
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: ayuda con sdk de ThermalServiceLibrary

Postby carlos vargas » Thu Oct 13, 2011 9:18 pm

he estado ayudando a un nuevo programador que se une a harbour, este es un pos dejado en los grupos de harbour donde pide ayuda
I'm writing to you on behalf of my father Antoni Jablonski, who is
Clipper programmer, and has been writing his own accounting /
warehousing applications in it since early 90-ies. Nowadays he needs
to switch to harbour / harbour extended minigui (with very poor
knowledge of both) because Windows 7 apparently doesn't support 16
bits applications. his English is not good enough, and asked me for
help.

So this is a little background. My father tries to invoke from harbour
code the third party dll library of fiscal printer manufacturer  and
he hits the wall. We've tried different Harbour miniGui extended
samples and we're able to successfully pass one command from this
library and printer prints it but then it looks like the response is
not passed / handled (the execution return value is not passed to the
program) and it hangs waiting for the response. Then some Windows
message bos appeares asking if it should retry, keep waiting or
cancel.
We use LoadLibrary and FreeLibrary and DECLARE DLL_TYPE... code
(please find the below code for reference ) -  or DLLCall xHabour
method and programm still hangs waiting.


Hence my question - do you have any ideas why is that ? Any
suggestions how properly DLL functions should be invoked ? The library
could be downloaded from the following address:
http://www.posnet.com.pl/files/2915/The ... 201.10.zip
(ThermalServiceLibrary.dll).


Me and my father are not C/C++ programmers, and just starting to learn
Harbour.
Below is one of the approchaes based on sample \MiniGUI\SAMPLES
\Advanced\RMChart_dll.  If you'll find time to look into this and
suggest something, it would be great:


****************************************************************************
#include "minigui.ch"
#include "dll32.ch"


Static hInstDLL
*************
Function main()
*************
local f_Com       := "COM2"
local f_BaudRate  := 9600
local BlOK        :=0
local Lines       :=3
*local err_code    :=0
local NrKasy       :="A1"
local Kasjer       :="01"
priv err_code     := -1000
hInstDLL := LoadLibrary('ThermalServiceLibrary.DLL')


@ 0,0 clear
err_code := PortOpen(f_Com,f_BaudRate)
if err_code=BlOK
   ? 'Port opended'
else
   ? err_code
endif
err_code := WysuwLinii(Lines)
*err_code := Lbdsp(ps)
err_code := StanKasy(NrKasy,Kasjer)
?
? err_code
Port_Close()
? 'Port closed'
FreeLibrary(hInstDLL)
?
?
? 'Press a key...'
inkey(0)
return .t.


*--------------------------------------------------------------------------
---
*
DECLARE DLL_TYPE_INT Port_Open( DLL_TYPE_LPSTR port, DLL_TYPE_DWORD
Rate ) ;
ALIAS PortOpen IN hInstDLL
*-----------------------------------------------------------------------------
*
DECLARE DLL_TYPE_VOID ;
Port_Close() ;
IN hInstDLL
*-----------------------------------------------------------------------------
*
DECLARE DLL_TYPE_INT ;
  LBFEED( DLL_TYPE_BYTE Lines ) ;
ALIAS WysuwLinii IN hInstDLL
*-----------------------------------------------------------------------------
*
*-----------------------------------------------------------------------------
*
DECLARE DLL_TYPE_INT ;
  LBCSHSTS( DLL_TYPE_LPSTR Kasa,DLL_TYPE_LPSTR Kasjer ) ;
ALIAS StanKasy IN hInstDLL
*--------------------------------------------------------------------------




--
Pawel Jablonski

Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: ayuda con sdk de ThermalServiceLibrary

Postby carlos vargas » Thu Oct 13, 2011 9:22 pm

en esta version, he implementado algunas funciones, he eliminado el gpf de la funcion MYTSL_LBTRSLN
pero al fallar me retorna un error muy grande, cuando en caso de error esta hasta -60, actualmente me retona valores -1073741822 el cual no es valido.
si alguien me ayuda a ayudra, muy agradecido.

salu2


Code: Select all  Expand view  RUN

PROCEDURE Main()
   ?"Begin Test......"
   ?"Open Port......:", MYTSL_PortOpen( "COM1", 9600 )  
   ?"Printer status.:", MYTSL_PRINTSTATUS()  
   ?"Cash status....:", MYTSL_CASHREGISTERSTATUS()
   ?"Lines..........:", MYTSL_LBTRSHDR(1)  
   ?"Feed Lines.....:", MYTSL_LBFEED(2)
   ?"N/D............:", MYTSL_LBTRSLN( { 1, 1, "Not Defined", "2", "A", "10.5", "21", "0" } )
   ?"Close Port.....:", MYTSL_PortClose()
RETURN
   
#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"
#include "hbapiitm.h"

#define BYTE unsigned char        

#define SOK               0
#define SERROR            -1
#define ERR_UNKNOWN_CMD   -27
#define DLL_NAME          "thermalservicelibrary.dll"

typedef int ( *tTYPE_TRANSL_FUNC )( LPVOID, char * );

typedef struct
{
   tTYPE_TRANSL_FUNC TypeTranslFuncPtr;
   LPVOID            ParamValuePtr;
} tEXTERNAL_NUMERIC;                                

typedef struct
{
   BYTE                   Pi;
   BYTE                   Pr;
   char *                 Name;
   tEXTERNAL_NUMERIC      Quantity;
   char                   Vat;
   tEXTERNAL_NUMERIC      Price;
   tEXTERNAL_NUMERIC      Gross;
   tEXTERNAL_NUMERIC      Discount;
} tLBTRSLN_PARAMS;

typedef struct
{
   BYTE      Ps;
} tLBFEED_PARAMS;

typedef struct
{
   BOOL ONL;
   BOOL PE;
   BOOL ERR;
} tPRINTER_STATUS;

typedef struct
{
   BOOL   FSK;
   BOOL   CMD;
   BOOL   PAR;
   BOOL   TRF;
} tCASH_REGISTER_STATUS;

HINSTANCE hDllHandle = 0;

typedef LONG (WINAPI *TSL_OPEN)                  ( LPSTR, USHORT );
typedef LONG (WINAPI *TSL_CLOSE)                 ( VOID );
typedef LONG (WINAPI *TSL_LBTRSHDR)              ( BYTE );
typedef LONG (WINAPI *TSL_LBFEED)                ( tLBFEED_PARAMS );
typedef LONG (WINAPI *TSL_LBTREXITCAN)           ( char *, char * );
typedef LONG (WINAPI *TSL_LBTRSLN)               ( tLBTRSLN_PARAMS * );
typedef LONG (WINAPI *TSL_LBCASREP)              ( VOID );
typedef LONG (WINAPI *TSL_GETSTATUSPRINTER)      ( tPRINTER_STATUS * );
typedef LONG (WINAPI *TSL_GETSTATUSCASHREGISTER) ( tCASH_REGISTER_STATUS * );

/*typedef int      ( *tTHSL_LBTRSHDR )                   ( BYTE );*/
/*typedef int      ( *tTHSL_LBFEED )                     ( BYTE );*/
/*typedef int      ( *tTHSL_LBTREXITCAN )                ( char *, char * );*/
/*typedef int      ( *tTHSL_LBTRSLN )                    ( tLBTRSLN_PARAMS * );*/
/*typedef int      ( *tTHSL_O_LBTRSLN )                  ( tLBTRSLN_PARAMS * );*/
/*typedef int      ( *tTHSL_LBCASREP )                   ();*/
/*typedef int      ( *tTHSL_GET_STATUS_CASH_REGISTER )   ( tCASH_REGISTER_STATUS * );*/
/*typedef int      ( *tTHSL_GET_STATUS_PRINTER )         ( tPRINTER_STATUS * );*/



HB_FUNC( MYTSL_PORTOPEN )
{
   LPSTR  szComPort  = (char *) hb_parc( 1  );
   USHORT usBaudRate = hb_parni( 2 );
   SHORT sReturn;
   
   hDllHandle = LoadLibrary( DLL_NAME );
   
   if( hDllHandle )
   {
      TSL_OPEN pFunc = (TSL_OPEN) GetProcAddress( hDllHandle, "p_Port_Open" );
      if( pFunc )
      {        
         sReturn = pFunc( szComPort, usBaudRate );
         
         if( sReturn == SERROR )
         {
            FreeLibrary( hDllHandle );        
         }        
         hb_retni( sReturn );
         return;
      }      
   }  
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_PORTCLOSE )
{
   if( hDllHandle )
   {
      TSL_CLOSE pFunc = (TSL_CLOSE) GetProcAddress( hDllHandle, "p_Port_Close" );
      if( pFunc )
      {
         hb_retni( pFunc() );
         FreeLibrary( hDllHandle );            
         return;
      }
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBTRSHDR )
{  
   BYTE bNumLine = (BYTE) hb_parni( 1 );
   
   if( hDllHandle )
   {
      if( bNumLine >= 1 && bNumLine <= 80 )
      {        
         TSL_LBTRSHDR pFunc = (TSL_LBTRSHDR) GetProcAddress( hDllHandle, "p_LBTRSHDR" );
         if( pFunc )
         {
            hb_retni( pFunc( bNumLine ) );      
            return;
         }
      }        
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBTREXITCAN )
{
   LPSTR szParam1 = (LPSTR) hb_parc( 1 );  
   LPSTR szParam2 = (LPSTR) hb_parc( 2 );      

   if( hDllHandle )
   {
      TSL_LBTREXITCAN pFunc = (TSL_LBTREXITCAN) GetProcAddress( hDllHandle, "p_LBTREXITCAN" );
      if( pFunc )
      {
         hb_retni( pFunc( szParam1, szParam2 ) );      
         return;
      }    
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBTRSLN )
{
   tEXTERNAL_NUMERIC tQ, tP, tG, tD;
   tLBTRSLN_PARAMS aSLN_Par;  

   tQ.TypeTranslFuncPtr = NULL;
   tQ.ParamValuePtr     = hb_parvc( 1, 4) ;
   tP.TypeTranslFuncPtr = NULL;  
   tP.ParamValuePtr     = hb_parvc( 1, 6) ;
   tG.TypeTranslFuncPtr = NULL;  
   tG.ParamValuePtr     = hb_parvc( 1, 7) ;
   tD.TypeTranslFuncPtr = NULL;  
   tD.ParamValuePtr     = hb_parvc( 1, 8) ;  
   
   aSLN_Par.Pi           = (BYTE)  hb_parvni( 1, 1 );
   aSLN_Par.Pr           = (BYTE)  hb_parvni( 1, 2 );
   aSLN_Par.Name         = (LPSTR) hb_parvc( 1, 3 );
   aSLN_Par.Vat          = (char)  hb_parvc( 1, 5 );  
   aSLN_Par.Quantity     = tQ;    
   aSLN_Par.Price        = tP;
   aSLN_Par.Gross        = tG;
   aSLN_Par.Discount     = tD;
   
   if( hDllHandle )
   {
      TSL_LBTRSLN pFunc = (TSL_LBTRSLN) GetProcAddress( hDllHandle, "p_LBTRSLN" );
      if( pFunc )
      {
         hb_retni( pFunc( &aSLN_Par ) );
         return;
      }        
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBCASREP )
{
   if( hDllHandle )
   {
      TSL_LBCASREP pFunc = (TSL_LBCASREP) GetProcAddress( hDllHandle, "p_LBCASREP" );
      if( pFunc )
      {
         hb_retni( pFunc() );
         return;
      }      
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_LBFEED )
{
   tLBFEED_PARAMS tFeed;
   tFeed.Ps = (SHORT) hb_parni( 1 );

   if( hDllHandle )
   {
      TSL_LBFEED pFunc = (TSL_LBFEED) GetProcAddress( hDllHandle, "p_LBFEED" );
      if( pFunc )
      {
         hb_retni( pFunc( tFeed ) );
         return;
      }      
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_PRINTSTATUS )
{
   tPRINTER_STATUS tPrintStatus;
   int iReturnFunc;
   BYTE bResponse;
   
   if( hDllHandle )
   {
      TSL_GETSTATUSPRINTER pFunc = (TSL_GETSTATUSPRINTER) GetProcAddress( hDllHandle, "p_GetStatus_Printer" );
      if( pFunc )
      {
         iReturnFunc = pFunc( &tPrintStatus );
         if( iReturnFunc == SOK )
         {
            bResponse = 0x70 + ( tPrintStatus.ONL  ? 0x04 : 0 ) +
                               ( tPrintStatus.PE   ? 0x02 : 0 ) +
                               ( tPrintStatus.ERR  ? 0x01 : 0 ) ;
            hb_retni( bResponse );
         }
         else
         {
            hb_retni( 255 );
         }
         return;      
      }
   }
   hb_retni( SERROR );
}

HB_FUNC( MYTSL_CASHREGISTERSTATUS )
{
   tCASH_REGISTER_STATUS tCashRegisterStatus;  
   
   if( hDllHandle )
   {
      TSL_GETSTATUSCASHREGISTER pFunc = (TSL_GETSTATUSCASHREGISTER) GetProcAddress( hDllHandle, "p_GetStatus_CashRegister" );
      if( pFunc )
      {
         pFunc( &tCashRegisterStatus );
         if( !tCashRegisterStatus.CMD )
         {
            hb_retni( ERR_UNKNOWN_CMD );
         }
      }
   }
   hb_retni( SERROR );  
}

#pragma ENDDUMP
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: ayuda con sdk de ThermalServiceLibrary

Postby Daniel Garcia-Gil » Thu Oct 13, 2011 9:46 pm

Hola

las funciones estan declaradas para retornar un valor LONG pero estas retornando un enetero, hb_retni usa hb_retnl

prueba y comenta
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ayuda con sdk de ThermalServiceLibrary

Postby carlos vargas » Thu Oct 13, 2011 10:16 pm

ok, gracias daniel por tu indicacion.-

aca tengo una duda existencia. :-)

recuerda que son mis primeros pinitos al c.

se que las funciones segun la documentación retornan un entero, pero le puse long,
por me creia que que GetProcAddres retorna la direccion de la funcion en al dll y que esa direccion es
long, por lo que no se si aca typedef long es para el retorno de la funcion en si o del retorno de GetProcAddres.


salu2
Code: Select all  Expand view  RUN

...
typedef LONG (WINAPI *TSL_OPEN)                  ( LPSTR, USHORT );
...
TSL_OPEN pFunc = (TSL_OPEN) GetProcAddress( hDllHandle, "p_Port_Open" );
 
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua

Re: ayuda con sdk de ThermalServiceLibrary

Postby Daniel Garcia-Gil » Fri Oct 14, 2011 2:26 am

Hola

Code: Select all  Expand view  RUN
...
typedef LONG (WINAPI *TSL_OPEN)                  ( LPSTR, USHORT );
...
TSL_OPEN pFunc = (TSL_OPEN) GetProcAddress( hDllHandle, "p_Port_Open" );


el puntero a la funcion lo defines en la parte del prototipo (WINAPI *TSL_OPEN) ( LPSTR, USHORT ) que devolvera un LONG

es decir GetProcAddress te devolvera un puntero a una funcion que la almacena en pFunc y cuando llamas a esa funcion por el puntero devuelve un LONG
pFunc( szComPort, usBaudRate );
User avatar
Daniel Garcia-Gil
 
Posts: 2365
Joined: Wed Nov 02, 2005 11:46 pm
Location: Isla de Margarita

Re: ayuda con sdk de ThermalServiceLibrary

Postby carlos vargas » Fri Oct 14, 2011 9:07 pm

gracia Daniel, como siempre claro y oportuno. :-)

salu2
carlos vargas
Salu2
Carlos Vargas
Desde Managua, Nicaragua (CA)
User avatar
carlos vargas
 
Posts: 1721
Joined: Tue Oct 11, 2005 5:01 pm
Location: Nicaragua


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 56 guests