Author Topic: Change com port at runtime  (Read 1347 times)

opc0de

  • Newbie
  • *
  • Posts: 4
    • View Profile
Change com port at runtime
« on: May 25, 2012, 01:08:06 pm »
I have started recently at the recomandation of someone from stackoverflow to use nrComm library to handle the communication between the computer and a GSM Modem. I am having trouble with assigning a certain port to the component maybe someone worked with the component before and can tell me what i am doing wrong.

When i use the TnrDeviceBox to pick a COM Port it works fine but when i assign it manually like this it fails :

...
  nrcm1.ComPort := cpCOMxx;
  nrcm1.ComPortNo := comportnumber;
  nrcm1.Active := True;
...
What am i doing wrong. I need to assign COM23 and the component defines only COMS to 1 - 7

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Change com port at runtime
« Reply #1 on: May 25, 2012, 01:34:22 pm »
Hello

Quote
... but when i assign it manually like this it fails ...

Please show me error message. I don't understand what fails.


Usual following code works fine:

Code: [Select]
  nrComm1.ComPortNo := 23;
Possible if you do all at runtime without visual controls, you did not load list of available serial ports:

Code: [Select]
 
nrComm1.Update;
nrComm1.ComPortNo := 23;

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

opc0de

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Change com port at runtime
« Reply #2 on: May 25, 2012, 01:42:41 pm »
Thank you for your fast reply.

There is no error message only the port that i want is not getting opened.I have only a nrgsm and a nrcomm component on my form.It opens COM1 instead of COM23 where COM1 is the value that is at design time.

Should i set ComPort to cpComxx first ? or not ?

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Change com port at runtime
« Reply #3 on: May 25, 2012, 03:33:10 pm »
Hello

Did you try code from my previous message?

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.

opc0de

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Change com port at runtime
« Reply #4 on: May 25, 2012, 07:55:56 pm »
Hello

Did you try code from my previous message?

Roman Novgorodov
DeepSoftware llc

Yes it works though I don't understand why this strange behaivour.Anyway congratulation for this wonderful set of components. Interfacing with serial devices is not hard when you think about it but when it comes to practice there are manny things you must take care of. Luckly nrComm components do their job very well. Good luck !

Roman Novgorodov

  • Engineer
  • Administrator
  • Hero Member
  • *****
  • Posts: 994
  • we will win
    • View Profile
    • Forums.nrCommLib.Com
Re: Change com port at runtime
« Reply #5 on: May 26, 2012, 02:23:24 am »
Hello

You do not need change ComPort if you set ComPortNo value.
But you need to load (enumerate) available port list (at least  once call update()) before setting port number.

When you use TnrDeviceBox attached to TnrComm it calls TnrComm.Update() by itself.

Roman Novgorodov
DeepSoftware llc
DeepSoftware llc - The professional components for Delphi/CBuilder/.NET. The high quality custom software development.
Forums.nrCommLib.Com - DeepSoftware Tech Support Forum.