Balanza con conexion USB

Post Reply
devwin2010
Posts: 38
Joined: Tue Jul 17, 2007 12:37 pm

Balanza con conexion USB

Post by devwin2010 »

Estimados Colegas

Alguien tiene algun ejemplo como leer los datos de una balanza con conexion USB

desde ya muchas gracias
Fabian
User avatar
karinha
Posts: 4882
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: Balanza con conexion USB

Post by karinha »

cual és el modelo?

Teste este ejemplo cambiando el puerto:

Code: Select all

#include "FiveWin.ch" 

// Protocolo Prt1 STXPPPPPETX
// Protocolo Prt2 STXPPPPPPCR
// Protocolo Prt3 STXP/I/N/SETX

#DEFINE ENQ chr(05)
#DEFINE STX chr(02)
#DEFINE ETX chr(03)
#DEFINE CR chr(13)

static hLib, hDib, oSpoolTimer, nCom

Function Main(_tempo_,cComm) 
 Default _tempo_ := "05", cComm := "COM4"
 nCom := APRICOM( cComm )
 cConteudo := STX + strZero( Random( 999999 ), 6 ) + ETX
 for i = 1 to len( cConteudo )
   SENDSTR( nCom, Substr( cConteudo, i, 1 ) )
 next
 cConteudo := ""
 Return NIL         

STATIC FUNCTION TASTI( nCom, nKey ) 
  SENDSTR( nCom, CHR( nKey ) ) 
  RETURN NIL 

STATIC FUNCTION APRICOM( cComm ) 
  LOCAL nCom, cDcb 
  BEGIN SEQUENCE 
    nCom = OPENCOMM( cComm, 16384, 16384 ) 
    IF nCom < 0 
      ? "Errore di apertura della porta di comunicazione." 
      BREAK 
    ENDIF 
    BUILDCOMMDCB( cComm+":115200,N,8,1", @cDcb ) 
    IF !SETCOMMSTATE( nCom, cDcb ) 
      ? "Errore di impostazione della porta di comunicazione." 
      BREAK 
    ENDIF 
    Connect( nCom )
  RECOVER 
    nCom = -1 
  END SEQUENCE 
  RETURN nCom 

STATIC FUNCTION CONNECT( nCom ) 
  LOCAL cStr 
  ENABLECOMMNOTIFICATION( nCom, 0, 1, -1 ) 
  cStr = RECEIVESTR( nCom ) 
  cStr = STRTRAN( cStr, CHR( 13 ), "" ) 
  cStr = STRTRAN( cStr, CHR( 10 ), CRLF ) 
  RETURN NIL 

STATIC FUNCTION SENDSTR( nCom, cString ) 
  LOCAL nBytes := WRITECOMM( nCom, cString ) 
  RETURN nBytes = LEN( cString ) 

STATIC FUNCTION RECEIVESTR( nCom ) 
  LOCAL cBuf := SPACE( 1000 ) 
  RETURN LEFT( cBuf, READCOMM( nCom, @cBuf ) )

STATIC FUNCTION Random( nMaximo )
  static nRandom
  local nTemporal
  nMaximo = if( nMaximo == NIL, 65535, nMaximo )
  if nRandom == NIL
   nRandom = seconds()
  endif
  nTemporal = ( nRandom * seconds() ) % ( nMaximo + 1 )
  nRandom = nTemporal + seconds()
  RETURN int( nTemporal )
 
salu2
João Santos - São Paulo - Brasil
Post Reply