Join 358,488 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,184 people online right now.Registration is fast and FREE... Join Now!
Chat LIVE With a Expert
Getting VB to control objects outside of computer
52 Weeks of Code Challenge:Android
Week #11 of the 52 Weeks of Code Challenge is Android, you should give it a shot. Click Here!
Hi, I am new here and even newer to VB so if this is the wrong place to
post this or i use the wrong terms i apologize, it is not my intention to
offend or insult.
I am told that the code does not seem to contain any reference to a template file for
controlling the device. This information might be in the array StatoCubo,
and perhaps the text file is used to populate that array, but there is no
code here to do that.
I am using VB 2008 Express edition. I did not write the code below but i was
told that it works but it dont.
I am building an 8 x 8 x 8 led cube and have most of the code i need to make
it work but i can not figure out how to make VB callup(?) a .txt
(template)file to control the cube designs. Below is the code so far (some of
it is in Italian i think) and the file name i want to use is;
RainbowExplosion_8x8x8_bw_bit01 VER1.txt
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress
As Integer, ByVal Value As Integer)\par
'--------------------------COSTANT FOR LPT1
ADDRESS--------------------------------\par
Public Const IndirizzoData As String = "&H378" 'DATA REGISTER: 8 bit\par
'-------------------------------------------------------GLOBAL
VARIABLES----------------------------------------------------\par
Public StatoCubo(1 To 8, 1 To 64) As Integer 'variable that contains the
actual state of cube\par
'-------------------------------------------------------------FUNCTIONS--------------------------------------------------------\par
Public Function ScriviCubo(NumeroCicli As Integer) 'function for write into
cube the state stored in StatoCubo matrix\par
Dim ByteLpt As Byte\par
Dim ContaLivelli As Integer\par
Dim ContaLed As Integer\par
Dim ContaCicli As Integer\par
For ContaCicli = 1 To NumeroCicli\par
For ContaLivelli = 1 To 8\par
'set all bit of shift reg. of columns without clocking on shift reg. of
layers and disabling EVER all clear pins (xx 01x _1_)\par
For ContaLed = 64 To 1 Step -1 'For ContaLed = 1 To 64\par
'SHIFT REG. LAYERS:\par
'MSB (D5) = 0 --> clock disables\par
'CENTRAL (D4) = 1 (valore=16)--> clear disabled\par
'LSB (D3) = not important\par
'SHIFT REG. LED:\par
'MSB (D2) = 0 --> clock disabled\par
'CENTRAL (D1) = 1 (valore=2)--> clear disabled\par
'LSB (D0) = StatoCubo(ContaLivelli, ContaLed)\par
ByteLpt = (0 + 16 + 0) + (0 + 2 + StatoCubo(ContaLivelli, ContaLed))\par
Call ClokkaLed(ByteLpt) 'send the value at function that give 1 clock signal
to the shift reg. of columns\par
Next ContaLed\par
'SHIFT REG. LAYERS:\par
'MSB (D5) = 0 --> clock disabled\par
'CENTRAL (D4) = 1 (valore=16)--> clear disabled\par
'LSB (D3) = (if layer = 1--> 1(value=8); if layer <> 1--> 0) --> set 1 only
the fist time\par
'SHIFT REG. LED:\par
'MSB (D2) = 0 --> clock disabled\par
'CENTRAL (D1) = 1 (valore=2)--> clear disabled\par
'LSB (D0) = not important\par
\cf2\fs18 \par
\cf1\fs15 If ContaLivelli = 1 Then 'if I\'19m setting the first layer I send
a 1 at the shift reg. of layers, after I will send only the clock signal\par
ByteLpt = (0 + 16 + 8) + (0 + 2 + 0)\par
Else\par
ByteLpt = (0 + 16 + 0) + (0 + 2 + 0)\par
End If\par
Call ClokkaLivello(ByteLpt) 'send value to the function that give a clock
signal to the shift reg. of layers\par
Call Aspetta(60000) 'calling the function for generate a delay (the cube
stops flashing from 60.000 to 70.000 cycles)\par
Next ContaLivelli 'restart the cycle for setting the next layer\par
Call ClearAll 'call the function for activate clear on all shift register
(switch off all leds)\par
Next ContaCicli\par
End Function\par
Public Function ClokkaLed(Valore As Byte)\par
Out Val(IndirizzoData), Val(Valore) 'clock DISABLED\par
'add 4 because I want to set at 1 the clock bit of shift register of columns
for giving clock signal\par
Out Val(IndirizzoData), Val(Valore + 4) 'clock ENABLED\par
End Function\par
Public Function ClokkaLivello(Valore As Byte)\par
Out Val(IndirizzoData), Val(Valore) 'clock DISABLED\par
'add 32 because I want to set at 1 the clock bit of shift reg. of layers for
giving clock signal\par
Out Val(IndirizzoData), Val(Valore + 32) 'clock ENABLED\par
End Function\par
Public Function ClearAll() 'function for enable the clear pin on all shift
register\par
Dim ByteLpt As Byte\par
'enabling clear on all shift register (value=0) (xx x0x x0x)\par
ByteLpt = 0 '00 000 000\par
Out Val(IndirizzoData), Val(ByteLpt)\par
End Function\par
Public Function Aspetta(Ncicli As Long) 'function used to delay the cycle of
updating the each layers\par
Dim Contatore As Long\par
Dim Contato As Long\par
For Contatore = 0 To Ncicli\par
Contato = Contatore 'assignment operation (only for do a CPU operation)\par
Next Contatore\par
End Function\cf0\fs20\par
}
I hope that helps.
If any one can help i would really appreciate it
Thank you
This post has been edited by Core: 09 November 2009 - 06:37 AM
Re: Getting VB to control objects outside of computer
Posted 11 November 2009 - 04:10 AM
Hi,
What is going on here?
Your code is quite messed up, you have on every line a \par and its not indented properly. (quite unreadable when it comes to the If or For statements)
Can you pleas update your code and paste the whole class. It seems like there is something missing.
Also paste or attach the Text file so we can see what the format looks like.
Re: Getting VB to control objects outside of computer
Posted 11 November 2009 - 06:45 PM
Hi, First thank you for answering my plea. The \par is not in my code anywhere I don't know where that came from, must be because the code is wider that the text box it's in, I don't know.
The StatoCubo matrix:
The StatoCubo matrix is composed by 8 vectors of 64 elements. Each vector represents the state of an entire layer, every element of the vector represents the state of 1
single one led: 1 = on, 0 = off
The ScriviCubo function:
This function is called by the timer event and his function is to transmit the content of the StatoCubo matrix to the real cube.
The ClokkaLed function:
This function is called by ScriviCubo function and it works by sending a clock signal to shift register of the columns ONLY modifying the bit of the clock. In this way the bit
placed on input of the first shift register of the columns becames acquired.
The ClokkaLivello function:
This function is called by ScriviCubo function and it works by sending a clock signal to shift register of the layer ONLY modifying the bit of the clock. If the layer to activate
is the first, an high signal (1) is placed on input of the shift register, for the next layer the bit on input is 0. In this way the bit for activation slides from one layer to the next
one. The layer will be lighted in sequence, one at each time.
The ClearAll function:
This function enables the clear pin on both shift registers. All the bits in the shift register will be set to 0 and the cube will totally switch off.
The Aspetta function:
This function is used to delay the cycle of updating of each layer. Without this function, the leds of the each layer turns on and off too quickly for properly lighting.
Now we can pass to the real code, comments in bold:
Public Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress As Integer, ByVal Value As Integer)
'--------------------------COSTANT FOR LPT1 ADDRESS--------------------------------
Public Const IndirizzoData As String = "&H378" 'DATA REGISTER: 8 bit
'-------------------------------------------------------GLOBAL VARIABLES----------------------------------------------------
Public StatoCubo(1 To 8, 1 To 64) As Integer 'variable that contains the actual state of cube
'-------------------------------------------------------------FUNCTIONS--------------------------------------------------------
Public Function ScriviCubo(NumeroCicli As Integer) 'function for write into cube the state stored in StatoCubo matrix
Dim ByteLpt As Byte
Dim ContaLivelli As Integer
Dim ContaLed As Integer
Dim ContaCicli As Integer
For ContaCicli = 1 To NumeroCicli
For ContaLivelli = 1 To 8
'set all bit of shift reg. of columns without clocking on shift reg. of layers and disabling EVER all clear pins (xx 01x _1_)
For ContaLed = 64 To 1 Step -1 'For ContaLed = 1 To 64
'SHIFT REG. LAYERS:
'MSB (D5) = 0 --> clock disables
'CENTRAL (D4) = 1 (valore=16)--> clear disabled
'LSB (D3) = not important
'SHIFT REG. LED:
'MSB (D2) = 0 --> clock disabled
'CENTRAL (D1) = 1 (valore=2)--> clear disabled
'LSB (D0) = StatoCubo(ContaLivelli, ContaLed)
ByteLpt = (0 + 16 + 0) + (0 + 2 + StatoCubo(ContaLivelli, ContaLed))
Call ClokkaLed(ByteLpt) 'send the value at function that give 1 clock signal to the shift reg. of columns
Next ContaLed
'SHIFT REG. LAYERS:
'MSB (D5) = 0 --> clock disabled
'CENTRAL (D4) = 1 (valore=16)--> clear disabled
'LSB (D3) = (if layer = 1--> 1(value=8); if layer <> 1--> 0) --> set 1 only the fist time
'SHIFT REG. LED:
'MSB (D2) = 0 --> clock disabled
'CENTRAL (D1) = 1 (valore=2)--> clear disabled
'LSB (D0) = not important
If ContaLivelli = 1 Then 'if Im setting the first layer I send a 1 at the shift reg. of layers, after I will send only the clock signal
ByteLpt = (0 + 16 + 8) + (0 + 2 + 0)
Else
ByteLpt = (0 + 16 + 0) + (0 + 2 + 0)
End If
Call ClokkaLivello(ByteLpt) 'send value to the function that give a clock signal to the shift reg. of layers
Call Aspetta(60000) 'calling the function for generate a delay (the cube stops flashing from 60.000 to 70.000 cycles)
Next ContaLivelli 'restart the cycle for setting the next layer
Call ClearAll 'call the function for activate clear on all shift register (switch off all leds)
Next ContaCicli
End Function
Public Function ClokkaLed(Valore As Byte)
Out Val(IndirizzoData), Val(Valore) 'clock DISABLED
'add 4 because I want to set at 1 the clock bit of shift register of columns for giving clock signal
Out Val(IndirizzoData), Val(Valore + 4) 'clock ENABLED
End Function
Public Function ClokkaLivello(Valore As Byte)
Out Val(IndirizzoData), Val(Valore) 'clock DISABLED
'add 32 because I want to set at 1 the clock bit of shift reg. of layers for giving clock signal
Out Val(IndirizzoData), Val(Valore + 32) 'clock ENABLED
End Function
Public Function ClearAll() 'function for enable the clear pin on all shift register
Dim ByteLpt As Byte
'enabling clear on all shift register (value=0) (xx x0x x0x)
ByteLpt = 0 '00 000 000
Out Val(IndirizzoData), Val(ByteLpt)
End Function
Public Function Aspetta(Ncicli As Long) 'function used to delay the cycle of updating the each layers
Dim Contatore As Long
Dim Contato As Long
For Contatore = 0 To Ncicli
Contato = Contatore 'assignment operation (only for do a CPU operation)
Next Contatore
End Function
I hoped that worked, if not i have attached it in a word doc named 8x8x8_code and the template code i need to make the cube work is named RainbowExplosion_8x8x8_bw_bit01 VER1.
Re: Getting VB to control objects outside of computer
Posted 11 November 2009 - 08:56 PM
Everything before "Public Declare Function Inp Lib..." is a comment and should not be included - the remainder looks very much like VB code. I would keep the rest and copy and paste it into a Module.
Re: Getting VB to control objects outside of computer
Posted 11 November 2009 - 10:08 PM
Thanks for looking, I just included that first part just in case it might help someone. I am told that the code does not seem to contain any reference to a template file for
controlling the cube. This information might be placed in the array StatoCubo,
and perhaps the text file is used to populate that array, but there is no
code here to do that.
Re: Getting VB to control objects outside of computer
Posted 12 November 2009 - 10:39 AM
This part of the code is not where you should be looking. Have you downloaded the full ZIP file from the Instructibles web site and compiled from the Project1.vbp?
I did that and it seemed to work fine.
Once it runs, you select 'strumenti' from the menu and then 'editor timeline' from the submenu, from there click on the 'carica...' button and load your 'RainbowExplosion_8x8x8_bw_bit01 VER1.txt' file from the ...Gestione led cube 0.5.3\Animazioni\Carl MODIFICATI PER MIO LED CUBE\ directory.
Reference to the actual .txt file is in Funzioni_rotazioni_editor.vb but once you compile and run it properly, you should be using the built in editor to load and save these files anyway.
Re: Getting VB to control objects outside of computer
Posted 12 November 2009 - 11:01 AM
Yes i have downloaded the zip file but i am curious what version of VB would be best for this project. Also,please excuse my ignorance,but i dont understand what you mean by compiled from the Project1.vbp, i dont see that file anywhere.
Re: Getting VB to control objects outside of computer
Posted 12 November 2009 - 11:36 AM
Robotjam, on 12 Nov, 2009 - 11:01 AM, said:
Yes i have downloaded the zip file but i am curious what version of VB would be best for this project. Also,please excuse my ignorance,but i dont understand what you mean by compiled from the Project1.vbp, i dont see that file anywhere.
Thank you
I'm using VB2008 express edition. A free download from the microsoft website.
In the directory \instructible light cube\Gestione led cube 0.5.3 which is created when you unzip the file, you should see 12 files and 2 directories.
If you didn't bother renaming the file when unzipping then it is probably called FUHGGXZFY7M6DVB.
Open your VB editor, select 'open project' then navigate to that directory and select Project1.vbp.
VB will then 'upgrade the project' to VB.net and you will be able to run it.
Re: Getting VB to control objects outside of computer
Posted 12 November 2009 - 12:44 PM
I truely hate bothering you like this but you are the only person since i began this project that has answered my pleas for help and i really do appreciate it.
I am also using VB2008 Express but when Winzip opens the FUHGGXZFY7M6DVB file all i see is two folders and one dll file.
I have found the Project1.vbp file in the Gestione led cube 0.5.3 location but i cant seem to find the'instructable light cube' directory.
Do i put the contents of the file Project1.vbp into the other code and if so where?
My email address is b9robot01@gmail.com if you would like to do this that way.
Re: Getting VB to control objects outside of computer
Posted 12 November 2009 - 03:30 PM
OK, sorry for the confusion. 'instructable light cube' is the name I gave to the directory when I unpacked it. Yours will be the 'FUHGGXZFY7M6DVB' directory if you didn't choose a new name when unpacking it.
It is important though that you do unzip the file to a directory instead of searching the ZIP archive as you will be using the VB2008 Express file open dialog to locate the .vbp file, not explorer. You will not be able to right click and open this file.
The directory with the 2 sub-directories and a .Dll file is the right place to start. one of those two directories is called 'Gestione led cube 0.5.3' the other seems to be concerned with just the audio side of things so you need not bother with that one.
'Gestione led cube 0.5.3' is the directory with the VB files in it.
Fire up VB2008 Express and from 'File' select ' open new project' (not open file) and then navigate to the 'Gestione led cube 0.5.3' directory.
Once VB2008 Express file open dialog is in that directory you should see the 'Project1.vbp' file as the only one in that directory.
When you open the 'Project1.vbp' file you will see the Visual Basic Upgrade Wizard. Follow the wizard through with the file conversion (takes several minutes) and you should end up with a working project.
I have run it through VB and attached a ZIP file with a built version of 'GestioneLedCube.exe' for you. You will still need to have 'inpout32.dll' in your windows\system32 directory but that should get you up and running for now.
Don't feel bad about bothering me, glad to help. I'm considering building this project myself so it's no trouble to find out more about it while helping you.
I recommend that you still build your own .exe from scratch though as you will learn more about it and you will be able to customise it from there too.
If the project1.vbp file is still hard to locate, use windows search and paste the location into the file open dialog...
Re: Getting VB to control objects outside of computer
Posted 12 November 2009 - 04:17 PM
Revolution.radio, on 12 Nov, 2009 - 03:30 PM, said:
OK, sorry for the confusion. 'instructable light cube' is the name I gave to the directory when I unpacked it. Yours will be the 'FUHGGXZFY7M6DVB' directory if you didn't choose a new name when unpacking it.
It is important though that you do unzip the file to a directory instead of searching the ZIP archive as you will be using the VB2008 Express file open dialog to locate the .vbp file, not explorer. You will not be able to right click and open this file.
The directory with the 2 sub-directories and a .Dll file is the right place to start. one of those two directories is called 'Gestione led cube 0.5.3' the other seems to be concerned with just the audio side of things so you need not bother with that one.
'Gestione led cube 0.5.3' is the directory with the VB files in it.
Fire up VB2008 Express and from 'File' select ' open new project' (not open file) and then navigate to the 'Gestione led cube 0.5.3' directory.
Once VB2008 Express file open dialog is in that directory you should see the 'Project1.vbp' file as the only one in that directory.
When you open the 'Project1.vbp' file you will see the Visual Basic Upgrade Wizard. Follow the wizard through with the file conversion (takes several minutes) and you should end up with a working project.
I have run it through VB and attached a ZIP file with a built version of 'GestioneLedCube.exe' for you. You will still need to have 'inpout32.dll' in your windows\system32 directory but that should get you up and running for now.
Don't feel bad about bothering me, glad to help. I'm considering building this project myself so it's no trouble to find out more about it while helping you.
I recommend that you still build your own .exe from scratch though as you will learn more about it and you will be able to customise it from there too.
If the project1.vbp file is still hard to locate, use windows search and paste the location into the file open dialog...
Good luck.
Mike.
Mike,
I got the 'Project1.vbp' file opened and upgraded even had the little control panel opened then my computer froze and i had to reboot now i cant get it to work again but dont worry i will figure that part out. I also have the 'inpout32.dll' placed in the windows folder.
A little bad news though Winzip was unable to open the zip file you attached, i tried opening it right from this page and even downloading it to the desktop but i keep getting the same message "cannot open file; it doesent appear to be a valid archive".
As far as building the cube i only have about $30 invested in it, $20 for the led's and i had most of the other parts just laying around. Looks like a cool project i hope to someday get it working, tonight i plan on going over the pc board checking all the wiring carefully just to be sure.
Re: Getting VB to control objects outside of computer
Posted 12 November 2009 - 04:59 PM
Robotjam, on 12 Nov, 2009 - 04:17 PM, said:
Mike,
I got the 'Project1.vbp' file opened and upgraded even had the little control panel opened then my computer froze and i had to reboot now i cant get it to work again but dont worry i will figure that part out. I also have the 'inpout32.dll' placed in the windows folder.
A little bad news though Winzip was unable to open the zip file you attached, i tried opening it right from this page and even downloading it to the desktop but i keep getting the same message "cannot open file; it doesent appear to be a valid archive".
As far as building the cube i only have about $30 invested in it, $20 for the led's and i had most of the other parts just laying around. Looks like a cool project i hope to someday get it working, tonight i plan on going over the pc board checking all the wiring carefully just to be sure.
Jim
Well I'm glad you got it going in the end, sorry to hear about the crash. I'm currently using an LPT vu meter that cost less then £1.
8 leds and a resistor on a 1x32 piece of veroboard soldered on the end of an ancient printer cable and stuffed into a CD storage spindle so the light shines out through the CDs. I'm thinking of putting it up as my first Instructible.
I compressed that archive with WinRar so I probably forgot to make it winzip compatible or something but I wasn't sure if I would be able to upload a .rar archive to D.I.C.
Keep us posted of how you get on with the cube. I like them and I'd like to hear how it goes before committing to building one.
Re: Getting VB to control objects outside of computer
Posted 14 November 2009 - 08:15 AM
Hi Guys,
OK I got the program working and i even went back and changed all the Italian words on the control panels to English. Now my question is this, When i measure the output voltage on the 25pin connector i get a constant 5 volts but after i start the program i still get a constant 5 volts, shouldn't there be some sort of floctuation in the voltage with the program running and 0 volts with the program turned of. If that is true how do i control the parallel port? I do have the inpout.dll installed in the windows\system32 folder.