Recent

Author Topic: using synaser  (Read 8044 times)

a13di_63

  • Newbie
  • Posts: 1
using synaser
« on: May 08, 2009, 01:07:22 am »
hello there i'm a newbie.... :D.
help me please..... :-[

how to use synaser!
I'm already download the file in www.ararat.cz / synapse

thank's b4 :)

DGambrinus

  • Newbie
  • Posts: 4
Re: using synaser
« Reply #1 on: May 08, 2009, 05:35:13 pm »
Can't post my whole class because its a work project and it depends on a few other classes that you wouldn't have but hopefully this can get you started.

Code: [Select]
//Make sure synaser is in your uses clause

//Create object
  mySerialPort := 'COM1';
  myBaudRate := 19200;
  myBits := 8;
  myParity := 'N';
  myStop := 0;
  mySoftFlow := False;
  myHardFlow := False;

 mySerial := TBlockSerial.Create();
  try
    mySerial.RaiseExcept := False;
    mySerial.LinuxLock := False;
    mySerial.Connect(mySerialPort);
    mySerial.Config(myBaudRate, myBits, myParity, myStop, mySoftFlow, myHardFlow);
    s := mySerial.LastErrorDesc;
  except
    FreeAndNil(mySerial);
  end;



//Sending stuff
mySerial.SendString(s);



//Receiving stuff
  while (mySerial.CanRead(100)) do
  begin
    s := mySerial.RecvPacket(0);
    ReceivedData := ReceivedData + s;
  end;

  if (Length(ReceivedData) > 0) then
  begin
    //Do what you want to with the received data.
    //I post it onto a global MessageQueue for my app.
    ReceivedData := '';
  end;


This all sits in its own thread with the sending and receiving taking place in the execute method. In my class any received data is put into a global message queue so that the main thread can process the messages received.

Hopefully this provides a starting point for you.