MarshallSoft

Delphi RS232 Serial Example


unit Dvce_pgm;

interface

uses
  wsc32, wsc32w, keycode, Display,
  SysUtils, WinTypes, WinProcs, Messages,
  Classes, Graphics, Controls,
  Forms, Dialogs, StdCtrls, ExtCtrls;

implementation

function SendCommand(Port,Baud:Integer;Command:String;var Buffer:String:BufLen:Integer):Integer;
begin
  {reset (open) the port}
  SendCommand := fReset(Port, 1024, 1024);
  {error ? (negative return codes are errors)}
  if Code < 0 then exit;
  {set the baud rate}
  SendCommand := fBaud(Port, Baud);
  if Code < 0 then exit;
  {send string}
  SendCommand := fPuts(Port, Command, Length(Command));
  if Code < 0 then exit;
  {wait up to 250 mSec for a response}
  if(fWaitFor(Port, 250)<0) return Code;
  {allow time for entire response (depends on serial device)}
  fSleep(1);
  {return data}
  SendCommand := SendCommand fGets(Port, Buffer, BufLen)
end;

{initialization}
begin
end.

MSC Logo

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