Ask a Question

Undefined SerialPort

SOLVED
rancan
Occasional Contributor

Undefined SerialPort

Hi, 

 

I am a beginner in both TestComplete and Scripting (Java). 

 

I am trying to send sequence and read the com port of a device using TestComplete. 

I found the code on this page: https://support.smartbear.com/testcomplete/docs/scripting/working-with/com-ports.html

 

I copied the function Test() on the page and tried to run it. I received an error message saying 'Cannot read property 'SerialPort' of undefined.

I am not sure whats going on, could anyone help me. 

 

I did the test on a VM, .NET already installed, "NET Classes Support' plug-in is installed and enabled". 

 

Thanks in advance. 

 

4 REPLIES 4
Wamboo
Community Hero

Welcome to TestComplete world!:)

 

"I am a beginner in both TestComplete and Scripting (Java). "

 

First, this is JavaScript, not Java 😉

 

"'Cannot read property 'SerialPort' of undefined."

 

Did You try to do steps from the documentation? You can find there this thread.

 

"The System.IO.Ports namespace is included in the system.dll assembly. This assembly is registered in the Global Assembly Cache (GAC). In order to use the namespace in scripts, register this assembly in the CLR Bridge Options page of the Project Properties editor:"

 

Let me know if this helps You.

rancan
Occasional Contributor

Hi, 

 

Thank you for your help 🙂 

 

Yes, I have followed the steps as instructed, and I have selected the components (System.Data.Linq, System.Data, System.IO) on GAC. However, I couldn't find 'System.IO.Ports' on the list, am I choosing the wrong components? 

 

And when I ran it, it still showed the same error message. Thank you. 

 

Edit: Sorry, my mistake. After checking it again and I enabled the System component on GAC, it ran but showing 'No Data' for the results (it might be because of the external device that I connected, I am unsure)

 

Thank you for your help.

rancan
Occasional Contributor

Hi, 

 

Once again thanks, it works now! 

But, I think there is something wrong with my code, do you mind helping me..

 

Here's the code:

function Test ()
{
   var Port, s;
   
    Port = dotNET.System_IO_Ports.SerialPort.zctor_4 ("COM3", 115200);
    Port.Open ();
    
// Writing data to the port
Port.Write ("1A 03 06 88");
// Waiting for response
aqUtils.Delay (1000);
// Processing response
if (Port.BytesToRead != 0)
{
s = Port.ReadExisting;
Log.Message (s);
}
else
Log.Warning("No Data");

Port.Close();
}

It ran successfully on TestComplete, but the response is empty. It just gave me blank result. 

 

I would really appreciate it if you could help me with this. Thank you. 

Wamboo
Community Hero

I've never done this before, but...


Have you tried to change "zctor_4" to other values?


There's some information on that:

 

SAMPLES -> //Calling a class instance constructor

 

https://support.smartbear.com/testcomplete/docs/testing-with/advanced/using-external-functions/calli...

 

 

 

cancel
Showing results for 
Search instead for 
Did you mean: