Computer Hope

Software => Computer programming => Topic started by: macdad- on February 04, 2008, 08:14:30 PM

Title: New to VB Express How do i work with Dll's
Post by: macdad- on February 04, 2008, 08:14:30 PM
help!! im new to VB Express and im trying to make a prgm that sends files and words through a USB port.
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 05, 2008, 01:43:33 AM
Well, you need to find the dll that lets you interface with the usb port (no, I don't know where it is), and then add a referance to it, and then import it into vb.net.

These instructions may be improved if you tell me your:
.Net framework
Visual Studio being used
Operating System
Title: Re: New to VB Express How do i work with Dll's
Post by: Shynnie on February 05, 2008, 05:40:35 AM
If you try the upload file function which uploads the file to that port drive since if you connect a stiff on a usb port it will be assignned a drive letter.
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 05, 2008, 02:19:24 PM
no i have the dll and i've seen the commands in the dll. but heres how my prgm is suppose to work.
1st you type in a word or sentence in the textbox.
2nd you press the send button and the dll should send the word or sentence to the device. the device is a Lego USB Tower that comes with the lego mindstorm set. the lego robot i made is a printer that can print letters, numbers, and graphics. so when i send whatever i type in the textbox the dll send the words to my lego robot which then prints out the words.
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 05, 2008, 03:07:43 PM
Ok, add a refrence to your dll.

Then your code should be something like this (If you are using VB.net)

Code: [Select]
Imports SomeDll 'replace this with your dll

Public Class Form1

Private WithEvents LegoThing as SomeDll 'only add withevents if your dll actually has events

Private Sub SomeButton_Click(ByVal sender as object, ByVal e as System.EventArgs) _
         Handles SomeButton.Click
         
         Try
                 LegoThing.PrintSomething(SomeTextBox.Text)
         Catch ex as Exception
                 Msgbox("Error: " & ex.Message, msgboxstyle.critical, "An error has occured!")
         End Try

End Class


I could help more if you tell me:
The dll functions.
Where to find/download this dll.
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 05, 2008, 03:37:29 PM
heres the dll its in txt format so you have to open it with notepad and save it as a DLL file. all the function are intact take ur time and reply back when u have the chance

[file cleanup - saving space - attachment deleted by admin]
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 06, 2008, 12:09:02 AM
That didn't work... please put the dll in a zip folder and put that on here.
Thanks,
Bones
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 06, 2008, 06:06:12 AM
ok here...

[file cleanup - saving space - attachment deleted by admin]
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 06, 2008, 10:48:47 PM
Ok, I explored that dll and there is a heck of a lot of functions in it. Which ones am I using to send text and get a response?
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 07, 2008, 01:59:20 PM
ok there is first a command that says open port. the port i want to open is usb.
then there is a command that says RCX2 which tells u the Brick type for IR compatibility
after that there is a folder that says VPBrick open it and go to the command that says Download(By Ref String, which says send a letter or number to the RCX.
 
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 07, 2008, 09:54:58 PM
Ok, I've found that. Which function do I use to send text out? (and realise there may be glitches, I have no lego mindstorms set to test it with)
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 08, 2008, 03:42:19 PM
the Download(By Ref String is the function that sends the text to the RCX.
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 09, 2008, 05:58:24 PM
ok, this is what i've got from what you've told me, but it will need tweaking.

Uses a button called Sendbtn and a textbox called SendTxtBox

Code: [Select]
Imports LEGOVPBrickLib

Public Class Form1
    Const MyPort As Integer = 1 'change this to your usb port

    Private Sub SendBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendBtn.Click
        Static LegoThing As LEGOVPBrickLib.VPBrick
        Try
            LegoThing.Open(MyPort.ToString)
            LegoThing.Download(SendTxtBox.Text)
        Catch ex As Exception
            MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "An error has occured.")
        End Try
    End Sub
End Class
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 10, 2008, 03:43:50 PM
ok the build succeded but when i press the SendBtn i get an error message that says "Error: Object reference not set to an instance of an object"
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 11, 2008, 12:41:25 AM
What did you use for your usb port number?
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 11, 2008, 02:17:38 PM
1. but how do i find out what usb port # its on?
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 11, 2008, 08:37:50 PM
It won't be port 1, i'm not sure what that is, i was just using an example. I don't actually know, nor do I know how to find out... maybe someone else knows how to find out?
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 12, 2008, 05:25:26 PM
ok i change the number to many times and still i get the same error message.
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 12, 2008, 11:29:09 PM
Code: [Select]
Imports LEGOVPBrickLib

Public Class Form1
    Const MyPort As Integer = 1 'change this to your usb port

    Private Sub SendBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendBtn.Click
        Static LegoThing As New LEGOVPBrickLib.VPBrick '*new* was needed
        Try
            LegoThing.Open(MyPort.ToString)
            LegoThing.Download(SendTxtBox.Text)
        Catch ex As Exception
            MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical, "An error has occured.")
        End Try
    End Sub
End Class

I tried this on my computer but I believe your dll needs a heck of a lot of code to interface with it as it was returning a COMException and an InnerException, which means I need to dissassemble the dll to know what to send to it, which takes a very long time and is incredibly difficult. I could try, but
1: without the mindstorms set I have no way of testing it and
2: it would take me at least 2 weeks, probably 3 to write the code.

Is there a manual that comes with your mindstorms set which tells you how it can work? Or a ReadMe that came with the dll? Anything at all that came that can give me a headstart?
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 13, 2008, 06:03:04 AM
the help file that came with the dll is to large can i send it to u by email?
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 13, 2008, 09:11:57 PM
Feel free. I will PM you my email.
Title: Re: New to VB Express How do i work with Dll's
Post by: Bones92 on February 17, 2008, 08:44:58 PM
I'm very sorry, but It just won't work, no matter what I do. Do you know anybody who has successfully communicated with the set? You may have to ask them how its done.

I even tried and online "example" - it returned 57 errors.

Here is a link to a sample I found - its VB6, however

http://news.lugnet.com/robotics/?n=23464

Once again, I am very sorry.
Title: Re: New to VB Express How do i work with Dll's
Post by: macdad- on February 18, 2008, 09:15:46 AM
its ok thank you for trying.