Hellow My friends
Some of you have had experience with communication with USB ports to 485 with converter. There will be state codes in ports 485 ??
. Please someone to give me a hand.
I have a counter of people, communicate by 485 and I put a converter to USB, I use a third-party program .. to communicate and work very well
See .. http://www.busmaticcr.com/pantalla.bmp
As you can see, a command is sent and the return is fine.
Now My Program..
I perceive when I use my program with the same setting I do not receive anything .. although I see the TXD converter light that if I send data..
This program was taken from some people who post it
#Include "FiveWin.Ch"
Function Comunica()
Local mport := 2 // Puerto COM
Local PortId, cBloque
PortId := abrirport(mport)
cbloque = leer_bloque(PortId,31)
CloseComm(PortId)
RETURN cBloque
STATIC FUNCTION abrirport(n)
LOCAL IdPort, cDcb, nError
IdPort := OpenComm("COM"+STR(n,1),1024,256)
IF IdPort <= 0
nError = GetCommError( IdPort)
MsgInfo( "Error al abrir: " + Str( nError ) )
ELSE
MsgRun("Puerto abierto como " + STR(IdPort))
ENDIF
IF ! BuildCommDcb("COM"+STR(n,1)+":9600,n,8,1" , @cDcb)
nError = GetCommError( IdPort)
MsgInfo( "Error al Configurar: " + Str( nError ) )
RETURN 0
ELSE
MsgRun("Puerto Configurado")
ENDIF
IF ! SetCommState( IdPort, cDcb )
nError = GetCommError( IdPort)
MsgInfo( "Error al setear: " + Str( nError ) )
RETURN 0
ELSE
MsgRun("Puerto Seteado")
ENDIF
RETURN IdPort
STATIC FUNCTION leer_bloque(port,n)
LOCAL bloque:= SPACE(n),bcc1,nBytes,i:=1
DO WHILE .t.
nBytes := ReadComm( port,@bloque)
i++
IF EMPTY(bloque)
MsgWait("Esperando ENQ","Espere",3)
mandar_enq(port)
LOOP
ENDIF
IF i > 20 // .or. bloque <> SPACE(n)
EXIT
ENDIF
ENDDO
RETURN bloque
STATIC FUNCTION mandar_enq(port)
LOCAL mcont,retorno,nBytes
LOCAL cString:="02 30 30 30 31 31 33 30 30 31 34 03", nByteslargo:= Len( cString )
retorno = .t.
FOR mcont := 1 TO 10
IF ( nBytes := WriteComm( port,cString,nByteslargo)) <= 0
MsgAlert("Mando mal ENQ")
retorno := .f.
ELSE
retorno := .t.
exit
ENDIF
MsgWait("Enviando datos...","Aguarde",1)
NEXT
RETURN retorno