Recent

Author Topic: How to use Lazserial  (Read 21784 times)

microguy

  • New Member
  • *
  • Posts: 49
How to use Lazserial
« on: March 30, 2018, 05:41:33 am »
I am trying to figure how to use LazSerial. I have a list of text in memo. What I would like to send each line at time. When I hit enter and it will send one line then hit enter to send second one then hit enter to send next one.  Need to use Com4, 1200, 8,n,1

I have set TLazSerial
BaudRate = br_1200
DateBits = db8bits
Device = Com4
FlowControl = fcNone
Parity = pNone
StopBits = sbOne


I need to send CRTL-A N5 plus first line of memo.  If need to send again like hit enter then need to add CRTL-A  N5 plus second line memo.

All I can think of this but not working.

procedure TForm1.Button1Click(Sender: TObject);
begin
    LazSerial1.ShowSetupDialog;
    LazSerial1.Active:= True;
    LazSerial1.Open;
    LazSerial1.WriteData(char(Ctrl_A) + char(N5) + char("Hello there")
//will add memo later....
    LazSerial1.SynSer.flush;
end;                       

 

totya

  • Hero Member
  • *****
  • Posts: 720
Re: How to use Lazserial
« Reply #1 on: March 30, 2018, 10:02:55 am »
Code: Pascal  [Select][+][-]
  1. char("Hello there")

The char is only one (1) character. "Hello there" is a string. But you must got compiler error...

WriteData definition:
Code: Pascal  [Select][+][-]
  1. function WriteData(data: string): integer;

So you need similar of this:
Code: Pascal  [Select][+][-]
  1. LazSerial1.WriteData(char(1)+'N5'+Memo1.Lines[0]);

Test:
Code: Pascal  [Select][+][-]
  1. ShowMessage(char(1)+'N5'+Memo1.Lines[0]);  


 

microguy

  • New Member
  • *
  • Posts: 49
Re: How to use Lazserial
« Reply #2 on: April 04, 2018, 03:45:39 am »
I am frustrated to get serial port working.  First I want to run program which want to set the port, baud rate, data bits, stop bits, parity set.. But I still get error on this. Can someone tell me what did I do wrong. I tried two different way.

procedure TForm1.FormCreate(Sender: TObject);
begin
  LazSerial1.BaudRate := br_1200;
  LazSerial1.DateBits := db8bits;
  LazSerial1.Device := COM4;
  LazSerial1.FlowControl := fcHardware;
  LazSerial1.Parity := pNone;
  LazSerial1.StopBits := sbOne;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  LazSerial1.BaudRate := 1200;
  LazSerial1.DateBits := 8;
  LazSerial1.Device := COM4;
  LazSerial1.FlowControl := Hardware;
  LazSerial1.Parity := None;
  LazSerial1.StopBits := 1;
end;

I put them on hold like nod or // for each line and try this one which it didn't give me any error.

procedure TForm1.Button14Click(Sender: TObject);
begin
  LazSerial1.ShowSetupDialog;
  LazSerial1.Open;
end;

ShowSetupDialog did show what I have on properties.

However I tried to send CTRL_A

procedure TForm1.Button19Click(Sender: TObject);
begin
  LazSerial1.SynSer.SendInteger(Ctrl_A);
end;

It didn't give me any error but to me it is not to blink led light on "Link". I have Belkin USB to Serial Portable (DB9) Adapter. This adapter has 3 LED light. (link, TX,RX).  When I use HyperTerminal program and it works fine to hit any key which led light blink on "Link".

I went to Torry delphi  webpage and found some comport to see if I can convert into Lazarus. None of them are working. Is there any example programs that will work with Lazarus? I want to download some example program and play with code. I want to see many example code and how does it works that will refresh my mind to understand this serial code works.

Reid

 






tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: How to use Lazserial
« Reply #3 on: April 04, 2018, 08:35:04 am »
Hello,

Is your device supporting to hardware flow?
I added an virtual com settings in attach but means in real hardware almost same.

microguy

  • New Member
  • *
  • Posts: 49
Re: How to use Lazserial
« Reply #4 on: April 05, 2018, 03:47:17 am »
tr_escape,

I am sure it is support hardware flow. When I use Hyperterminal program and I set hardware flow and it works just fine.  I think maybe something wrong with this LazSerial component on my computer might not working. How can we find out which version I have? I see that current version is 0.2.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: How to use Lazserial
« Reply #5 on: April 05, 2018, 06:37:02 am »
hello,
don't use SendInteger :
Code: Pascal  [Select][+][-]
  1. procedure SendInteger(Data: integer); virtual;
  2. send four bytes as integer.
Have you tried the totya's code ? it's the right way.
What is your target device ? have you the documentation of it ? May be you must send some characters at the end of each line (like  CRLF ) .

Friendly J.P
« Last Edit: April 05, 2018, 06:43:26 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

microguy

  • New Member
  • *
  • Posts: 49
Re: How to use Lazserial
« Reply #6 on: April 06, 2018, 06:35:31 am »
Jurassic Pork,

This device I have is PCE-845 Encoder for closing caption. This device required to send CTRL_A first then send N5 then send any Character we want to type which it will show up on TV Closing Caption.  It use 1200 Baudrate, 8 databits, 1 stopbits, none parity. My laptop use COM4 for USB adapter to RS232. (Beklins)

First of all it is my understand we need to set 1200, 8, 1, none in formcreate before we do anything else.

Here is my code which I couldn't get it working. It gives me some errors.

procedure TForm1.FormCreate(Sender: TObject);
begin
  LazSerial1.BaudRate := br_1200;
  LazSerial1.DateBits := db8bits;
  LazSerial1.Device := COM4;
  LazSerial1.FlowControl := fcHardware;
  LazSerial1.Parity := pNone;
  LazSerial1.StopBits := sbOne;
end;

I did try this LazSerial1.BaudRate := 1200;  It didn't work either. 

Also are there any example programs on LazSerial that I can take a look and see how it works?

Reid 

tr_escape

  • Sr. Member
  • ****
  • Posts: 432
  • sector name toys | respect to spectre
    • Github:
Re: How to use Lazserial
« Reply #7 on: April 06, 2018, 07:17:23 am »
Hello you can try this software:  This software written in lazarus/fpc and used Lazserial and LNet packages.

https://sourceforge.net/projects/muterm/files/muterm/

source codes are there:

https://github.com/mehmetulukaya/muterm

You can use freely.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: How to use Lazserial
« Reply #8 on: April 06, 2018, 11:53:09 pm »
hello,
here is in attachment a small project to send binary data from a comma delimited string with TLazserial component.
1 - click on the port settings button -> Choose your COM port and configure it.
2 - click on the open button to open the port
2 - Write a hexa comma delimited  string in the Tedit field and check the HEXA checkbox
example :  01,4E,35,48,65,6C,6C,6F,20,74,68,65,72,65 for <CTRL-A>N5Hello There
3 - click on the send button to write your data on the serial port.
The project use a TLazserial component and a TKHexEditor component (from KControls package that you can install from the online package manager). The TKHexEditor is used to display the data coming from the serial port.
the project has been tested on Windows 10 Lazarus 1.8.2  with two serial ports (COM3 and COM4) connected each other with a null modem cable. See attachment.
 
Friendly, J.P
« Last Edit: April 08, 2018, 07:09:52 am by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

microguy

  • New Member
  • *
  • Posts: 49
Re: How to use Lazserial
« Reply #9 on: April 07, 2018, 11:27:29 pm »
tr_escape,

Your program muterm is nice but I am little confusing how to use it.  I tried to do something and it didn't work for me.  I will figure it out later..

Jurassic Pork,

I have some trouble to get it working. I think I got KControlsLaz.Ipr to addthe package. I couldn't get TKHexEditor working. I don't see Ipr on TKHexEditor.Ipr on list. How can we add it?

Reid

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: How to use Lazserial
« Reply #10 on: April 08, 2018, 07:12:34 am »
hello,
what is your version of lazarus and your O.S? You don't have the online package manager ?
To install kcontrols package without online package manager :
1 - Download the last version of kcontrols from bitbucket     (last version is 1.7.1)
2 - Unzip the file
3 -  menu Package/Open Package File (*.lpk) -> Open the package    packages/kcontrols/kcontrolslaz.lpk in the unzipped folder.
4 - Compile it and install it.

My project works also on Lubuntu 16.04 (see attachment).


Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

microguy

  • New Member
  • *
  • Posts: 49
Re: How to use Lazserial
« Reply #11 on: April 08, 2018, 04:32:09 pm »
Jurassic,

I have Lazarus 1.6.4 and OS window 10. If I have old version of Lazarus. How can I update Lazarus? Do we need to uninstall then download the new one?

Reid

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: How to use Lazserial
« Reply #12 on: April 08, 2018, 04:57:17 pm »
1.6.4 is old. It is better to uninstall and upgrade to 1.8.2 from the official source which is http://www.lazarus-ide.org/
Note: make backups. There are breaking changes.
Specialize a type, not a var.

microguy

  • New Member
  • *
  • Posts: 49
Re: How to use Lazserial
« Reply #13 on: April 09, 2018, 02:36:12 am »
I have uninstall Lazarus old version and install a new version 1.8.2. Also I added LazSerial and LazControl.  Now I got an error message which I am missing Lazsynser.  I also download synser but it didn't work. I don't know how to fix it.

Reid

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: How to use Lazserial
« Reply #14 on: April 09, 2018, 05:06:49 am »
hello,
are you sure that you are using the 0.2 version of TLazSerial ? Lazsynaser is inside this version.
The 0.2 version is here
Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

 

TinyPortal © 2005-2018