06-21-2016 08:45 AM
Hi - new TS user here so treat me kind! Thanks
I'm creating a VB.Net assembly (dll) whose functions I want to call from TS to write/read to an instrument using a telnet session.
If I create a VB form in my project to use the assembly write/read function calls it works ok. But I keep getting "object not defined" error messages when trying to call the same functions from TS steps using the .net adaptor.
Let me simplify the VB.Net code to highlight the key areas and the object that is throwing the error.
Imports System.Net.Sockets
Imports System.Text
Public Class Class1
Public telnetclient2 As New TcpClient ' object used to open the telnet session
Public thisstream2 As NetworkStream ' object used to write/read to/from the instrument via the telnet session
Public Function TelNet_Connect2() ' used to make initial telnet connection and send some default messages to the instrument
telnetclient2.Connect("10.0.0.16", 23) ' connect
Threading.Thread.Sleep(2000) ' sleep 2s
Read2() ' read initial response after connecting
TelNet_Query2("login") ' send "login" message and read response
TelNet_Query2("root") ' send "root" message and read response
TelNet_Query2("wl ver") ' send "wl ver" message and read response
End Function
Private Sub Read2() ' used to read telnet response
thisstream2 = telnetclient2.GetStream()
' use thisstream2 object to get telnet response here
End Sub
Public Function TelNet_Query2(Text As String)
thisstream2 = telnetclient2.GetStream()
' write Text
' wait 2s
' read response
End Function
End Class
Now in the TS sequence, Setup section I can call TelNet_Connect2() ok. In functions Read2 and TelNet_Query2 then object thisstream2 is available.
However if in the TS sequence, Main section I call TelNet_Query2("wl revinfo") so sending a different command then TS throws an error from my VB code saying object thisstream2 is Nothing.
How can this be Nothing when previously TelNet_Connect2 called TelNet_Query2 which used object thisstream2 with no problems.
Hope somebody can shed some light on this for me please.
I know the code is ok in VB.Net since if I call the same functions in the same order from a VB.Net form then it runs ok.
Much appreciated.
Regards
Chris Hargreaves
06-23-2016 10:08 AM
When you construct your object with the .NET adapter you need to store it in a TestStand Object Reference variable and reuse that as the existing object when you want to make later method calls on the same object (rather than constructing a new object for the method calls). Are you doing that? If you show us what your .NET calls in your sequence look like that would help us better determine the problem.
Hope this helps,
-Doug
06-23-2016 11:19 AM
Thanks for the reply Doug.
The guys at NI Newbury are looking into this issue too. I have passed on your suggestion. They have my full VB.Net code.
I'll see if your comments give them any clues.
Regards,
Chris
06-27-2016 10:13 AM
Hi again Doug,
Here's copy of the info I sent NI direct - still no reply.
Plus the attached VB.Net source files and TS sequence.
I've added new simple functions to the .Net dll today (not in this version of source code) and calling those functions from TS sequence steps show similar issues.
It looks like each time a TS step calls a .Net dll function it creates a new instance. So two adjacent steps calling the same VB.Net function are not sharing variables/objects.
Looking at the Module tab in Step Settings, I can see the "Object Reference" under "Type". Its "Value" is empty. I'm guessing here that I need some extra info input into TS step to "link" the two variables/objects together.
There seems to be very limited online TS and VB.Net examples. Am I on the right lines and can you provide any more info?
Much appreciated,
Regards
Chris
NI email info below...
Ok – I’ve stripped down the TS and VB.Net code to an absolute minimum and uploaded all files to your “incoming” folder.
2644128 for NI.7z
The TS sequence file is “Sequence file 3.seq”
The 2013 VB.Net solution file is “example_class2.sln” in sub folder…
...for NI\V0.2\example_class2
When you open this VB.Net solution you’ll see 2 projects,
the common dll code is Class1. This is the dll called by the TS sequence steps.
Let me describe first how the code works ok when run in VB.Net using the example_form2 project and then second using TS with its problem.
Now how this similar sequence doesn’t work with TS
<see Document123.rtf attached here>
An exception occurred inside the call to .NET member 'TelNet_Version':
System.InvalidOperationException: The operation is not allowed on non-connected sockets.
at System.Net.Sockets.TcpClient.GetStream()
at example_class2.Class1.TelNet_Query(String Text) in T:\Anritsu MT8870A\TestStand vb.net control project\for NI\V0.2\example_class2\example_class2\Class1.vb:line 21
at example_class2.Class1.TelNet_Version() in T:\Anritsu MT8870A\TestStand vb.net control project\for NI\V0.2\example_class2\example_class2\Class1.vb:line 31
I hope you can follow this explanation.
Any ideas much appreciated,
Regards
Chris
06-29-2016 08:32 AM - edited 06-29-2016 08:35 AM
Have you tried what I suggested in my previous post? If you want to share an object between different .NET steps you need to create a local variable to store the object (an Object Reference variable) and then you should only call the constructor once and store the result in the local variable, in the first step. In subsequent steps you should select the special <Use Existing> item instead of calling a constructor.
Also, the example sequence located here shows this:
<TestStandPublic>\Examples\Demos\Computer Motherboard Test\DotNET\Computer Motherboard Test Sequence.seq
Hope this helps,
-Doug
07-01-2016 10:03 AM
Hi Doug,
Thanks for the reply. With your explanation and a little further guidance from NI directly, I now have my code working. The changes make sense.
Much appreciated.
Regards
Chris