//---------------------------------------------------------------------------
#ifndef PcScaleH
#define PcScaleH
//---------------------------------------------------------------------------
/****************************************************************************
*                                                                           *
* PcScale.h - procedure declarations, constant definitions					*
*                                                                           *
* Copyright (c) 1998, Filizola All rights reserved.             			*
*                                                                           *
****************************************************************************/

#define SOH 0x01
#define EOT 0x04
#define STX 0x02
#define ETX 0x03
#define ACK 0x06
#define NAK 0x15
#define DLE 0x10

// Return errors definitions

#define	ScaleError	        0
#define	ScaleInMotion	    1
#define	ScaleStable	        2
#define	ScaleOutOfRange	    3
#define	ProteqNotFound      4

#define	dfnBalancaErro              0
#define	dfnPesoOscilando            1
#define	dfnPesoEstavel              2
#define	dfnBalancaForaRange	        3
#define	dfnLicencaNaoEncontrada     4

#define	dfnErro -99999

// Indicators type definitions

#define	BIDS		        0
#define	BIQP810		        1
#define	B9091		        2
#define	B8132		        3
#define	BID10000	        4
#define	BBP		            5
#define	BMF		            6
#define	BIDC		        7
#define	BE  		        8
#define	BCS  		        9
//* 4.0.10 - Será o mesmo que a CS
#define BPLURIS             9
//*
#define BIDM                10
#define BIDU                11
#define BTRU_TEST_SR2000    12
#define BCI                 13
//4.0.1.2
#define BMICHELETTI_C       14
#define BMICHELETTI_I       15
#define BALFA3102           16
//*
//*4.0.0.14
#define SATURNOSB5000S2     17
//*
#define BWT300              18 //4.0.1.5

#define BFLEXARLR22         19 //4.0.1.9

//* 4.0.2.2
#define BALFA3101           20
//*



#define sizeofweight  9     //The sizes are compose for buffer + null terminator
#define sizeofunit    3
#define sizeofqtd     6
#define sizeofcod     7
#define sizeofvalue   7
#define sizeofdate    7

typedef struct _PcscaleVars {
    char bruto[sizeofweight];
    char tara[sizeofweight];
    char liquido[sizeofweight];
    char unidade[sizeofunit];
    char quantidade[sizeofqtd];
    char codigo[sizeofcod];
    char vunitario[sizeofvalue];
    char vtotal[sizeofvalue];
    char pmedio[sizeofweight];
    char datafab[sizeofdate];
    char dataval[sizeofdate];
} PcScaleVars;

extern int GlobalCom;

#ifdef DLLCODE
    #define	PCSCALEAPI	WINAPI _export
    #define	PCSCALECALL
#else
    #define	PCSCALEAPI WINAPI
    #define	PCSCALECALL extern
#endif

/*
------------------------------------------------------------------------
ReadScale: function to read a Filizola buffer trasmited for scales

Return : error

input:
hScale		Point to comunication device
Com 			Port number 1,2,3 ou 4
BaudRate		2400,4800,9600,14400...
ByteSize		5,6,7 or 8
StopBits		0=1 1=1,5 2=2
Parity			0=none 1=odd 2=even 3=mark 4=space
Indicator		BIDS,BIQP810,B9091,B8132,BID10000,BBP
gross			buffer to return gross
tare			buffer to return tare
net				buffer to return net
unitd			buffer to return unit
------------------------------------------------------------------------
*/

extern "C" {

// Rotinas antigas para leitura da balança / indicadores
PCSCALECALL int	PCSCALEAPI AttachScale(
	HANDLE	*hCom,
    int 	Com,
    int 	BaudRate,
    int 	ByteSize,
    int 	StopBits,
    int 	Parity
    );
PCSCALECALL void PCSCALEAPI DettachScale(HANDLE *hCom);

PCSCALECALL int PCSCALEAPI ReadScale(
	HANDLE	*hCom,
    int 	Indicator,
    char	*gross,
    char	*tare,
    char	*net,
    char	*unitd
    );

PCSCALECALL int PCSCALEAPI ReadIDM(
    HANDLE *hCom,
    char far *gross,
    char far *tare,
    char far *net,
    char far *cont,
    char far *cod);

PCSCALECALL int PCSCALEAPI ReadCS(
	HANDLE	*hCom,
    char	*peso,
    char	*vunit,
    char	*vtotal,
    char	*codigo
    );

PCSCALECALL int PCSCALEAPI ReadCI(
    HANDLE *hCom,
    char far *gross,
    char far *tare,
    char far *net,
    char far *qtd,
    char far *cod,
    char far *pmed,
    char far *dfab,
    char far *dval
    );

PCSCALECALL int PCSCALEAPI WriteCS(
	HANDLE	*hCom,
    char	*vunit
    );

// Rotinas auxiliares para obter as balanças/indicadores contemplados pelo PcScale
PCSCALECALL int PCSCALEAPI GetScaleRecordCount(void);
PCSCALECALL void PCSCALEAPI ObtemNomeBalanca(int Modelo, char *Nome);

// Rotina de exibição de mensagem de erro na chamada das funções;
PCSCALECALL void PCSCALEAPI ExibeMsgErro(HWND Aplicativo);

// rotinas para configuração da balanca
PCSCALECALL bool PCSCALEAPI ConfiguraBalanca(int balanca,HWND Aplicativo);

PCSCALECALL bool PCSCALEAPI SalvaParametrosBalancaEthernet(
    int balanca,
    int Modelo,
    int Porta,
    int BaudRate,
    int Tipo,
    char *IP,
    int Port
    );

PCSCALECALL bool PCSCALEAPI SalvaParametrosBalanca(
    int balanca,
    int Modelo,
    int Porta,
    int BaudRate
    );


PCSCALECALL bool PCSCALEAPI ObtemParametrosBalanca(
    int balanca,
    int &Modelo,
    int &Porta,
    int &BaudRate
    );


PCSCALECALL bool PCSCALEAPI ObtemParametrosBalancaEthernet(
    int balanca,
    int &Modelo,
    int &Porta,
    int &BaudRate,
    int &Tipo,
    char *IP,
    int &Port
    );


// Novas Rotinas para leitura da balança
PCSCALECALL bool PCSCALEAPI InicializaLeitura(int balanca);
PCSCALECALL bool PCSCALEAPI FinalizaLeitura(int balanca);
PCSCALECALL double PCSCALEAPI ObtemInformacao(int balanca,int campo);

// Rotina para envio do preço/kg para a CS
PCSCALECALL bool PCSCALEAPI EnviaPrecoCS(int balanca,double preco);

// Rotina para verificar se a porta selecionada está também em outra balança
PCSCALECALL bool PCSCALEAPI PortaJaExiste(int Porta, int Balanca);

// Rotina que retorna a mesagem de erro
PCSCALECALL void PCSCALEAPI ObtemMsgErro(char *mensagem);
};

#endif
