Source file: /~heha/messtech/rs485dde.zip/SRC/TESTCLI.PAS

program testcli;
{$W-,K+}
uses WinProcs,WinTypes,Win31,WinCrt,DDEML,WUtils,Parser;

const
 timeout: Word=3000;
var
 Inst: LongInt;
 Conv: HConv;
 line: TS255;
 argv: array[0..2] of PChar;
 lip: PChar;
 argc: Integer;
 sz1,sz2: HSZ;
 fOK: Bool;
 data: HDdeData;
begin
 lstrcpy(WindowTitle,'h#s DDE Client (mini)');
 DdeInitialize(Inst,nil,APPCMD_ClientOnly or CBF_Skip_AllNotifications,0);
 writeln('Inst=',Inst);
 repeat
  Write('>');
  ReadLn(line);
  if lstrcmpi(line,'1')=0 then lstrcpy(line,'init rs485 "com2 9600,n,8,1"');
  if lstrcmpi(line,'2')=0 then lstrcpy(line,'req #02:>;');
  if lstrcmpi(line,'3')=0 then lstrcpy(line,'req %02R1E019:>:');
  if lstrcmpi(line,'4')=0 then lstrcpy(line,'poke %02W1E01901;');
  lip:=line;
  argv[0]:=NextItem(lip,Word('"'),DELIM_WhiteSpace);
  argv[1]:=NextItem(lip,Word('"'),DELIM_Whitespace);
  argv[2]:=NextItem(lip,Word('"'),DELIM_Whitespace);
  if lstrcmpi(argv[0],'init')=0 then begin
   sz1:=DdeCreateStringHandle(Inst,argv[1],CP_WinAnsi);
   sz2:=DdeCreateStringHandle(Inst,argv[2],CP_WinAnsi);
   Conv:=DdeConnect(Inst,sz1,sz2,nil);
   DdeFreeStringHandle(Inst,sz1);
   DdeFreeStringHandle(Inst,sz2);
   WriteLn('Conv=',Conv);
  end else if lstrcmpi(argv[0],'timeout')=0 then begin
   Val(argv[1],timeout,argc);
   if argc<>0 then WriteLn('Fehler!');
  end else if lstrcmpi(argv[0],'exit')=0 then break
  else if lstrcmpi(argv[0],'help')=0
  then WriteLn('Kommandos: init exec poke req adv unadv term exit timeout')
  else begin
   if Conv=0 then begin
    WriteLn('Erst "init" ausführen!'); continue;
   end;
   fOK:=true;
   if lstrcmpi(argv[0],'term')=0 then begin
    fOK:=DdeDisconnect(Conv);
    if fOK then Conv:=0;
   end else if lstrcmpi(argv[0],'poke')=0 then begin
    sz1:=DdeCreateStringHandle(Inst,argv[1],CP_WinAnsi);
    fOK:=DdeClientTransaction(argv[2],lstrlen(argv[2])+1,
      Conv,sz1,CF_Text,XTYP_Poke,timeout,nil)<>0;
    DdeFreeStringHandle(Inst,sz1);
   end else if lstrcmpi(argv[0],'req')=0 then begin
    sz1:=DdeCreateStringHandle(Inst,argv[1],CP_WinAnsi);
    data:=DdeClientTransaction(nil,0,Conv,sz1,CF_Text,XTYP_Request,timeout,nil);
    DdeFreeStringHandle(Inst,sz1);
    if data=0 then fOK:=false
    else begin
     WriteLn('Antwort="',PChar(DdeAccessData(data,nil)),'"');
     DdeUnaccessData(data);
     DdeFreeDataHandle(data);
    end;
   end else if lstrcmpi(argv[0],'exec')=0 then begin
    fOK:=DdeClientTransaction(argv[1],lstrlen(argv[1])+1,
      Conv,0,CF_Text,XTYP_Execute,timeout,nil)<>0;
   end else if lstrcmpi(argv[0],'adv')=0 then begin
    sz1:=DdeCreateStringHandle(Inst,argv[1],CP_WinAnsi);
    fOK:=DdeClientTransaction(nil,0,Conv,sz1,CF_Text,XTYP_AdvStart,timeout,nil)<>0;
    DdeFreeStringHandle(Inst,sz1);
   end else if lstrcmpi(argv[0],'unadv')=0 then begin
    sz1:=DdeCreateStringHandle(Inst,argv[1],CP_WinAnsi);
    fOK:=DdeClientTransaction(nil,0,Conv,sz1,CF_Text,XTYP_AdvStop,timeout,nil)<>0;
    DdeFreeStringHandle(Inst,sz1);
   end;
   if fOK=false then WriteLn('Fehler!');
  end;
 until false;
 DdeUninitialize(Inst);
 DoneWinCrt;
end.
Detected encoding: ANSI (CP1252)4
Wrong umlauts? - Assume file is ANSI (CP1252) encoded