To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.dactaOpen lugnet.dacta in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Dacta / 261
260  |  262
Subject: 
ControlLab 70909 Interface (9751?) VB.NET Class (DLL)
Newsgroups: 
lugnet.dacta
Date: 
Fri, 8 Jan 2010 22:32:19 GMT
Viewed: 
20138 times
  
Hi,

Here is my first attempt to build a VB.NET DLL class to facilitate somehow the
building of VB.NET programs that talk to the old ControlLab Interface "B",
70909.

http://www.box.net/shared/xc44rksi2h

This folder includes Source files and also setup files.
To RUN the DEMO applications you need Microsoft .NET Framework 3.5 SP1 (FREE)
already installed on your PC.
To use the Source, you need Vusal Basic .NET 2008 Express Edition. (FREE)

I am not a VB.NET expert and this project is also a learning opportunity for me.

This is not a ControlLab programming language.  I use VB.NET as the programming
language to make Programs that Reads the Interface Inputs (Switch,
Light/Temp./Rotation Sensors) and Writes to Interface Outputs (Motors,
Lights...).  The DLL is just a black box that manages the Serial Communication
and implements the required protocol for the interface and provide methods and
properties for easy access through a main program.

I supplied all sources.  The simplest program to look at the source to get
familiar is the demo2 which activates a motor on output 1 when a limit switch is
pressed on input 1, motor stops if the switch is not pressed.
The DEMO2 has a reference to the Lego70909ClassLib.dll...

I did not yet wrote a document that explains how to use it.  But I will
eventually write it.  Meanwhile, if you know a little about VB or VBA or VB.NET,
you will probably find your way by yourself.

I did not make a lot of testing on another computer so I am not sure it has all
files needed... Please let me know.

I tested only on Windows XP sp3.  No idea if it will run on a Vista or win7 or
2000.

Since I don't have more than one interface, I don't know if it can really handle
2 or more controlLab interface.  Some feedback would be appreciated on this
matter.

I am using a Prolific USB to RS232 adaptor which works great.


Here is a quick start to build your own controllab program with the use of the
DLL in VB.NET.

1- Start VB.NET 2008 express edition, and start a new Project and select a
Windows Form Application template.

2- In "Project" Menu, select "Add Reference"

3- Go to "Browse" TAB and select the Lego70909ClassLib.DLL that is part of the
Lego70909ClassLibSource.zip in folder
...Lego70909ClassLib\Lego70909ClassLib\bin\Release

4- On the Form (Form1 if you did not rename it), drag a Timer control from the
toolbox on the left (Part of the "Components" folder in the toolbox).

5- This timer will execute a sub routine at a certain scan time you supply.

6- Double clicking on the form will bring you on the code page related to the
form and will automatically create the first subroutine we need wich is the
Form1_Load that will execute as soon as your application start.

7- In this code windows, just before the "Public Class Form1" (General
Declaration region), write: Imports LegoControlLab
This is to get an easier access to the lego70909 methods and properties etc...

8- Always in the code window, right below "Public Class Form1", write:
Dim lego1 As New Lego70909

This is to create an object from the DLL representing a ControlLab Interface
If you have two interfaces (and 2 serial ports) then you would write:
Dim lego1 As New Lego70909
Dim lego2 As New Lego70909

9- Inside the "Form1_Load" subroutine (Just under "Private Sub Form1_Load"),
write the following lines:
        lego1.ComPort = "Com2"   'Tells the DLL which com port is used for the interface
        lego1.StartLego()        'To Start Communicating with the interface
        Me.Timer1.Interval = 50  'Configue the Timer we added to the form (Step
4) at 50 ms (quite fast)
        Me.Timer1.Enabled = True 'Starts the Timer


10- Go back to the Form (Form1.vb [Design]) and double-click on the timer1
control at the bottom of the screen.  This will create automatically the
Timer1_Tick Subroutine in the form Code window.

11- In the form code window, inside the timer1_tick sub, you actually program
your Lego ControlLab application.
Write the following lines inside the timer1_tick subroutine:

        'At the beginning, you must get the actual status of the imputs.
        lego1.GetInputs()

        If lego1.InputPressed(1) Then
            lego1.Out_OnR(1) 'Start motor on output 1 right direction (Right LED
on Output 1 goes ON )
        Else
            lego1.Out_Off(1) 'Stop and Brake motor on output 1.  Use Out_Free(1)
instead if you want the motor to stop without braking.
        End If

12- Last step to our first controlLab application, is to stop the interface if
when we close our form.  In the form1 code window, there are two combo box on
the top, in the first combobox, select "(Form1 Events)" and in the second
combobox, select "FormClosing".  This will create automatically the subroutine
"Form1_FormClosing" that will execute we close our application during runtime.

13- Inside the Form1_FormClosing subroutine, write the following lines:
        If Not (lego1 Is Nothing) Then
            If lego1.IsStarted Then
                lego1.StopLego()
                Do While lego1.IsStarted
                    ' Wait until IsStarted = False (Waiting for Lego Read Inputs
thread to be stopped)
                Loop
            End If
            lego1 = Nothing
        End If


14- Done.  Save you application.  Go to Debug menu and select "Start Debugging"
to test your application. Press Switch one connected on input 1 of the
controlLab interface, the motor on output "A" should start. Release Switch to
stop motor.



There are many Methods (To command outputs) and properties. I will try to
describe them in details in a document I will put in the Folder URL...
For now, you can browse them using the View menu, Object Browser, Browse "My
Solution", Lego70909ClassLib, LegoControlLab, Lego70909 then look on the Right
pane...

All method to control outputs start with Out_ for one port control (You have to
supply the port number) and OutM_ for multiple port control.  For the OutM_
methods, you must supply a byte (8 bits) where each bit correspond to a Port.
Use Hexadecimal annotation (&H).
To turn on Output 1 and 5 = 00010001, use Lego1.OutM(&H11), for out 1,2,7 =
01000011, use Lego1.OutM(&H43)

For switch status use property InputPressed(PortNum).  This will return True if
switch is pressed, False if not pressed.
For light and Temperature sensor, use InputValue(PortNum).
For Rotation sensor, use RotationCount(PortNum) to Get/Set the rotation count
(16 count per turn).  Lego1.RotationCount(5) = 0 will reset the count of port 5.
For rotation sensor, there is also the properties: RotationCW (true if turning
clockwise, False otherwise), RotationSpeed: thise is for information. 0= no
moves, 1 turning slow, 2=fast, 3 is very very fast...

This is a work in progress.


Thank you for your feedback.

Yves Levesque.



Message has 3 Replies:
  Re: ControlLab 70909 Interface (9751?) VB.NET Class (DLL)
 
(...) Thanks for posting your program for others to share. I will try and make some time to test it out. It is becoming quite rare to see others using these interfaces. I have multiple 9751 ControlLab interfaces and could do some testing using more (...) (14 years ago, 9-Jan-10, to lugnet.dacta)
  Re: ControlLab 70909 Interface (9751?) VB.NET Class (DLL)
 
(...) with it (using Robolab) has always been the incredibly slow response to inputs (press a touch sensor and wait about 1 second for the motor to stop). Can you tell me anything about response times in your program? Jetro (14 years ago, 10-Jan-10, to lugnet.dacta)
  Re: ControlLab 70909 Interface (9751?) VB.NET Class (DLL)
 
(...) I just uploaded a PDF document to the "Box" url mentionned in the first message. This document (Lego70909DLL.pdf) is a tutorial on how to make ControlLab Interface (CLI)project in VB.NET using the proposed DLL. It is also a reference document (...) (14 years ago, 19-Jan-10, to lugnet.dacta)

17 Messages in This Thread:



Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR