Hello, 
 
I am trying to communicate with a system. 
There is something I can't figure out. 
Following is a piece of code that I used to communicate on other cases
without problems. 
 
But this time, the instrument on the other side does not 
respone until I close the port. Is it because of Flow Control or 
other signal such as DTR ?
 
Unfortunately, I don't know much about the changing the Serial Flags
and also to finding the relevent code or help was not easy for me. 
May be just for me.
 
It will be much appreciated if you point me the right place or share
piece of code . 
 
one more question: As you can see in the code below, I get "0 byte" 
is this normal ? To prevent endless loop, I inserted time-check.
 
Thank you
 
onions
 
=========================================================================
 
 
procedure TForm1.BitBtn2Click(Sender: TObject);
var
 ySer : TBlockSerial ;
 yCmd : String ;
 yXOR : LongInt ;
 n : Integer ;
 yByte: Byte ;
 yOldTime : TDateTime ;
 yArr : Array[0..1000] of Char ;
 yC : Integer ;
 yZeroCount : Integer ;
 yMax : Integer ;
begin
 TRY
 if Length(Trim(Form1.Edit1.Text)) < 1 then
 yMax := 100
 else
 yMax := StrToInt(Form1.Edit1.Text) ;
 memo1.Clear ;
 ySer := TBlockSerial.Create ;
 ySer.LinuxLock := False ;
 ySer.RaiseExcept := False ;
 ySer.Connect('COM6') ;
 ySer.Config(38400,8,'N',0,False,False);
 if ySer.CanWrite(1000) then
 begin
 yCmd := #27 + 'PR3 2' + #13 ; // ESC + PR3 2 + CR
 ySer.SendString(yCmd);
 end;
 yZeroCount := 0 ;
 yC := 0 ;
 yOldTime := Now ;
 FillChar(yArr,1000,$0) ;
 while not ySer.LastError <> 0 do
 begin
 Application.ProcessMessages ;
 yByte := ySer.RecvByte(1) ;
 if ( Now - yOldTime) * 100000 > 3 then
 begin
 Form1.Memo1.Lines.Add('timeout 3') ;
 ySer.Free ;
 exit ;
 end;
 if yByte = 0 then
 begin
 Form1.Memo1.Lines.Add(' 0 byte') ;
 Inc(yZeroCount) ;
 if yZeroCount > yMax then
 begin
 Form1.mmoDebug.Lines.Add(' 0 byte count over > ' + IntToStr(yMax)) ;
 ySer.Free ;
 exit ;
 end;
 continue;
 end;
 if yByte = 13 then // CR LF
 begin
 Form1.Memo1.Lines.Add(yArr) ;
 ySer.Free ;
 exit ;
 end;
 if yC < 1000 then
 begin
 yArr[yC] := Char(yByte) ;
 Inc(yC) ;
 end;
 end;
 ySer.Free ;
 EXCEPT
 on E:Exception do
 begin
 if Assigned(ySer) then
 ySer.Free;
 Form1.mmoDebug.Lines.Add(E.Message) ;
 end;
 end;
end;
 
 
 
 
 
 
 
 
 
 onionsjk님의 블로그
 안녕하세요.
 
 
 
 
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
synalist-public mailing list
synalist-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synalist-public

Reply via email to