MarshallSoft

FoxPro RS232 Serial Example


* Send command to RS232 serial device

Function SendCommand(Port, Baud, Command)
Local Kode
Local Buffer
* reset (open) the port
Kode = SioReset(Port, 1024, 1024)
* error ? (negative return codes are errors)
if Kode < 0
  return Kode
endif
SioBaud(Port, Baud)
* send string
Kode = SioPuts(Port, @Command, Len(Command))
if Kode < 0
  return Kode
endif
* wait up to 500 mSec for a response
Kode = SioWaitFor(Port, 500)
if Kode < 0
  return Kode
endif
* allow time for entire response (depends on serial device)
Kode = SioSleep(250)
* display response
Buffer = SPACE(256)
Kode = SioGets(Port, @Buffer, 255)
if Kode > 0
  ? Left(Buffer, Kode)
endif
return Kode

MSC Logo

HOME PAGE
MARSHALLSOFT is a trademark of MarshallSoft Computing, Inc.