Página 1 de 1

Leitura de peso - clipper para xharbour

Enviado: 17 Mar 2009 17:17
por TerraSoftware
Caros colegas, tenho uma funcao em clipper com ctp.lib que faz a leitura de peso de balança, funciona certinho. Agora preciso portar para xharbour, e nao manjo muito da hbcomm.lib, os amigos poderiam me ajudar?

Preciso de uma funcao em xharbour que faça a mesma coisa que a funcao em clipper esta fazendo.
Segue a funcao em clipper:

Código: Selecionar todos

*******************
Function Ler_Peso() 
*******************
Local nPorta := 1 
Local cTrans := "N" 
Local nBits := 8 
Local nParad := 1 
Local nVeloc := 2400 
Local cInicia:= Chr(05)
Local Erro := .F. 
Local VlrPeso:= 0 
Local nRetorn:= .T. 
If Com_Open(nPorta,1000,1000) == .t. 
   nConf := Com_Init(nPorta,nVeloc,cTrans,nBits,nParad) 
   Com_Send(nPorta,cInicia) 
   Inkey(0.10) 
   Com_Count(nPorta) 
   Inkey(0.10) 
   nLeitura := Com_read(nPorta,10) 
   If Substr(nLeitura,1,1)== Chr(02) .And. Right(AllTrim(nLeitura),1)==Chr(03)
      alert(nleitura)
   Endif 
   Com_Close(nPorta) 
Endif 
Return (.T.)

Re: Leitura de peso - clipper para xharbour

Enviado: 17 Mar 2009 17:40
por DLZ
Cara..
Já que vc migrou para Xharbour, usa a DLL do fabricante da balança... é muito mais fácil !!
Eu já fiz isso com balanças PDV da Toledo.. não sei se é o teu caso, mas se não for é só entrar no site do fabricante e pegar a DLL e a documentação dela...
Um abraço

Re: Leitura de peso - clipper para xharbour

Enviado: 17 Mar 2009 21:00
por TerraSoftware
Caro colega DLZ, é justamente isso que quero fazer, ler o peso de uma balança de PDV da Toledo. Não sabia que existia uma DLL para este fim. Vou me enteirar do assunto. Se o amigo tiver algum exemplo e puder me mandar, fico agradecido.

:)Pos

Re: Leitura de peso - clipper para xharbour

Enviado: 18 Mar 2009 10:04
por DLZ
Eis aqui um pequeno exemplo da utilização da P05.DLL para capturar o peso das balanças PDV da Toledo.

Código: Selecionar todos

FUNCTION RET_PESO()
CLEAR GETS
TDLL:=LoadLibrary("P05.dll")
IF TDLL=0
   ALERT("Problemas na abertura da DLL P05.dll")
   RETURN 0
ENDIF

VTELAPESO:=SAVESCREEN(00,00,24,80)
@ 05,05 CLEAR TO 16,35
@ 05,05 TI 16,35
@ 07,06 SAY PADC(" ",30," ")
@ 15,06 SAY PADC(" ",30," ")

@ 09,06 SAY "Peso:"
VPORTA:=1   // COM1=1 COM2=2.... COM5=5
VVELOCIDADE:=0  // 0=2400 1=4800 2=9600
VDATABITS:=1    // 0=7  1=8
VPARIDADE:=0    // 0=NENHUMA 1=IMPAR 2=PAR 3=ESPACO
RETPORTA:=DLLCALL(TDLL,32,"AbrePorta",VPORTA,VVELOCIDADE,VDATABITS,VPARIDADE)
IF RETPORTA<>1
   ALERT("Erro ao iniciar a porta de comunica‡Æo Com"+ALLTRIM(STR(VPORTA)))
   VRETPESO:=0
   @ 09,11 GET VRETPESO PICT "@E 999.999"
   READ
   RESTSCREEN(00,00,24,80,VTELAPESO)
   RETURN VRETPESO
ENDIF

@ 07,06 SAY PADC("Aguardando retorno da balan‡a",30," ")
@ 15,06 SAY PADC("ESC=Aborta",30," ")
VPESO:=SPACE(6)
DO WHILE EMPTY(VPESO) .OR. SUBSTR(VPESO,1,5)="00000"
   DLLCALL(TDLL,32,"PegaPeso",1,VPESO,"C:\")
   VTEC:=INKEY(0.1)
   IF VTEC=27
      EXIT
   ENDIF
ENDDO

@ 07,06 SAY PADC(" ",30," ")
@ 15,06 SAY PADC(" ",30," ")
VRETPESO:=VAL(VPESO)/1000

@ 09,11 GET VRETPESO PICT "@E 999.999"
READ
RESTSCREEN(00,00,24,80,VTELAPESO)
SETLASTKEY(0)
RETURN VRETPESO

Re: Leitura de peso - clipper para xharbour

Enviado: 19 Mar 2009 10:21
por sygecom
Seu exemplo em clipper ficaria assim na Hbcomm:

Código: Selecionar todos

*****************
Function Ler_Peso
*****************
Local nPorta := 1
Local cTrans := "N"
Local nBits := 8
Local nParad := 1
Local nVeloc := 2400
Local cInicia:= Chr(05)
Local Erro := .F.
Local VlrPeso:= 0
Local nRetorn:= .T.
Local nBytes, oCom

if nPorta > 9
   oCom := DS_Portas():New('\\.\COM'+STR(nPorta,2),nVeloc,nBits,0,nParad)
else
   oCom := DS_Portas():New('COM'+STR(nPorta,1),nVeloc,nBits,0,nParad)
endif
oCom:AbrirPorta()
if oCom:lAberto = .F.
   oCom:FecharPorta(oCom)
   alert("Problemas na Inicialização da Porta Serial, Favor Revisar a Porta COM"+str(nPorta))
   Return(.F.)
endif

Millisec(300)  // tempo obrigatorio de espera de limpeza da porta

nBytes := InbufSize(oCom) // Pega Dados do Buffer.
oCom:EscreverPorta( nBytes, cInicia )

nLeitura:=oCom:LerPorta(10)

oCom:FecharPorta(oCom)

If Substr(nLeitura,1,1)== Chr(02) .And. Right(AllTrim(nLeitura),1)==Chr(03)
   alert(nleitura)
Endif
Return(.T.)

#include "HB_PORTAS.prg"
Obs: Tem que linkar junto o .PRG em anexo que é uma classe para leitura da porta usando a Hbcomm, e junto no anexo tem um pequeno Read-me.

Re: Leitura de peso - clipper para xharbour

Enviado: 19 Mar 2009 11:38
por TerraSoftware
Valeu moçada!!

O cobra foi matada.

:))