This sample code for get data temperature in clipper :
FUNCTION GetTemperature()
LOCAL buff_size,com_ok,init_ok,c_input,l_send, t01,a01,b01,VAL_01
a01 := 0
b01 := 0
t01  := 0

buff_size := 4000 && 4000 byte buffer
com_ok := COM_OPEN(1,buff_size) && COM1: open
DO WHILE .T. .and. INKEY()<> K_ESC
IF .NOT. com_ok
? “It was not possible to open interface.”
ELSE
init_ok = COM_INIT(1, 9600, “N”, 8, 1)
IF .NOT. init_ok
alert(“It was not possible to initialize the interface”)
ELSE
** SENSOR 01
l_send = COM_SEND(1,”:01R;”)
INKEY(0.5)
c_input = COM_READ(1,COM_COUNT(1)) && Read in 10
IF LEN(ALLTRIM(c_input)) <= 0
t01 = 0
ENDIF
a01 = AT(“01+”,c_input )
IF a01 > 0
b01 = AT(“*”,SUBSTR(c_input ,a01,9))
IF b01 > 0
VAL_01 = VAL(SUBSTR(c_input ,(a01+b01)-5,4))
t01 = VAL_01
ENDIF
ENDIF

COM_FLUSH(1)

@XX,XX SAY TRANSFORM(t01,”###.##”)

ENDIF

ENDIF

IF LastKey() = 27 &&K_ESC
COM_CLOSE(1)
ENDIF
ENDDO

RETURN .T.

Advertisements