Recent

Author Topic: [SOLVED]-How do you switch Ports on TLazSerial?  (Read 2961 times)

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 480
  • Programming is FUN only when it works :)
    • Cool Technology
[SOLVED]-How do you switch Ports on TLazSerial?
« on: April 22, 2016, 04:47:49 pm »
Hello,

I am using TLazSerial component for serial communication on Raspberry PI to communicate with external devices. I have figured out that I can also use USB ports for serial communication. So, now I can use USB ports and Serial port right off the Raspberry PI. In my testing, I have noticed that when my program starts up it only talks through the first option I have selected for serial communication and it won't let me switch. For instance, if I initially start my program to work with USB ports, it works but only on USB. But if I want to switch to on-board serial ports I have to select the on-board serial ports, shutdown my program and then start it back up again. I just can't switch ports on the fly. I don't know why.

My code:
Code: Pascal  [Select][+][-]
  1. procedure TDXCommdlg.ApplyComm();
  2. begin
  3.  
  4.         if (MComport.Active=false) then
  5.         begin        
  6.              MComport.Close;
  7.              MComport.Active:=false;
  8.              if (TypeOfCon.ItemIndex=0) then
  9.              begin
  10.                   //showmessage('USB');
  11.                   case Commport.ItemIndex of
  12.                   1:MComport.Device:='/dev/ttyUSB0';
  13.                   2:MComport.Device:='/dev/ttyUSB1';
  14.                   3:MComport.Device:='/dev/ttyUSB2';
  15.                   4:MComport.Device:='/dev/ttyUSB3';
  16.                   5:MComport.Device:='/dev/ttyUSB4';
  17.                   end;
  18.              end
  19.              else
  20.              begin
  21.                   //showmessage('AMA0');
  22.                   case Commport.ItemIndex of
  23.                   1:MComport.Device:='/dev/ttyAMA0';
  24.                   2:MComport.Device:='/dev/ttyAMA1';
  25.                   3:MComport.Device:='/dev/ttyAMA2';
  26.                   4:MComport.Device:='/dev/ttyAMA3';
  27.                   5:MComport.Device:='/dev/ttyAMA4';
  28.                   end;
  29.              end;
  30.        
  31.              case BaudRate.ItemIndex of
  32.              0:MComport.BaudRate:=br___300;//tmpbaud:=300;
  33.              1:MComport.BaudRate:=br__1200;//tmpbaud:=1200;
  34.              2:MComport.BaudRate:=br__2400;//tmpbaud:=2400;
  35.              3:MComport.BaudRate:=br__4800;//tmpbaud:=4800;
  36.              4:MComport.BaudRate:=br__9600;//tmpbaud:=9600;
  37.              5:MComport.BaudRate:=br_19200;//tmpbaud:=19200;
  38.              6:MComport.BaudRate:=br_38400;//tmpbaud:=38400;
  39.              7:MComport.BaudRate:=br_57600;//tmpbaud:=57600;
  40.              8:MComport.BaudRate:=br115200;//tmpbaud:=115200;
  41.              end;
  42.        
  43.              case paritygroup.ItemIndex of
  44.              0:MComport.Parity:=pEven;
  45.              1:MComport.Parity:=pNone;
  46.              end;
  47.  
  48.              MComport.StopBits:=sbOne;
  49.              MComport.FlowControl:=fcNone;
  50.              MComport.DataBits:=db8bits;
  51.              MComport.RcvLineCRLF:=false;
  52.  
  53.              MComport.SynSer.EnableRTSToggle(true);
  54.  
  55.              try
  56.                 MComPort.Open;
  57.              except on Exception do
  58.                 ShowMessage('Can''t connect to '+ Inttostr(Commport.ItemIndex));
  59.              end;
  60.  
  61.         end;
  62. end;                                                
  63.  
« Last Edit: April 26, 2016, 03:09:30 pm by reltek »

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1290
Re: How do you switch Ports on TLazSerial?
« Reply #1 on: April 22, 2016, 11:54:47 pm »
hello,
something is strange in your code  :-\   :
Code: Pascal  [Select][+][-]
  1.         if (MComport.Active=false) then
  2.         begin        
  3.              MComport.Close;
  4.              MComport.Active:=false;
  5.         // rest of code
  6.  

try  :
Code: Pascal  [Select][+][-]
  1.         if (MComport.Active=true) then
  2.         begin        
  3.              MComport.Close;
  4.              MComport.Active:=false;
  5.         end;
  6. // rest of code
  7.  

Friendly, J.P
« Last Edit: April 22, 2016, 11:57:38 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

Awesome Programmer

  • Sr. Member
  • ****
  • Posts: 480
  • Programming is FUN only when it works :)
    • Cool Technology
Re: How do you switch Ports on TLazSerial?
« Reply #2 on: April 26, 2016, 03:09:09 pm »
 :D
It works Now...Thank you...

I guess I made a logical error. Thank you JP...
 :-[

 

TinyPortal © 2005-2018