Jump to content

As of July 17, 2015, the LabJack forums here at forums.labjack.com are shut down. New registrations, topics, and replies are disabled. All forums are in a read-only state for archive purposes.

Please visit our current forums at labjack.com/forums to view and make new posts. To post on the current forums, use your labjack.com login account. Your old LabJack forums login credentials have been retired. There are no longer separate logins for labjack.com and LabJack forums.


Photo

LJSocket Port forwarding


  • Please log in to reply
4 replies to this topic

#1 Rezuan Asrah

Rezuan Asrah
  • Members
  • 3 posts

Posted 23 September 2010 - 08:38 AM

Hey guys, I'm trying to reverse port 6000 through SSH tunnel on a remote host, so that from the remote host, I'll be able to connect through LJSocket. Here's the setup :- From client ( which the U3 is installed ), I create SSH tunnel using this command :- ssh remote-host -R6371:localhost:22 -R60001:localhost:6000 So on the remote-host, I open up python terminal and type this :- import u3 d = u3.U3( LJSocket = 'localhost:60001' ) Here's where I got stucked. Is it possible to even reverse the port 6000 ? Here's the traceback error :- Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/python2.5/site-packages/u3.py", line 81, in __init__ self.open(**kargs) File "/usr/lib/python2.5/site-packages/u3.py", line 116, in open Device.open(self, 3, firstFound = firstFound, serial = serial, localId = localId, devNumber = devNumber, handleOnly = handleOnly, LJSocket = LJSocket ) File "/usr/lib/python2.5/site-packages/LabJackPython.py", line 572, in open d = openLabJack(devType, ct, handleOnly = handleOnly, LJSocket = LJSocket) File "/usr/lib/python2.5/site-packages/LabJackPython.py", line 1395, in openLabJack handle = _openLabJackUsingLJSocket(deviceType, firstFound, pAddress, LJSocket, handleOnly ) File "/usr/lib/python2.5/site-packages/LabJackPython.py", line 1225, in _openLabJackUsingLJSocket handle = LJSocketHandle(ip, port, deviceType, firstFound, pAddress) File "/usr/lib/python2.5/site-packages/LabJackPython.py", line 2841, in __init__ raise LabJackException(ec = LJE_LABJACK_NOT_FOUND, errorString = "Couldn't connect to a LabJack at %s:%s. The error was: %s" % (ipAddress, port, str(e))) LabJackPython.LabJackException: Couldn't connect to a LabJack at localhost:6000. The error was: (111, 'Connection refused')

#2 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 23 September 2010 - 09:48 AM

LJSocket works like this:

On port 6000, you can send the "SCAN" command to get a listing of all the devices that it has open. This listing contains the product id (3 = U3, 6 = U6), a Command/Response (C/R) port, a Modbus port, a spontaneous data port, local id, and serial number.

Here's an example scan with 1 U3 connected:
scan
OK 1
3 6001 5021 x 5 32003XXXX

In this example, I have 1 U3, with local id 5, which has a C/R port open on 6001, and a Modbus port open on 5021.

In order to send commands to this device, LabJackPython needs to connect to port 6001 and 5021. It will send regular C/R commands (Feedback, ConfigU3) to 6001, and Modbus commands to 5021 (Read/Write Register).

What was happening in your case, was that it was able to call scan, but then couldn't open any of the device's ports. You instead could run a command like this:

ssh -R 60001:localhost:6000 -R 6001:localhost:6001 -R 5021:localhost:5021 Remote-host

But that will only work if you have one device plugged in. If you think you'll have more devices connected, you can add more -R's.

#3 Rezuan Asrah

Rezuan Asrah
  • Members
  • 3 posts

Posted 23 September 2010 - 10:03 AM

Thanks for the reply!

But I just tried to reverse other ports such as 6001 and 5021 and it didn't work.

In my situation, there is only one device that will be plugged in.

LJSocket works like this:

On port 6000, you can send the "SCAN" command to get a listing of all the devices that it has open. This listing contains the product id (3 = U3, 6 = U6), a Command/Response (C/R) port, a Modbus port, a spontaneous data port, local id, and serial number.

Here's an example scan with 1 U3 connected:

scan
OK 1
3 6001 5021 x 5 32003XXXX

In this example, I have 1 U3, with local id 5, which has a C/R port open on 6001, and a Modbus port open on 5021.

In order to send commands to this device, LabJackPython needs to connect to port 6001 and 5021. It will send regular C/R commands (Feedback, ConfigU3) to 6001, and Modbus commands to 5021 (Read/Write Register).

What was happening in your case, was that it was able to call scan, but then couldn't open any of the device's ports. You instead could run a command like this:

ssh -R 60001:localhost:6000 -R 6001:localhost:6001 -R 5021:localhost:5021 Remote-host

But that will only work if you have one device plugged in. If you think you'll have more devices connected, you can add more -R's.



#4 Rezuan Asrah

Rezuan Asrah
  • Members
  • 3 posts

Posted 23 September 2010 - 10:22 AM

Hey it works!

Actually the port number was 6002 and 5022. And the pattern is that every connection will increase the port number that it should listen to.

Next question would be, how would you send that "SCAN" command as a oneliner?

LJSocket works like this:

On port 6000, you can send the "SCAN" command to get a listing of all the devices that it has open. This listing contains the product id (3 = U3, 6 = U6), a Command/Response (C/R) port, a Modbus port, a spontaneous data port, local id, and serial number.

Here's an example scan with 1 U3 connected:

scan
OK 1
3 6001 5021 x 5 32003XXXX

In this example, I have 1 U3, with local id 5, which has a C/R port open on 6001, and a Modbus port open on 5021.

In order to send commands to this device, LabJackPython needs to connect to port 6001 and 5021. It will send regular C/R commands (Feedback, ConfigU3) to 6001, and Modbus commands to 5021 (Read/Write Register).

What was happening in your case, was that it was able to call scan, but then couldn't open any of the device's ports. You instead could run a command like this:

ssh -R 60001:localhost:6000 -R 6001:localhost:6001 -R 5021:localhost:5021 Remote-host

But that will only work if you have one device plugged in. If you think you'll have more devices connected, you can add more -R's.



#5 LabJack Support

LabJack Support
  • Admin
  • 8677 posts

Posted 23 September 2010 - 10:36 AM

You can test your connection with telnet. After running the SSH command, type the following into the remote host:

$ telnet localhost 60001

if the response looks like this:

Trying ::1...
Connected to localhost.
Escape character is '^]'.

then, the tunnel to LJSocket's main port (6000) is working. Try typing "scan" and pressing Enter. This should give you a message like the one I posted earlier, then exit.

Check the ports in the scan match the ports in your -Rs.

Next, test the C/R port with telnet:

[code=auto:0]
$ telnet localhost 6001
[code=auto:0]

If that works, then check the Modbus port. To exit telnet, hold control and press the ']' key, then press enter. The prompt should change to "telnet> ". From there, type "quit" and press enter.

Try these tests out. It will give us a better idea of where we are failing.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users