Recent

Author Topic: Synaser  (Read 18434 times)

PeterH

  • New member
  • *
  • Posts: 30
Synaser
« on: February 08, 2011, 03:31:14 pm »
Hello,
I'm trying to find an example how to receive serial data (19200,n,8,1) with synaser.
The data is a string of 128 characters.
Since synaser has no event driven receive routine... how is this done?

The examples that come with the source code only show sending data.

Thanks in advance for your time !

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1890
« Last Edit: February 08, 2011, 03:42:09 pm by theo »

jhmos

  • New member
  • *
  • Posts: 24
Re: Synaser
« Reply #2 on: February 08, 2011, 06:06:24 pm »
Synasers API is described in the declaration section of the synaser.pas source file.

You could do something like this:

var
    Timeouts : integer;
    buf : array [0..128] of Byte;

    SynaSerComPort: TBlockSerial;

begin
  if SynaSerComPort = nil then

    SynaSerComPort:= TBlockSerial.Create;

  SynaSerComPort.LinuxLock:= False;
  // ignore port locking in Linux
  if not SynaSerComPort.InstanceActive then

    SynaSerComPort.Connect('COM1');  // or whatever com port (might be /dev/ttyUSB0 for Linux)
  // add some delays to allow for serial port setup times

  sleep(500);

  SynaSerComPort.Config(19200, 8, 'N', SB1, False, False);

  sleep(300);


    count:= SynaSerComPort.RecvBufferEx(@buf[0], 128, 500);  //Wait for 500ms per 128 byte packet
    if SynaSerComPort.LastError = ErrTimeout then

    begin

      Inc(Timeouts);
  // Do some sort of recovery here maybe
    end;


end;

PeterH

  • New member
  • *
  • Posts: 30
Re: Synaser
« Reply #3 on: February 10, 2011, 10:44:43 pm »
Thanks ! I'm going to look into the example

PeterH

  • New member
  • *
  • Posts: 30
Re: Synaser
« Reply #4 on: February 20, 2011, 09:44:05 pm »
I'm still a little confused. I don't see any polling in the example above.
Or does Synaser fires an event on Receiving characters?

I'm also curious on the Receive Packet function. Can I receive a string by delaring a start/stop character?




« Last Edit: February 20, 2011, 11:02:21 pm by PeterH »

Laksen

  • Hero Member
  • *****
  • Posts: 616
    • J-Software
Re: Synaser
« Reply #5 on: February 20, 2011, 11:01:36 pm »
In the example it calls RecvBufferEx and blocks until it either times out or receives some data