• Welcome to Forum.Deepsoftware.Com. Please login or sign up.
 
April 25, 2024, 10:06:06 pm

News:

SMF - Just Installed!


Change com port at runtime

Started by opc0de, May 25, 2012, 10:08:06 am

Previous topic - Next topic

opc0de

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

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:

  nrComm1.ComPortNo := 23;

Possible if you do all at runtime without visual controls, you did not load list of available serial ports:

 
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

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

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

Quote from: Roman Novgorodov on May 25, 2012, 12:33:10 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

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.