Programming > Packages and Libraries

How to use Lazserial

(1/4) > >>

microguy:
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:

--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function WriteData(data: string): integer;
So you need similar of this:

--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---LazSerial1.WriteData(char(1)+'N5'+Memo1.Lines[0]);
Test:

--- Code: Pascal  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ShowMessage(char(1)+'N5'+Memo1.Lines[0]);  

 

microguy:
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:
Hello,

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

microguy:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version