Jump to content
THIS IS THE TEST SITE OF EUROBRICKS! ×
THIS IS THE TEST SITE OF EUROBRICKS!

Recommended Posts

Posted (edited)
2 hours ago, Bliss said:

But I wonder if the logo "onfor 20" will prevent any following instructions to execute unti the 2.0 delay has elapsed.

Hello and Yes.  They are blocking commands.

But you got me curious, so I started paging through the Reference Guide again (the list of "primitives" are alphabetical) and found a couple that reference parallel processes.

The one you are probably interested in is launch

This test will run both the sound and lamp at the same time for 5 seconds

to test

launch [tto "SoundC setleft onfor 50]
launch [tto "LampB setleft onfor 50]

 

2 hours ago, Bliss said:

RCX, is an integrated PLC that has it's own Local I/O's (Not remote).

Despite owning 10 of these little yellow bricks (enough for short yellow brick road to the wizard of LEGO) I really haven't done anything with them (I really didn't like the blocky method, and get bogged down in all the alternatives, of which I can never seem to find the right firmware for an example I am interested in).

Anyhow, I digress...  I believe the RCX can follow both internal and remote commands at same time.  I know the IR remote control (and tower) can start/stop programs and directly control outputs.  They can also communicate between themselves via IR (but not sure if that requires alternate firmware or not).

Edited by Gunners TekZone
  • Replies 446
  • Created
  • Last Reply

Top Posters In This Topic

Posted
2 hours ago, Bliss said:

...

But as far as I remember, the serial/Infrared link between the PC and the RCX was only to send a program to the CPU inside the RCX (and to update/upload the firmware). 
...

Hello,

When you check the Firmware-Command-Overview that is part of the SDK (can be downloaded on Philos' Page) then for each command there is stated if this Command is "Direct", or "Program" or both.
So most commands can be used inside a to RCX downloaded Program or to be executed imediate after IR-Reception. Therefore a "Reply" is usually specified, that in a Program-Execution is not needed.

Jo

Posted
On 1/2/2025 at 3:33 PM, Bliss said:

- You probably can use many Python modules (import), for now I just used import time in my examples.

- You do not need to install Python.  The exe is supposed to include all dependant libraries. 

Hello.

I am attempting to convert a MQTT script I have for use on my BuildHat (a LEGO Powered Up adapter for the Raspberry Pi) to the Interface-B (using its inputs/outputs instead of the BuildHat ones)... Because why not :D

I have all the required modules already installed on my PC (and Python 3.10.4)... And tested good using Thonny.

However, I instantly ran into import issues...

Lego1: Opening Serial Port COM1...
Lego1: Serial Port COM1 Opened.
Lego1: Sending initialization messsage on COM1...
Lego1: Reading initialization answer from COM1...
Lego1: Running on COM1
No module named 'random'

I also require paho.mqtt ... but as random should already be part of the base Python, and still not loading, I suspect there is more going on. 

Posted
2 hours ago, Gunners TekZone said:

I believe the RCX can follow both internal and remote commands at same time. 

 

Sure it does! My entire train layout relies on that. For example, two trains have RCX' as controller on the engine or one of the carriages. I have a video on YT (https://www.youtube.com/watch?v=wTP6WtcnQbg). I can change PID parameter settings on the fly, when the trains are running, via messaging. There are a couple of tasks running on the RCX, one is for IR message handling (OK, I changed that to RF, but the protocol is exactly the same), one is for the PID speed control (there is a rotation sensor on the engine or carriage) and one is the main control program. This is done in NQC = LEGO byte codes. Without PID, they run on original LEGO firmware, with PID to work properly, the RobotC firmware is required. These are all currently available on the net.

Best,
Thorsten

 

 

Posted (edited)
8 hours ago, Gunners TekZone said:

Hello.

I am attempting to convert a MQTT script I have for use on my BuildHat (a LEGO Powered Up adapter for the Raspberry Pi) to the Interface-B (using its inputs/outputs instead of the BuildHat ones)... Because why not :D

I have all the required modules already installed on my PC (and Python 3.10.4)... And tested good using Thonny.

However, I instantly ran into import issues...


Lego1: Opening Serial Port COM1...
Lego1: Serial Port COM1 Opened.
Lego1: Sending initialization messsage on COM1...
Lego1: Reading initialization answer from COM1...
Lego1: Running on COM1
No module named 'random'

I also require paho.mqtt ... but as random should already be part of the base Python, and still not loading, I suspect there is more going on. 

Seems that the Lego script B program does not embed this module.  (I'msearching if it is even possible to embed some python modules in the exe...)

But from what I found out, In the publish folder of Lego Script B, where the exe is also located, there is a lib sub folder with a bunch of .py modules...
So, you could do this:

import sys
sys.path.append(".\lib")
import random
print(random.random())

 

Edited by Bliss
Posted (edited)

Allright... I deleted the prior contents of this post as it was getting too long as I made discoveries.

Long story still long... and ongoing... I am finding issues and workarounds "porting" functional code from Thonny to Interface B Scripting.  Both running on my Win10 PC.

BUT... it is such a tedious job, discovering issues, blindly guessing at solutions (some even worked) and generally embedding keycaps into my forehead, that I will just wait until I either figure it out and post the resulting Interface-B MQTT code... or give up :P

Meanwhile... this is the code I have running in Thonny (but obviously not doing much of anything in the physical/LEGO world).

print("Start script")
import sys
sys.path.append("C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages")
import random
from paho.mqtt import client as mqtt_client
 
##############################################################################
#                         GLOBAL VARIABLES / SETUP                           #
##############################################################################
print("MQTT Start")
# -----------------------#
# MQTT Configuration    #
# -----------------------#
broker = '192.168.0.17'     # IP of your broker
port = 1883                 # Port for MQTT (default is 1883)
topic = "test/relay"        # Topic to subscribe/publish to
 
# We create a random ID just so multiple clients on the same broker
# don't stomp on each other:
client_id = f'subscribe-{random.randint(0, 100)}'
 
# Username / password for the broker (if needed)
username = 'YOURUSERNAME'
password = 'YOURPASSWORD'
 
# -----------------------#
# Interface-B Configuration #
# -----------------------#
#print("LEGO config")
#Lego1.ComPort="COM1"
#Lego1.StartLego()
#Lego1.SetPow[out.D] = 7


# This will indicate the relay state:
buttonFlag = 0
 
# -----------------------#
# The Big Global Client  #
# -----------------------#
#
# We declare 'client' here. We'll fill it in `connect_mqtt()`.
# This is so that any function that needs it can do `global client`.
client = None
 
 
##############################################################################
#                            MQTT SETUP FUNCTIONS                            #
##############################################################################
 
def connect_mqtt():
    """
    Connects to the MQTT broker exactly once and assigns the resulting
    mqtt_client.Client instance to the global 'client'.
    Returns the same client, but we also store it in the global variable.
    """
    global client  # Tells Python we're referring to the global variable above.
 
    def on_connect(client, userdata, flags, rc):
        """
        Callback that fires when a connection to the broker is established.
        """
        if rc == 0:
            print("Connected to MQTT Broker!")
            # As an example, we publish a greeting on a different topic:
            client.publish("test/time", "HI from PI!")
        else:
            print(f"Failed to connect. Return code={rc}")
 
    # Actually create the client object
    client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id)
    #client = mqtt_client.Client(client_id)
 
    # Assign credentials
    client.username_pw_set(username, password)
 
    # Assign the on_connect callback
    client.on_connect = on_connect
 
    # Connect to the broker
    client.connect(broker, port)
 
    return client
 
 
def subscribe():
    """
    Sets up subscription to a topic and defines how incoming messages are handled.
    """
    global client  # We'll need the client to call subscribe on it
 
    def on_message(client, userdata, msg):
        """
        Callback that fires when a message arrives on a topic we subscribed to.
        """
        print(f"Received `{msg.payload.decode()}` from `{msg.topic}` topic")
        
        # If the received payload is '1', turn the port ON else OFF
        # (Adjust logic if your messages are strings other than '1'/'0')
        if msg.payload.decode() == '1':
            #Lego1.SetOn[out.D] = True
            print("Light ON")
        else:
            #Lego1.SetOn[out.D] = False
            print("Light OFF")
 
    # Subscribe to the desired topic
    client.subscribe(topic)
 
    # Assign the on_message callback
    client.on_message = on_message
 
 
 ##############################################################################
#                       FUNCTIONS TO PUBLISH MESSAGES                        #
##############################################################################
 
def publish_message():
    """
    Publishes the current state of 'buttonFlag' to the MQTT broker.
    """
    global client  # We'll need the global client
    print("Publishing message:", buttonFlag)
    client.publish(topic, buttonFlag)
 
 
##############################################################################
#                        BUILDHAT BUTTON-RELATED CODE                        #
##############################################################################
 
def handle_pressed():
    """
    Called automatically when the button on port '1' is pressed.
    We'll flip the buttonFlag from 1 to 0 or 0 to 1 and then publish.
    """
    global buttonFlag  # Tells Python to use the global variable    
#if Lego1.InOn[1]:
    print("Button Pressed!")
    # Flip the state of buttonFlag
    if buttonFlag == 1:
        buttonFlag = 0
        #Lego1.SetOn[out.D] = True
        print("Light ON")
    else:
        buttonFlag = 1
        #Lego1.SetOn[out.D] = False
        print("Light OFF")
 
        # Now publish our updated buttonFlag via MQTT
        publish_message()
 
 
##############################################################################
#                             MAIN LOOP (run)                                #
##############################################################################
 
def run():
    """
    Main entry-point for our script. Connect to MQTT, subscribe, 
    and start the loop forever.
    """
    global client  # We'll store the client in the global variable
    
    # 1. Connect once
    connect_mqtt()
    
    # 2. Subscribe once
    subscribe()
    
    # 3. Start an infinite loop to process messages and keep the connection open
    client.loop_forever()
 
 
##############################################################################
#                          START THE PROGRAM HERE                            #
##############################################################################
 
if __name__ == '__main__':
    run()

 

And these are the issues and solutions I have found so far...


future feature is not defined:annotations  is "fixed" but this change:

from paho.mqtt import client as mqtt_client

to

import paho.mqtt

Who knows if this causes other issues later on... I don't :P

 

One of the many occurances of "No error, but script just stalls" is fixed by this change:

if __name__ == '__main__':
    run()

to this

while not cancellationToken.IsCancellationRequested:
    run()

 

And finally... so far... This is where I (and the script, without error) have stalled out:

I tried both versions... the uncommented one is a fix due a "Paho MQTT 'Unsupported callback API version' error"... Google is my only friend :D

    # Actually create the client object
    client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id)
    #client = mqtt_client.Client(client_id)

I don't know if this stalling out issue is because of the initial import "fix" or perhaps the Interface B Scripting program is not allowing internet access??

Anyhow, that's all for now folks!

Edited by Gunners TekZone
spelling & grammar, when I catch it. And total rewrites when needed :)
Posted
4 hours ago, Gunners TekZone said:

What version of Python is your script running?  Or is there another explanation of this future feature is not defined:annotations message?

Actually, I'm using IronPython and I'm not sure what version of official Python it is using.

Posted
1 minute ago, Bliss said:

Actually, I'm using IronPython and I'm not sure what version of official Python it is using.

Ah, thanks... I eventually saw the IronPython bit, but turns out the version didn't seem to be the issue.  I edited my prior post explaining such...

Posted (edited)

I made a big change in the LegoScriptB program and the previous Examples will not work anymore.

Please, use the examples provided in the README file.

New version LegoScriptB

Before:

Lego1.SetOn[3] = True  
if Lego1.InOn == True:

Now:

Lego1.Out[3].On = True
if Lego1.Inp[1].On:

This allow us to do the following:
MotorA = Lego1.Out[out.A]
Touch1 = Lego1.Inp[1]
Example:

import time
Lego1.ComPort="COM14"
Lego1.StartLego()
time.sleep(1)

MotorA = Lego1.Out[out.A]
Touch1 = Lego1.Inp[1]

MotorA.Pow = 7
MotorA.Dir = False

while not cancellationToken.IsCancellationRequested:
	MotorA.On = Touch1.On
	time.sleep(0.020)

 

I also added a method in the outputs calle OnFor(Delay) Delay = 0-255 tenth of second.  Lego1.Out[1].OnFor(20) will activate Output A of Lego1 for 2 seconds then deactivate it.
It will not block the program flow, if you want to block, use after time.sleep(2) to wait 2 sec.

 

Edited by Bliss
Posted
31 minutes ago, Bliss said:

I made a big change in the LegoScriptB program

Um... unless I am getting too tired... this latest version no longer allows...

import sys
sys.path.append(...)

It seems to just ignore it and claim it can't find a module (in my case random, again, and so on)

print("Start script")
import sys
sys.path.append("C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages")
import random
import paho.mqtt

Output Log:

No module named 'random'
Start script

 

Posted (edited)
12 minutes ago, Gunners TekZone said:

Um... unless I am getting too tired... this latest version no longer allows...

It still work for me.

Is random.py in "C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages"?

Should C:\\ be C:\ ?

For me random.py is in ...AppData\Local\Programs\Python\Python313\Lib\.

 

Edited by Bliss
Posted
1 hour ago, Bliss said:

Should C:\\ be C:\ ?

No.  That is the solution to this error:

 

  File "C:\Users\Gunner\Desktop\Interface-B MQTT Test.py", line 3
    sys.path.append("C:\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages")
                                                                                               ^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

 

1 hour ago, Bliss said:

It still work for me.

Is random.py in "C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages"?

It was working with your prior version... I chose that path because all other modules I might use, like paho.mqtt, is also there for when working with other Python editors.

 

Posted (edited)
6 minutes ago, Gunners TekZone said:

It was working with your prior version... I chose that path because all other modules I might use, like paho.mqtt, is also there for when working with other Python editors.

This should work no?

import sys
sys.path.append("C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages")
sys.path.append("C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib")
import random
import paho.mqtt

OR MAYBE JUST:

import sys
sys.path.append("C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib")
import random
import paho.mqtt

 

Edited by Bliss
Posted (edited)

That is the correct path, and did work on your prior (to the syntax changes, etc.) version.  As per your solution to the original "No module named 'random'" issue.

But no worries... I realised that trying to do something rather fansnazy like MQTT with the Interface-B, while you are still developing and making changes, might not be a good idea yet :D  So I will go back to the semi-autonomous train port, from TC LOGO to python code... No fancy stuff there, that I can't understand without hours of Googling... Hah!

 

Edited by Gunners TekZone
Posted (edited)
5 hours ago, Gunners TekZone said:

... So I will go back to the semi-autonomous train port, from TC LOGO to python code... No fancy stuff there, that I can't understand without hours of Googling... Hah!

Here is an attempt to make a script for the first part of your train program (9V train part) .

In that script, You have to change the com port, CN_Auto_Speed (I set it to 7), and the LightSp = 550 (Light Setpoint).

The light setpoint is very different than you program which is Light < 70.  Also, this appears to be reverse than the Value I programmed for the inputs.
I suspect that ControlLab software/TC Logo is using a special calculation for the Light sensor.
Me, I just take the raw 10 bits value...

So might be a good Idea to use the LegoDemoB program to test the your Light8 and Light7 value when a train block the sensor and the value when it clrears the sensor.  Then adjust the LightSp variable accordingly.

So, in "while not C() and Light8.Val < LightSp :" ,  when Sensor is clear (sees the light), value is around 480 (For me), and the code is looping, and when Sensor is blocked, it gives a value over 620.  So the loop will end when Sensor has a value > LightSp (550)

import time
Lego1.ComPort="COM14"
Lego1.StartLego()
time.sleep(1)

C=lambda:cancellationToken.IsCancellationRequested

LampB = Lego1.Out[out.B]
SoundC = Lego1.Out[out.C]
MotorD = Lego1.Out[out.D]
LampF = Lego1.Out[out.F]
MotorH = Lego1.Out[out.H]

Touch4 = Lego1.Inp[4]
Light7 = Lego1.Inp[7]
Light8 = Lego1.Inp[8]

LampB.Dir=True
LampB.On=True
MotorD.Dir=True
MotorD.OnFor(20)
time.sleep(2)
SoundC.Dir=True
SoundC.OnFor(20)
time.sleep(2)

CN_Auto_Speed=7
LightSp = 550 # Light Setpoint

while not C():
	MotorH.Dir = True
	MotorH.Pow = CN_Auto_Speed
	MotorH.On = True
	while not C() and not Touch4.On:
		pass
	MotorH.On = False
	LampF.On = True
	time.sleep(1)
	SoundC.Dir=False
	SoundC.On=True
	MotorH.Dir = False
	MotorH.On = True
	# backup until trigger light sensor
	while not C() and Light8.Val < LightSp :
		pass
	MotorH.On = False
	LampF.On = False
	SoundC.On=False
	MotorD.Dir=False
	MotorD.OnFor(20)
	time.sleep(2)
	break

LampB.On=False

 

5 hours ago, Gunners TekZone said:

That is the correct path and did work on your prior version (as per your solution to the original "No module named 'random'" issue).

Maybe it is because you tried first the code 

import sys
sys.path.append(".\lib")

And it worked .

Then you change the path but the last one (.\lib) was still in memory (Once the parh is appended, i suspect it remains in the session even if you modify the script or clear the script textbox windows and run the script again with a new path append.

But shuting down the LegoSriptB program completly must reset the memory... and when you run it again, or a new version, it will not find the random.py if you only append the ...site-packages folder because random.py does not exist in this folder.

Edited by Bliss
Posted (edited)
51 minutes ago, Bliss said:

Then you change the path but the last one (.\lib) was still in memory (Once the parh is appended, i suspect it remains in the session even if you modify the script or clear the script textbox windows and run the script again with a new path append.

I don't think so... After getting the random module to work, I still needed to get the paho.mqtt module to import.  And that ended up having me uninstall all older versions of Python on my PC, reinstall the latest version, along with the paho.mqtt, and find the path that worked for that new version as well.  That, and I most likely had shut down your program at least once, while shuffling stuff around over the next few hours of troubleshooting :)

Anyhow... I needed a break from trying to figure out if it wasn't connecting to my broker because...

A) Needing to make the change from: from paho.mqtt import client as mqtt_client (which didn't work on your program) to import paho.mqtt (which did work).  But who knows how that changed the client code as written.

B) Or if the script simply can't link to the networking through your program... But can't supply any error, as you had stated, and I discovered, is currently limited to minimal, or simply nothing.

I suspected A) but without errors to guide, I was at a loss to proceed further.

Edited by Gunners TekZone
Posted
1 hour ago, Bliss said:

Here is an attempt to make a script for the first part of your train program (9V train part) .

Nice.  It worked as is, and without the hardware to test on :pir-triumph:

The light values were arbitrary anyhow, it worked as long as there was a significant change between "blocked from external light source" and "not blocked from external light source".

Posted (edited)
2 hours ago, Gunners TekZone said:
4 hours ago, Bliss said:

It still work for me.

Is random.py in "C:\\Users\Gunner\AppData\Local\Programs\Python\Python313\Lib\site-packages"?

It was working with your prior version

Out of a combo of curiosity and a niggling of self doubt :P  I restored the zipped "prior version" from my recycle bin.  And YES!!! I am not totally crazy... That path and loading of all the modules worked again.
I don't know what else to say?  The timestamp on the LegoScriptB.exe in that script folder shows January ‎3, ‎2025, ‏‎3:51:26 PM if that helps narrow down the one I am referring too.

 

Meanwhile...

1 hour ago, Gunners TekZone said:

A) Needing to make the change from: from paho.mqtt import client as mqtt_client (which didn't work on your program) to import paho.mqtt (which did work).  But who knows how that changed the client code as written.

 

1 hour ago, Gunners TekZone said:

I suspected A) but without errors to guide, I was at a loss to proceed further.

I realised that I could make the same change on my technically functional Thonny version and see what, if any, errors it makes.  

  File "C:\Users\Gunner\Desktop\Interface-B MQTT Test.py", line 73, in connect_mqtt
    client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id)
NameError: name 'mqtt_client' is not defined

Line 73 being: client = mqtt_client.Client(mqtt_client.CallbackAPIVersion.VERSION1, client_id)

I don't know why from paho.mqtt import client as mqtt_client throws this error: future feature is not defined:annotations in IronPython, but it is messing up my brain cells with confusion :pir-murder:

 

And... Off to sleep... It has been a long many hours learning me some Python... Partial results are better than nothing I guess.

Edited by Gunners TekZone
Posted (edited)
11 hours ago, Gunners TekZone said:

And... Off to sleep... It has been a long many hours learning me some Python... Partial results are better than nothing I guess.

Anyway, I think you're right, IronPython integration to C# is probably very minimum...

But since you aready have Python 3.X on your PC, you could do the other way around...

Use Lego directly into python...

You could use the Dacta Python program that you found here:  https://www.shamlian.net/projects/dacta/index.html
I did not personnaly had time to look at it.  But I'm guessing it might work very well.

OR

You could use my Lego DLL directly in Python but there are few step to achieve this.
I did some test and I will describe the steps I followed.
I'm still very newbie at Python.
I compiled the Lego Interface B program as a Class Library (DLL).  Only the part that manages the Interface B, No IronPython.  At first it did not work.  To make it work, I had to compile it using .Net Framework 4.7...

1. You have to intall Python Net from the CLI (Command Line Interface, I just opened a Dos Command Window)
You type in the command line:

pip install pythonnet

and press enter.  Make sure it has installed properly.

2. Download my LegoClassB: Link to my LegoClassB

3. In python IDLE Shell or Python CLI, enter the command:  

import clr


If pythonnet installed correctly there should be NO Error.

4.  Now enter the following:  (Please note the small "r" at the beginning of the path to tell to use raw string or you may get a problem because of the use of "\")
LegoClassB is the name of the DLL without the extension DLL... 

clr.AddReference(r"C:\...\LegoClassB\bin\Release\LegoClassB")

If things goes well, Python will respond with:  <System.Reflection.RuntimeAssembly object at 0x000001BEF230C9C0>

5. Enter the following:

from LegoClassB import LegoInterfaceB

if there are no Errors, then you are in business.

6.  Enter the following one at a time to declare the Lego1 Interface and configure the com port, start and try (Do the same for Lego2, Lego3, Lego4, Lego999 lol, but first lets make it work with Lego1)

Lego1 = LegoInterfaceB()
Lego1.ComPort="COM1"
Lego1.StartLego()
print(Lego1.IsRunning)
Lego1.Out[1].On=True

Let me know how it goes.

 

I think that you should have more luck with having MQTT to run with Lego box at the same time...
But still, there might be some surprises...

Edited by Bliss
Posted (edited)
37 minutes ago, Bliss said:

But since you aready have Python 3.X on your PC, you could do the other way around...

Use Lego directly into python...

You could use the Dacta Python program that you found here:  https://www.shamlian.net/projects/dacta/index.html
I did not personnaly had time to look at it.  But I'm guessing it might work very well.

Too funny... That is what I have been wanting to suggest to you, since I discovered you were using Python in your scripting application.

But I didn't want to detract from your vision, or whatever motivates you.  That said, Yes, I really want to see a proper importable Python module for use with vintage LEGO over a users choice of IDE.  And in this case the Interface-B seems the best primary option, but possibly something that will also work (perhaps in parallel with the Interface-B??) to remotely control RCX, possibly (if needed) with modified firmware that can act to identify individual units that communicate to Python via IR.  

I did look at that Shamlian code myself, many weeks ago.  The module does seem to have all the input/output code, and seems well commented, but I still wasn't able to make enough headway to understanding it, without some functional examples to work off of that supplied context & syntax for commands, ext.  The one included example seems mostly useless, and doesn't stay online anyhow.   I didn't bother pursuing it as it seems like it was a one-shot attempt and hasn't been in development for almost 10 years, so probably lots of issues with more current versions of Python.

37 minutes ago, Bliss said:

You could use my Lego DLL directly in Python but there are few step to achieve this.
I did some test and I will describe the steps I followed.

Thanks for this...

37 minutes ago, Bliss said:

I'm still very newbie at Python.

But you are far ahead of myself :)  ... I will definitely see what I can do with your DLL (DLL, class, module??  See I don't even understand the proper terminology, Hah!)

Edited by Gunners TekZone
Posted
32 minutes ago, Gunners TekZone said:

But you are far ahead of myself :)  ... I will definitely see what I can do with your DLL (DLL, class, module??  See I don't even understand the proper terminology, Hah!)

The lego Interface B code (Communication, Reading continuously and Decoding of Inputs and writing commands) is all done in what they call a C# Class which you can explore de code by opening the LegoInterfaceB.cs with notepad or Notepad++.

LegoInterfaceB.cs is located in the complete zip package directly in the root folder (Ex. LegoClassB folder)

When we compile a class it becomes a DLL (Library) and even in the LegoSciptB and LegoDemoB, there is a LegoInterfaceB.DLL but I tried to import it in Python and didn't work...  I had to compile with a different .Net...

 

 

Posted (edited)

Thanks for the info.

FYI, so far I haven't been able to make anything run in Thonny, thanks to NOT being able to import clr (as I understand it, it allows .net to play with Python).

I only have the one version of Python installed, and windows path point correctly to it...

Traceback (most recent call last):
  File "C:\Users\Gunner\Desktop\LEGO_IntB_IDE_Test.py", line 1, in <module>
    import clr
ModuleNotFoundError: No module named 'clr'

The Googling shall continue... :pir-look:

Edited by Gunners TekZone
I deleted a bunch of rambling, as this isn't a "Help with Python" topic
Posted
3 hours ago, Bliss said:

Let me know how it goes.

FYI... Using the CLI, I run into times when nothing happens.  But I have found simply typing Lego1.IsRunning without the print() will show True or False.  When false, it seems though only way to get it back running is to close down the CLI and start over.

Ideas?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.

Announcements

  • THIS IS THE TEST SITE OF EUROBRICKS!

×
×
  • Create New...