I'm sorry to bother you again but I can't grip the serial posrt
handling at all....
I have installed 5dpo serial component in Lazarus on Ubuntu 10 (a
virtual machine in VMWare, which uses the host COM1 serial port) and
tried the following test:

- Created a form with an Open/Close button, an edit box and a listbox.
- Added a 5dpo serial component to the form and set it to 9600 baud.
- Also set it to use ttyS0 (which I assume translates to the first
serial port in Linux)
- Implemented a button click event to open/close the port
- Implemented a button click event to send the editbox text out
- Implemented an RxData event to put incoming text into the listbox
- Connected the serial port used by the Ubuntu VM to the other port on
the PC using a null terminal cable.
- In Windows I started Hyperterminal on the second port

My test program was started in Ubuntu and I clicked the Open button,
then entered text in the editbox and clicked the send button.
Nothing appeared in Hyperterminal...

Tried typing into hyperterminal, but nothing appeared in the program
listbox either.

If I now close the port with my button and then try to open it again
there is an exception that forces the program to end.

In fact if I use the open/close button repeatedly without sending
anything then all seems to work. But if I open-send text-close then
the next time I try the open button again the exception occurs.

What have I done wrong?

Here is the body of the code:

  TfrmMain = class(TForm)
    btnClose: TBitBtn;
    btnOpen: TButton;
    btnSendData: TButton;
    edSendData: TEdit;
    lbxData: TListBox;
    serSdpo: TSdpoSerial;
    shpLED: TShape;
    procedure btnOpenClick(Sender: TObject);
    procedure btnSendDataClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var CloseAction:
TCloseAction);
    procedure serSdpoRxData(Sender: TObject);
  private
    FComBuffer: string;
  public
    { public declarations }
  end; 

var
  frmMain: TfrmMain;

implementation

{ TfrmMain }

procedure TfrmMain.serSdpoRxData(Sender: TObject);
var
  Data: string;
begin
  Data := serSdpo.ReadData();
  if Length(Data) > 0 then
    FComBuffer := FComBuffer + Data;
  lbxData.Items.Add(Data);
end;

procedure TfrmMain.btnOpenClick(Sender: TObject);
begin
  {Open/close port}
  if serSdpo.Active then
  begin
    serSdpo.Close;
    shpLED.Brush.Color := clRed;
    btnSendData.Enabled := false;
  end
  else
  begin
    FComBuffer := '';
    serSdpo.Open;
    shpLED.Brush.Color:= clLime;
    btnSendData.Enabled := true;
  end;
end;

procedure TfrmMain.btnSendDataClick(Sender: TObject);
var
  SendText: string;
  Res: integer;
begin
  SendText := edSendData.Text;
  if (SendText <> '') and serSdpo.Active then
    Res := serSdpo.WriteData(SendText);
end;

procedure TfrmMain.FormClose(Sender: TObject; var CloseAction:
TCloseAction);
begin
  if serSdpo.Active then
    serSdpo.Close;
end;


-- 
Bo Berglund
Developer in Sweden


--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to