Jump to content

Recommended Posts

Posted
8 minutes ago, Gunners TekZone said:

The slider positions remain after a start/stop action (Just the visual, the actual settings reset to full)
 

Good find.  Will try to fix later on.

Actually for this project, Controlling one box only would be enough as you found out that you can run more than one instance of the program allowing connecting to many lego interface B independly.
So I do not intend to add a Lego 3, at least not now.  (Maybe I should even remove the second Lego from this demo project... )

However, for my other project, yes, I can eventually allow more than 2...

Thank you.

Posted

@Gunners TekZone,

I updated the dropbox.

For the slider position vs start/stop of the lego box, after a stop, it will reset to max, but when starting again the box, the slider will come back to the last position but not if you activate an output, it will use this setting not the max like before.
If it is preferable, i could also after a stop reset all slider to the max and keep the max when clicking the start again.
I'm talking here about start/stop of the box in a same session.  If the program is shutdown and re-executed, sliders will initialize at max.

I also found another bug:  If there is NO com port on the PC, the program do the ghost thing because there was of an error not displayed but shown in the windows log events.
The program was initialzing with first com port, item 0 but there was no item.
Now it is allowed to start the program without com port in the PC but the combo box does not refresh if you plug a serial usb adapter while the program is running.  Have to restart the program...  I guess would need a refresh com list button eventually...

 

Bliss

 

Posted (edited)

Hello all.

Happy new year!

Here is a Draft of my C# project that embed IronPython as an attempt to make a programming environment for the Lego Interface B.

Dropbox link : LegoScriptB for Programming Lego Interface B.

It is based on my previous LegoDemoB project except that I removed all Lego Box Command Buttons and Status information.
However, I left the Serial Start Stop buttons so you can still use them but it is not necessary as you can start and stop lego box from the script textbox.

Features:
- You can connect and use up to three (3) lego interface B.  You can use Lego1, Lego2, Lego3 Variables.
- Upon exiting the software, the last script in the textbox is saved.
- In this version, there is no way to save to and load from files.
- For now, I use Notepad++ to save some scripts in one file that I copy paste the parts I need in the Script textbox...
- You probably can use many Python modules (import), for now I just used import time in my examples.
- I will provide a text file eventually with all the Methods and Properties of the Lego variable.
- You do not need to install Python.  The exe is supposed to include all dependant libraries. 
- If your script has errors, the output box does not give very detailed msg.  For example, it you forget a ":" colon for while or if, it will only log "invalid syntax".
I'm trying to find a way to have more detailed error messages.
I would suggest you try smaller parts of your code as it grows...
Usual mistakes are lowercase, uppercase, indents, missing colon...

 

How to use:
- Be careful, Python is case sensitive (Lego1, True, False, print, while, etc)
- In python, Indentation if VERY important.
- You may comment your script with "#" symbol followed by you comment.
- You enter your script in the "Enter you Python Script Here:" textbox.
- To execute the script, click "RUN Script" button.
- The Run Script button will be disabled during the execution of you script program.
- The "STOP Loop Scipt" button is provided to allow to gracefully end an infinite While Loop.  (See Example)
- The use of while loop is tricky as you can be stucked in an infinite loop.  You will have to shut down the whole Software.
Please always use "while not cancellationToken.IsCancellationRequested:" rather than "while True:" 

Lego Variable Methods:
-  StopLego() : Stop Serial Communication with Lego box.  Same as the STOP Button.  Ex.: Lego1.StopLego()
- StartLego() : Start Serial Communication with the Lgo box.  Same as the START Button. (You must have set a valid COM port prior to use this method)  Ex. Lego1.StartLego()

Lego Variable Properties:
- ComPort : Read/Write (R/W) COM port. Ex.: Lego1.ComPort = "COM14"
- SetOn[OutPortNo] : (R/W),  Where OutPortNo = 1 to 8 representing Output A to H.  Ex.:   Lego1.SetON[1] = True # Activates Output A.  Lego1.SetOn[1] = False # Deactivates (BRAKES) Output A.
- SetFree[OutPortNo]: (R/W),  Where OutPortNo = 1 to 8 representing Output A to H.  Ex.:  Lego1.SetFree[1] = True # to inform to Coast to Stop then on a second line: . Lego1.SetOn[1] = False # Deactivates (Coast to Stop) Output A.
- SetDir[OutPortNo]: (R/W),  Where OutPortNo = 1 to 8 representing Output A to H. Ex.: Lego1.SetDir[1] = False # Set the direction of output A to CCW I think.   If set to True, it's the opposite direction.  You should set this property before SetON...
- SetPow[OutPortNo]: (R/W),  Where OutPortNo = 1 to 8 representing Output A to H.  Accepts values 0 to 7.  Ex.: Lego1.SetPow[1] = 7 # Sets the max power to Output A.

- IsRunning: (Read Only), Tells if the Lego Box Serial Communication has been established, the Stop Led Light on the lego box should be OFF.  Ex.: if Lego1.IsRunning: print("Lego Box is Running")
- InOn[InputPort): (RO),  Input port range is 0 to 8.  0 is the status of the Lego Box Stop Button.  1 to 8 are the Input port number.  Reports True or False and follow the Led light status.  Can be used for many sensors.  Ex: if Lego1.InOn[1]: print("Lego1 input 1 is ON")
- InVal[InputPort): (RO),  Input port range is 1 to 8.  10 bit Value of input port.  Ex. if Lego1.InVal[1] > 100: print("Input 1 value > 100)
- InRotCW[InputPort): (RO),  Input port range is 5 to 8.  Status of the last direction reported by the rotation sensor.  True (CW?) or False(CCW?).  Ex.: if Lego1.InRot[5]: print("Lego 1 Input 5 Rotation ClockWise")
- InRot[InputPort): (RW),  Input port range is 5 to 8.  Rotation sensor Count.  You can Read or Set this property.  Ex. Lego1.InRot[5] = 0 # Resets input 5 rotation sensor count to 0.  if Lego1.InRot[5] > 48: print("Lego1 Rot Sensor 5 made at least 3 turns")

- InTempC[InputPort] and InTempF[InputPort]: (RO), Input port range 1 to 4.  Read the Temperature Sensor valur in celsius and fahrenheit.  print(Lego1.InTempF[3]) # prints temp sensor value at input port 3.

Script Examples:
The following script connects Lego1 to COM14 port and prints the IsRunning status in the Output Log Textbox.
Then it sets the power to max (7) and activates 4 outputs A, B, C, D.  It Waits 3 seconds, then it Deactivates the 4 same outputs.  Script ends.

import time
Lego1.ComPort="COM14"
Lego1.StartLego()
time.sleep(1)
print("Lego 1 Running: ", Lego1.IsRunning)

Lego1.SetPow[1] = 7
Lego1.SetPow[2] = 7
Lego1.SetPow[3] = 7
Lego1.SetPow[4] = 7

Lego1.SetOn[1] = True
Lego1.SetOn[2] = True
Lego1.SetOn[3] = True
Lego1.SetOn[4] = True

time.sleep(3)

Lego1.SetOn[1] = False
Lego1.SetOn[2] = False
Lego1.SetOn[3] = False
Lego1.SetOn[4] = False


The following scipts has a While loop using the cancellationToken to be able to exit the loop with the STOP Loop Script button.
You have to connect a Touch sensor to Input #1.  You may connect a motor to Output 1.
When executing the script,  Press once on the Touch Sensor.  The motor (Output 1) will Run for 3.5 sec, then stop for 1.5 sec, Reverse the direction, then start again for 3.5 sec and do this in a loop until you press again the Touch sensor.

import time
print("Script Running")
Lego1.ComPort="COM14"
Lego1.StartLego()
time.sleep(1)
print("Lego 1 Running: ", Lego1.IsRunning)

Lego1.SetPow[1] = 7
Lego1.SetDir[1] = False

seq_en=False
wait_en=False
m1=False # m1 is a memory used to simulate a ONE SHOT over the Input 1 to avoid hunting effect...
print("Sequence Disabled")

while not cancellationToken.IsCancellationRequested:
	if Lego1.InOn[1]:
		if not m1:
			m1=True
			if not seq_en:
				ti=time.time() + 3.5
				seq_en = True
				print("Sequence Enabled")
			else:
				seq_en= False
				print("Sequence Disabled")

	else:
		m1=False

	if seq_en:
		if not wait_en:
			if time.time()<ti:	
				Lego1.SetOn[1] = True
			else:
				Lego1.SetOn[1] = False
				tw=time.time()+1.5
				wait_en = True
		else:
			if time.time()>tw:
				Lego1.SetDir[1] = not Lego1.SetDir[1]
				ti=time.time() + 3.5
				wait_en=False
	else:
		Lego1.SetOn[1] = False

	time.sleep(0.020) # 20ms scan time.  Not mandatory but I thought it might help ressources.  Anyway, legobox scantime is around 20-30 ms

Lego1.SetOn[1] = False

 
Simple Loop script to make output 1 follow input 1

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

Lego1.SetPow[1] = 7
Lego1.SetDir[1] = False

while not cancellationToken.IsCancellationRequested:
	if Lego1.InOn[1]:
		Lego1.SetOn[1] = True
	else:
		Lego1.SetOn[1] = False
	
	time.sleep(0.020)

 

Can be even simpler:

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

Lego1.SetPow[1] = 7
Lego1.SetDir[1] = False

while not cancellationToken.IsCancellationRequested:
	Lego1.SetOn[1] = Lego1.InOn[1]
	time.sleep(0.020)

 

Edited by Bliss
Posted
38 minutes ago, Bliss said:

Happy new year!

Here is a Draft of my C# project that embed IronPython as an attempt to make a programming environment for the Lego Interface B.

Happy New Year!

How cool is this!!! I am totally in love ... this is the way to go on modern machines! Simply wonderful. Congratulations!!!

Well, this is a coincidence, the moment I noticed your update via EB email notification, I uploaded my (crappy as always ;) video on YouTube. Nothing special, just a demo that a DOS computer can handle the Interface B running QBASIC/QuickBASIC from about 3+ decades ago as well, in both direct and program control. 

This is what drives me: Controlling old hardware with old machines, using old software, because I am old :pir-huzzah2:.

Here is the link to the BAS file: https://bricksafe.com/files/Toastie/lego-interface-b-9751/Q9751_3.BAS

Here is the link to the EXE file: https://bricksafe.com/files/Toastie/lego-interface-b-9751/Q9751_3.EXE

They will change over time, but retain the name/link.

Here is a (stupid as ever) YouTube video, showing, what you can do (and what not ;)

All the best,
Thorsten

Posted (edited)

I updated my previous post and the dropbox link because I forgot to include properties InTempC and InTempF...

By the way, the password for the EXE standalone zip file is lego.

If you use the Start Stop button to connect your Lego Interface B Box, you do not need to connect it in the script by using StartLego() method.  (But you can do it also, It will see it is already started).
Then, If you have a temp sensor on input 3, you can just write the following script and Run it:

print("Temperature (C): ", Lego1.InTempC[3])
print("Temperature (F): ", Lego1.InTempF[3])

 

Edited by Bliss
Posted (edited)
import time
Lego1.ComPort="COM1"
Lego1.StartLego()
Lego2.ComPort="COM2"
Lego2.StartLego()
time.sleep(1)

Lego2.SetPow[1] = 7
Lego2.SetDir[1] = False

while not cancellationToken.IsCancellationRequested:
	if Lego1.InOn[1]:
		Lego2.SetOn[1] = True
	else:
		Lego2.SetOn[1] = False
	
	time.sleep(0.020)

 

Edited by Bliss
Posted (edited)
58 minutes ago, Gunners TekZone said:

Well... it keeps crashing and blurring out the screen.   This is the only way I can "clearly" show what the log says.  I think it is trying to use the same COM2 port for both devices.

Thanks!

It appears I forgot to fix the same error we had in the LegoDemoB program...

Here is the Fixed LegoScriptB program

I also corrected the Example codes in my posts above.
Some of them were not working because of some hidden characters ...

  

Edited by Bliss
Posted

@Gunners TekZone

Thank you very much for your kind words! Well, the $$$ situation here is also tight, but more or less due to strict regulations from the higher authorities :pir-laugh:. Which is OK; otherwise this place would be - well, you know what I mean.

6 hours ago, Gunners TekZone said:

But will see if I can figure out an emulator

I was very lucky to find a few vintage machines (an IBM XT, several Atari's, C64) a little over two years ago in a storage room of my group at the university - the students cleaning out that room for other purposes were ready to dump them ... but then I spotted the beauties :pir-love: and almost fainted. There was so much more wonderful stuff from the 1980's - to the joy of my wife. Well, at home I have an attic, where I am allowed to do what I like to do as long as it does not interfere with normal life in the house :pir-huzzah2:.

With regard to a DOS emulator: I strongly suggest DOSBox-X. It has been under vigorous development (and still improves with regard to issues, I never ever have heard off, see their wiki and GitHub page, but has reached a stage that is simply incredible. The "-X" is important, as DOSBox is - as far as I read - leaned more towards DOS games, whereas DOSBox-X tries to get as close to vintage hardware as possible:

https://dosbox-x.com/

On modern machines, e.g. Win11/64bit, communication with the outside world is via COM (serial) ports; a USB to serial adapter is all you need. It runs as a Win (etc.) application, no re-booting or dual boot or whatever required. The DOS "file system" is just another folder on your computer and behaves as such: Copy/paste files from any location etc. QBASIC is a matter of 1 file (QBASIC.EXE) of 190 kByte length;) plus the 128 kByte long help file QBASIC.HLP. The same holds true for QuickBASIC and so on and so forth. I have TurboPascal and TurboC running, VisualBasic for DOS of course, and all the original LEGO software, other fellows here on EB (particularly @evank) have archived, which is ready to go: https://archive.org/details/@magicratandbarefootgirl

Oh well, nothing for the younger generations I believe, but so much fun for the elderly :pir-triumph:

All the best,
Thorsten

 

 

Posted

I updated the LegoScriptB in the Dropbox link (See my post above).

I just added the possibility to use out.A to out.H as the output port number for the output type properties (SetOn, SetFree, SetDir, SetPow).  Ex.: Lego1.SetOn[3] , Lego1.SetOn[out.C] , Lego1.SetOn[out.c] are now allowed to activate/deactivate Output Port C.

I also replaced SetON by SetOn (Lowercase N) and changed the example codes in my previous post...

 

Posted
12 minutes ago, Gunners TekZone said:

@Bliss  Working great so far!!  Thanks!

Now to improve my Python coding so I can make good use of this.  Currently I am just using three push buttons on one device to manually control a switch and drive a 9v train (powered on another device) around my test track.  Next intent is to duplicate my semi-autonomous program, currently on ControlLab (running TC LOGO) in Python.

I can't recall of top-o-head if I already posted this somewhere here... If so, please forgive the duplication :)
https://youtu.be/hLKNcO3VmvQ

Nice.

Can you paste somehow your TC Logo program?
What are the inputs and outputs?

I guess a picture of the program would be enough if cannot paste or have a text file...

I never used the original control lab software...  Maybe I should have tried it to get familiar with the functions.  Could have given me some ideas...

 

Posted
7 hours ago, Bliss said:

I never used the original control lab software...  Maybe I should have tried it to get familiar with the functions.  Could have given me some ideas...

Well, I believe your software is already so full of ideas!!! That is incredible progress, you made!

Now for even further ideas, I'd go even back to Technic Control (TC), the 4.5V Interface A box and the software for it. It runs flawlessly in DOSBox-X (or on any semi-vintage computer. Has been discussed here on EB "a lot" (considering that only about 5 people are really interested in such moldy stuff :pir-laugh:

Here you'll find all the documents. TLG did a very good job back in the days doing that. It is fun to read the endless pages. tto = short for talkto and so on and so forth. For me, the single reason to make my own TC/interface A software (using QBASIC of course) was, that I simply could not get my head around TC LOGO. Well, I was too lazy I guess, others like @alexGS speak TC LOGO fluently! It is a rather powerful language. I simply like QBASIC, because I grew up with it. 

The TC LOGO Reference Guide is a very nice document to start with, as all commands and keywords are well laid out. But there is so much more, all available on the Internet Archive: @evank's 1) https://archive.org/details/@magicratandbarefootgirl and then this one 2) https://archive.org/details/vintagelegorobotics.

The same holds true for Control Lab. The olden days were better :pir-huzzah2:

But I guess you have already seen all that!

Best wishes,
Thorsten

Posted
On 1/4/2025 at 3:15 AM, Bliss said:

I updated the LegoScriptB in the Dropbox link (See my post above).

I just added the possibility to use out.A to out.H as the output port number for the output type properties (SetOn, SetFree, SetDir, SetPow).  Ex.: Lego1.SetOn[3] , Lego1.SetOn[out.C] , Lego1.SetOn[out.c] are now allowed to activate/deactivate Output Port C.

I also replaced SetON by SetOn (Lowercase N) and changed the example codes in my previous post...

 

 Hey @Bliss !

I've just tested your application and it works great on my Win11 laptop. Really appreciate your work, this is just what I need! I'm currently building a lego monorail based darkride controlled by 2 Dacta Control Labs and hopefully 2 RCX's as well (I dont get original software working atm, so RCX control integrated in your program as @Gunners TekZone suggested would be even greater, no pressure ofcourse :)

I probably wont be as consistent with testing your updates as @Gunners TekZone due to a busy working scheme, but I just wanted to let you know you got a big fan in me. I'll test whenever I can and I'll be following this thread with great interest. Thanks for the great work!

Regards,

Rob

Posted

@Gunners TekZone,

Thanks for all the details. 
The logo program already talks a lot by itself without knowing much about this language.  It's pretty simple.
That gives me ideas to implement few more commands of the lego interface B that I did not yet tested...

About the logo "onfor", I understand that this activates an output and deactivates after a delay, like onfor 20 will activate output for 2.0 seconds and deactivate output after the 2sec elapsed.
But I wonder if the logo "onfor 20" will prevent any following instructions to execute unti the 2.0 delay has elapsed.

So in the following for example, the MotorH will activate after 4 sec ?:
(MotorD, which I believe is the track sw, activates for 2 sec, then after this 2 sec, MotorD stops, SoundC activates for 2 sec, then after this delay, sounds will stop and MotorH will activates.

tto "MotorD setright onfor 20
tto "SoundC setright onfor 20
tto "MotorH setright setpower CN_Auto_Speed on 

According to you video and the timing, that's what it looks like.  Right?

Thanks again.

Posted (edited)
45 minutes ago, Ax4478 said:

 Hey @Bliss !

I've just tested your application and it works great on my Win11 laptop. Really appreciate your work, this is just what I need! I'm currently building a lego monorail based darkride controlled by 2 Dacta Control Labs and hopefully 2 RCX's as well (I dont get original software working atm, so RCX control integrated in your program as @Gunners TekZone suggested would be even greater, no pressure ofcourse :)

Hello, thanks for your interest!

About the RCX, I already owned few of those but unfortunately I sold them all.  I should have kept one at least :-)

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). 
The user program was running on the RCX in opposite of the lego interface B where the user program runs on a PC/MAC/Raspberry Pi etc.

Lego Interface B is like a remote Input and Output passive device linked to a Main Programmable Logic Controller (PLC, yes I have a backgound in Industrial PLC Programming :-) )

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

Unless you can put a firmware in the RCX that will make it acts has a dummy remote I/O gateway that waits for Output commands from its Infrared port and continuously sends sensors values to the IR port?

 

I recall there was custom firmwares back in the days like NQC, (Not Quite C) and more...  I did not check since if there was more custom firmwares available for the RCX.

 

Edited by Bliss

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.
×
×
  • Create New...