B4PPC & Mindsqualls DLL

ToGi

New Member
Hello,

I am considering to buy B4PPC.
The main purpose of B4PPC is to connect to my Brick of the Lego Mindstorn (NXT).
I found at mindsqualls.net a NET DLL which I could install in B4PPC.
My questions:
In Vb.NET there are the possibility to import the DLL Thru "Imports".
In B4PPC this will be done thru "Components" which I did.
After creating a new Object there were several properties missing :BangHead: which normally found in VB.Net.
Could somebody give me an advise how to get the whole properties.
I can connect to the NXT and use some of the properties ie. "Brick.Name" & "Brick.GetBatteryLevel" but some are missing.
In addition to that in VB.Net if I used brick.Commlink. .... there are another
properties behind which I can't use in B4PPC.
(Pfffff. yery tough to explain):confused:
Is there any way to create below's code in B4PPC:

B4X:
i.e.: Dim brick as New NxtBrick 
       brick = New NxtBrick(COMPortName)

It would be highly appreciated if somebody can help me to get this DLL working.:sign0085:

Thanks in advance
Thomas
 

agraham

Expert
Licensed User
Longtime User
You seem to be familiar with VB.NET. Is there a reason not to use VB.NET for your application - like maybe it won't compile for the device?

The reason you can't use some of the properties are that they return types of objects that Basic4ppc can't understand. It really only understands the primitive types and Color as library parameter and return types. As the source of the library is available (I've downloaded and compiled it OK) you could modify it to suit your needs, but maybe you aren't happy with C#.

You can make a brick by adding an object named "Brick " as a NxtBrick, Tools->AddObject, and instantiate it with

Brick.New2(COMPortName)

You could also add it at runtime but you lose the automatic listing of properties and methods at design time.

AddObject("Brick", "NxtBrick")
Brick.New2(COMPortName)

EDIT:- The properties you can't see in Basic4ppc can probably be manipulated with the Door library, obj1 is a Door library Object.

obj1.New1(False)
obj1.Value = Brick.CommLink
obj1.RunMethod("Connect")

but maybe this is getting a bit arcane :(
 
Last edited:

ToGi

New Member
Dear Erel,
dear agraham,

thanks a lot for the fast reply.
I am not so familar with VB.Net. I could compile my programm to the Emulator as well as to the Device. The problem was only that I could'nt established the BT Connection by starting my program. I got always a system exception. Only if I create the BT connection before I start my program I was able to connect the NXT.
I also compiled the Mindsqaulls with C# and the DLL works and you are right
I don't like C# because for me it's totally confusing and for sure I'm not able to modified the code. Delphi :sign0060:
If I embedded the DLL in B4PPC there are several Objects are available.
I.e.: NXTBrick, NXTBluetooth

Please see hereafter:

B4X:
Variable "port" is in Sub GLOBAL

Sub App_Start
nxtbrick.New1(port)   'Create New1 with COM5
End Sub
Sub mnuConnect_Click
   ErrorLabel(btnConnectErr)
      nxtbrick.Connect
      If nxtbrick.IsConnected Then
      ModGeneral.Connected
      End If
   Return
       btnConnectErr:
      Msgbox("Kann Anschluß " & port & " nicht öffnen", "Fehler")
       If nxtbrick.IsConnected Then 'close port
      nxtbrick.Disconnect
      ModGeneral.NotConnected 
       Else
      nxtbrick.IsConnected
      ModGeneral.Connected
      Sender.LabConnect.Color = 255,0,0 
       End If
End Sub

The above code works well with the Mindsquall DLL but only for the object
"NXTBrick".
If I try now to get information from the object "NXTBluetooth" like
"NXTBluetooth.GetFirmwareVersion" I create an Error because
NXTBluetooth.New1(port) is not open. But I can't open due to
the open NXTBrick.New1. :BangHead:

Is there any possibility to bypass the NXTBluetooth.New with any command in B4PPC and get the information thru NXTBrick's open port?

I hope you could understand what my problem are.
Thanks for your Feedback

Thomas
 
Last edited:

agraham

Expert
Licensed User
Longtime User
I create an Error because
NXTBluetooth.New1(port) is not open.
It's really a bit too complicated to explain here but NextBrick.New1 followed by NextBrick.Connect creates a NxtBluetoothConnection object and stores it in its CommLink property. You would need to use this CommLink object, not the one you created, to communicate.

This is a very low-level library with no explanatory documentation. The documentation is just a bald list of classes with their methods and properties. To use this library you would need to know about how .NET classes and objects work and to understand what it can do you need to know about the BDK which the documentation references - I assume this is is the Lego Brick Development Kit. You seem to have access to Visual Studio so if you don't already understand VB.NET then I am afraid that you might have a long learning curve ahead of you!
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
@ToGi
I am afraid that I'm not able to answer your question and instead want to ask a question of my own...

I have been considering buying a LEGO Mindstorm kit for my son as a means of introducing him to programming. I believe that it is loosely based on the National Instruments programming platform (I've previous experience using NI to control vision inspection systems).
Do you feel that this would be a good start for my son, who is 10 next month, to get involved in programming and mechatronics?

Regards,
RandomCoder
PS Sorry for taking this thread :sign0006:
 

ToGi

New Member
@ agraham
I understood the explanation from you regarding open port.
I have Microsofts Visual Studio 2008 and I create the same code for VB.Net
which I created for B4PPC. But also this creates other problems which former
worked quite well in B4PPC.:BangHead: (I like this Smiley).
In B4PPC directly after initialisation and opening port I got the BT connection.
But Now with VB.Net it's much more complicated and I got another error which I could'nt understand.
Anyway, this is a B4PPC based Website and I think that B4PPC have a lot of advantages which are better than VB.Net (one of them is that VB.Net is much more complicated).

I have to find a way to communicate which the PPC & LegoBrick in whatever way. Maybe next version of B4PPC :sign0060:

Anyway, thanks a lot to agrahm and erel to taking care my questions.

@ RandomCoder

My son is 10 years old and my intention was and is to guide him in a kittenish way to mechatronics and programming.

I am involved in John Hansen's BricxCC for Legos bricks as a beta tester and I translated the above mentioned program in my native german language and changed something in the code to make it easy for my son to program the Lego Mindstorm Brick in bloody similar C programming language named NXC, but by today it's a little bit hard for my son to understand text based programming language.

Of course, the software of Mindstorm is based upon NI's Labview with some limitations where my son is now programming with.
If you are familar with NI's Labview you can also download an SDK for Mindstorm on NI website with much more complex possibilities than the normal Lego software, but it's very tough I guess.

From my point of you, I think this is one of the best opportunities to start programming for kids in a very easy and funny way, because if your son
is using the orignal software of Lego Mindstorm he will have an WYSIWYG
like effect.
 

agraham

Expert
Licensed User
Longtime User
I have to find a way to communicate which the PPC & LegoBrick in whatever way. Maybe next version of B4PPC
I don't think that the next version of Basic4ppc will have anything in it that will help. Basic4ppc cannot handle non-primitive parameters and return values of external libraries.

If you want to stay with Basic4ppc then the Door library used with my DoorEx library (you have to buy Basic4ppc to be able to access the additional libraries) should let you manipulate the things that Basic4ppc itself can't handle. But doing it this way would be clumsy and need almost as much knowledge of .NET as needed to rewrite the library in the first place.

This is a flavour of what would be needed, obviously I haven't tried this to see if it works. Brick is a NxtBrick object, MotorA is a NxtMotor object, obj1 is a Door library Object object, objex1 is a DoorEx library ObjectEx object.
B4X:
Brick.New1(COMPort)
MotorA.New1
obj1.New1(False)
objex1.New1(B4PObject(2))
  ...
Brick.Connect
bl = Brick.BatteryLevel ' this should work as it returns a UInt which B4P understands
  ...
' the following does "Brick.MotorA = new NxtMotor();"
objex1.FromString("MotorA") ' get a reference to MotorA which we created earlier
Brick.SetProperty2("MotorA", objex1.Value)
' and then run at 75% power of 10 turns "Brick.MotorA.Run(75, 3600);"
MotorA.RunMethod3("Run", 75, "System.Int32", 3600, "System.Int32")
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
From my point of you, I think this is one of the best opportunities to start programming for kids in a very easy and funny way, because if your son
is using the orignal software of Lego Mindstorm he will have an WYSIWYG
like effect.

Thank you for your reply ToGi, my mind was pretty much set on the idea of getting my lad the Mindstorm kit and you have helped to confirm that this is a worthwhile investment.

Regards,
RandomCoder
 
Top