PDA

View Full Version : General Advice



KillGabio
1st February 2012, 17:48
Hi guys, im facing what i think is going to be my biggest problem. I need to stablish a communication with a Fiscal Printer. For that i have the following files downloaded from the official website of the printer:

winfis32.bas
winfis32.dll
Winfis.h
winfis.lib


To my surprise the header file included throws some extrange error when trying to compile: the sentence FAR PASCAL is not recognised. So i looked what was this and as I read is an old convention to especify parameters and size of pointers. (Precise and concise information here: http://stackoverflow.com/questions/2774171/what-is-far-pascal).

My question is: do i need to delete that part of the code?

The drivers also include a way to communicate via OCX but as shown in the examples of the drivers documentation is recommended to use them when programming with Visual Basic. Should i change and work with OCX?

here is the code of the header:


#ifndef _WINFIS_H
#define _WINFIS_H

#ifdef __cplusplus
extern "C" {
#endif

#define VERSION 427

#ifdef WIN32
#define _export
typedef void (*PFV)(int Reason, int Port);
typedef void (__stdcall *PFVSTDCALL)(int Reason, int Port);
#endif

int FAR PASCAL _export OpenComFiscal (int Com, int Mode);

int FAR PASCAL _export OpenTcpFiscal (char *HostName, int Socket, long TimeoutMilisecs, int Mode);
#ifdef WIN32
int FAR PASCAL _export ReOpenComFiscal (int Com);
#endif

void FAR PASCAL _export CloseComFiscal (int Handler);
int FAR PASCAL _export MandaPaqueteFiscal (int Handler, char *Buffer);
int FAR PASCAL _export UltimaRespuesta (int Handler, char *Buffer);
int FAR PASCAL _export UltimoStatus (int Handler, short *FiscalStatus,
short *PrinterStatus);
int FAR PASCAL _export VersionDLLFiscal (void);
int FAR PASCAL _export InitFiscal (int Handler);
void FAR PASCAL _export BusyWaitingMode (int Mode);
int FAR PASCAL _export CambiarVelocidad(int Handler, long NewSpeed);
void FAR PASCAL _export ProtocolMode(int Mode);
long FAR PASCAL _export SearchPrn (int Handler);

int FAR PASCAL _export ObtenerNumeroDePaquetes (int Handler,
int *Enviado, int *Recibido,
int *CmdRecibido);
#ifdef WIN32
void FAR PASCAL _export SetKeepAliveHandler(PFV Handler);
void FAR PASCAL _export SetKeepAliveHandlerStdCall(PFVSTDCALL Handler);
void FAR PASCAL _export Abort(int Handler);
#endif

int FAR PASCAL _export SetCmdRetries (int Retries);
int FAR PASCAL _export SetSndRetries (int Retries);
int FAR PASCAL _export SetRcvRetries (int Retries);

int FAR PASCAL _export SetModoEpson (int Modo);

#define SIZEANSWER 1024

#define MODE_ASCII 0
#define MODE_ANSI 1

#define BUSYWAITING_OFF 0
#define BUSYWAITING_ON 1

#define OLD_PROTOCOL 0
#define NEW_PROTOCOL 1

#ifdef __cplusplus
}
#endif


#endif // _WINFIS_H

ChrisW67
1st February 2012, 23:18
Try:


#include <windows.h>
#include "Winfis.h"

in your source.

You may find you have to use the OCX if you are using MingW and cannot link directly against the DLL.

KillGabio
2nd February 2012, 00:30
OMG i just added that and functions ""perfectly"". I can`t really tell because I dont have the fiscal printer so when i do i ll keep you posted cause im going to need some help. Still im trying to learn and i wanna know more about the OCX... it`s like a cpp that connects the dll with the header? cause I read that the OCX contains functions that help me program, for example:

if i only had the winfis.dll i would have to call like 10 functions to print a ticket, but with the OCX i just call print and it just know what to do with the .dll

as far as i could understand lol

ChrisW67
2nd February 2012, 02:12
C code produces libraries with simple names and interfaces that can generally be accessed without great difficulty from any language. This appears to apply to your DLL based on the 'extern "C"' in the header.

C++ code produces libraries with the class and method names mangled in a compiler specific fashion. The result is that libraries contain C++ classes etc. can only be directly used by code built with the same compiler. The DLL you have was built with a Microsoft compiler (educated guess) so, if it were a C++ library, you could not use it from a MingW program.

A OCX file is a dynamic library that provides binary interfaces and mechanisms to access its "objects" in a compiler/language independent fashion. Look up "Common Object Model" (COM). You would access this code using ActiveQt but you need a reasonable grasp of COM to understand what is going on. OCX files were the easiest way to extend classic Visual Basic programs, which is why they recommend it.

KillGabio
2nd February 2012, 03:11
In the documentation of the program (I guess you dont talk Spanish thats why I`m not giving you the web site) says it`s for C language, that meaning I can use that DLL, right? I tried to use some functions but as the fiscal printer is not initialized cause I dont physically have it for now, I can only see that the method OpenComFiscal return a zero (0) indicating that the printer couldnt be initialized. That all said, I really hope it means i can interact with the fiscal controller...if not, well I`ll start to cry and learn some COM (actually im googling it right now).

ChrisW67
2nd February 2012, 03:13
If you can compile and link a program against this library then I think you will be fine.

KillGabio
2nd February 2012, 03:15
I found it has an English version of the web site but in that mode it doesnt allow you to download the drivers of the printer...if you want to have a look:
http://www.grupohasar.com/en/product/hardware/printers/fiscal/hasar-p-715f

greetings tutor :P