Skip to content

Script for operator panel exchange

1 to 6 of 6
Posted March 2, 2018· Edited March 2, 2018

Hey all!

I have made a real operator console for control nolimits,
But my program is in Python, and my key enter is nottaken in account.

It's possible with script , to communicate with my program in Python ( Send and receive ) , Or the console (with Arduino Mega 2560 ) ?

You can communicate with NL2 using its telemetry server. Here's a quick demonstration how this can be done in Python:

The demonstration Python program text:

import socket
import struct

TCP_IP = '127.0.0.1'
TCP_PORT = 15151
RECEIVE_BUFFER_SIZE = 1024

# see https://docs.python.org/3/library/struct.html#format-characters
# and
# NoLimits 2/help/pages/telemetry.html#messageformat
no_data_message_struct = struct.Struct('!cHIHc')

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as nl2_connection:
    nl2_connection.connect((TCP_IP, TCP_PORT))

    # idle message (id 0) with request ID 42
    my_message = no_data_message_struct.pack(b'N', 0, 42, 0, b'L')

    nl2_connection.send(my_message)
    received_data = nl2_connection.recv(RECEIVE_BUFFER_SIZE)

_, id, request_id, _, _ = no_data_message_struct.unpack(received_data)
print("raw", repr(received_data))
print("message id", id)
print("request id", request_id)

If you want to communicate with a NL2 script, that's not possible by using the telemetry server for now, but maybe in the future.

Hey! I saw your code and was wondering how i can keep the connection live and read the state of dispatch, gates, etc? It connects then disconnects from NL2 immediately.

Can this be put onto a Ardunio to receive station status bits from NL2 now since they have added a few into the scripting library?

bestdani posted on March 2nd, 2018

You can communicate with NL2 using its telemetry server. Here's a quick demonstration how this can be done in Python:

The demonstration Python program text:

import socket
import struct

TCP_IP = '127.0.0.1'
TCP_PORT = 15151
RECEIVE_BUFFER_SIZE = 1024

# see https://docs.python.org/3/library/struct.html#format-characters
# and
# NoLimits 2/help/pages/telemetry.html#messageformat
no_data_message_struct = struct.Struct('!cHIHc')

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as nl2_connection:
    nl2_connection.connect((TCP_IP, TCP_PORT))

    # idle message (id 0) with request ID 42
    my_message = no_data_message_struct.pack(b'N', 0, 42, 0, b'L')

    nl2_connection.send(my_message)
    received_data = nl2_connection.recv(RECEIVE_BUFFER_SIZE)

_, id, request_id, _, _ = no_data_message_struct.unpack(received_data)
print("raw", repr(received_data))
print("message id", id)
print("request id", request_id)

If you want to communicate with a NL2 script, that's not possible by using the telemetry server for now, but maybe in the future.

1 to 6 of 6