Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi,

 

i'm at uni doing a project using the FTDI USB chip. It allows you to connect to it using a dll and control its logic pins.

 

I can connect to it fine in visual basic 6. But i'm trying to get it working in vb.net so i can start getting familiar with .net and vb.net does multi-threading.

 

I've copied the code from vb6 directly to vb.net and it seemed to compile fine so i'm assuming there are no language differences. But when i try to use the code i get errors returned from the dll and it won't allow me to connect.

 

Is there anything i should be doing or is the dll just not compatible with .net - but i thought dll's were usable by any language?

 

i've attached my code that just opens and closes the connection to the FTDI chip for you to have a look at.

 

Has anyone got any electronic books on vb.net, advanced features such as API calls, dll imports, mutli-threading? my book doesn't cover it.

 

Many Thanks

Posted

The code as it didn't attach properly in the form:

 

 

'Dll declarations

Private Declare Function FT_Open Lib "FTD2XX.DLL" (ByVal intDeviceNumber As Integer, ByRef lngHandle As Long) As Long

Private Declare Function FT_Close Lib "FTD2XX.DLL" (ByVal lngHandle As Long) As Long

 

' Return codes

Const FT_OK = 0

Const FT_INVALID_HANDLE = 1

Const FT_DEVICE_NOT_FOUND = 2

Const FT_DEVICE_NOT_OPENED = 3

Const FT_IO_ERROR = 4

Const FT_INSUFFICIENT_RESOURCES = 5

 

Private Sub TestBtn_Click()

Dim lngHandle As Long

 

'open the device

If FT_Open(0, lngHandle) <> FT_OK Then

msgbox "Open Failed"

Exit Sub

End If

 

'close the device

If FT_Close(lngHandle) <> FT_OK Then

msgbox "Close Failed"

exit sub

End If

end sub

  • Administrators
Posted

You may want to check the declare statements in VB.Net some of the data types have changed

 

i.e.

in VB6 Integer was 16 bits in .Net it is now 32 bits (a short is 16 bits)

 

a long was 32 but has changed to 64

 

try the following code instead

'Dll declarations
Private Declare Function FT_Open Lib "FTD2XX.DLL" (ByVal intDeviceNumber As short, ByRef lngHandle As Integer) As Integer
Private Declare Function FT_Close Lib "FTD2XX.DLL" (ByVal lngHandle As Integer) As Integer

 

btw - no promises, not tried the code (not even checked it compiles never mind runs)

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
that sounds like it'll work actually, because i did get an invalid parameter error code returned at some point while i was testing the other day. Many Thanks. I'll let you know tomoz
  • 6 years later...
Posted

Hi everyone,

 

I just found this thread and although it is quite old I hope someone can help me with it:

 

I am using FTDI USB chip and ftd2xx.dll to communicate with a PS 8360-30 (http://www.elektroautomatik.de/en/products/programmable/ps8000.html). I am trying to program it using VBA

 

I have read lots of tutorials and seen lots of examples, but still I cannot manage to make it work.

 

Here is the procedure that I am following:

 

 

-Open the device with the FT_Open() function � OK

-Reset the device to clear any existing settings with FT_ResetDevice() � OK

-Set the Baud rate to 57600 with FT_SetBaudRate() � OK

-Set data characteristics to 8 bits, stopbits=1 and odd parity with FT_SetDataCharacteristics() � OK

-Then we try to set the device in remote control ON sending it the following telegram (F1003610100147 - Contacted the developer and they confirmed that the telegram is correct) using FT_Write �

 

Initially, all the commands seem to work because the function does not return an error. However, the device does not recognize the write command because it does not set it to remote control.

 

Finally, we try to read what the device sends back with FT_Read, and it sends back what we I initially with the FT_Write function.

 

I am not sure where I am going wrong. This is the code:

 

 

ftbaudrate = 57600

ftStatus = FT_Open(0, ftopen)

If ftStatus = FT_OK Then

Worksheets("Sheet1").Cells(1, 1) = ftStatus

Else

MsgBox ("Open Failed")
Call closeonly
Exit Sub
End If


ftStatus = FT_ResetDevice(ftopen)
If ftStatus <> FT_OK Then
   Call closeonly
End If


ftStatus = FT_SetDtr(ftopen)
If ftStatus <> FT_OK Then
   Call closeonly
End If




ftStatus = FT_SetBaudRate(ftopen, ftbaudrate)
If ftStatus <> FT_OK Then
   Call closeonly
End If



ftStatus = FT_SetDataCharacteristics(ftopen, FT_BITS_8, FT_STOP_BITS_1, FT_PARITY_ODD)
If ftStatus <> FT_OK Then
   Call closeonly
End If

strBytesToWrite = "F1003610100129"
lngBytesToWrite = Len(strBytesToWrite)
lngRetVal = FT_Write(ftopen, strBytesToWrite, lngBytesToWrite, lngBytesToRead)

 

 

After this, the device should go on remote,but it is not working.

 

Any ideas? I am quite desperate because I have been fighting with this for a week!

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.

×
×
  • Create New...