Solved

calling a dll function...no errors....but returns the value -1

Posted on 2007-11-21
7
257 Views
Last Modified: 2013-11-25
hello sir/madam,
i have a Analog to digital converter card connected via usb port to my laptop. it converts the analog value and displays digital value. i want that digital value on my web page. To access that value i m trying to use the dll dunction which is used by that card
Private Declare Function ReadAnalogChannel Lib "C:\Inetpub\wwwroot\K8055D.DLL" (ByVal data As Long) As Long
Private Declare Function OpenDevice Lib "C:\Inetpub\wwwroot\K8055D.DLL" (ByVal N As Long) As Long
Dim data As Long
Dim i As Long
Dim N As Integer
Sub opencard()
i = OpenDevice(0)
End Sub
Sub callBeepDll()
data = ReadAnalogChannel(1)
End Sub
Private Sub cmd1_Click()
Dim data As Long
Call opencard
data = ReadAnalogChannel(1)
Text1.Text = data
End Sub
This is my code. In the description  of the card details says

If succeeded the return value will be the card address read from the K8055 hardware.
Return value -1 indicates that K8055 card was not found.

When i run this vb file...it gives me the value  -1. i.e. card is not connected. Can u plz give me solution or give me an alternate solution for this.
many thanks
0
Comment
Question by:Parvez_Siddiqui
  • 4
  • 3
7 Comments
 
LVL 25

Expert Comment

by:imitchie
ID: 20332419
are you sure the card can be found? maybe the dll cannot find the card due to other misconfiguration
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20332424
try

Sub opencard()
i = OpenDevice(0)
Text1.Text = i
End Sub
Sub callBeepDll()
data = ReadAnalogChannel(1)
End Sub
Private Sub cmd1_Click()
Dim data As Long
Call opencard
data = ReadAnalogChannel(1)
Text1.Text = Text1.Text & " " & data
End Sub
0
 

Author Comment

by:Parvez_Siddiqui
ID: 20332511
Hi imitchie,
I tried the code u said. its showing -1-1...

maybe the dll cannot find the card due to other misconfiguration.....can u plz explain wats the meaning of this..?
this is explained in the k8055 card pdf file


OpenDevice
Syntax
FUNCTION OpenDevice(CardAddress: Longint): Longint;
Parameter
CardAddress: Value between 0 and 3 which corresponds to the jumper (SK5, SK6) setting on the
K8055 board. See table 1.
Result
Longint: If succeeded the return value will be the card address read from the K8055 hardware.
Return value -1 indicates that K8055 card was not found.
Description
Opens the communication link to the K8055 card. Loads the drivers needed to communicate via the
USB port. This procedure must be performed before any attempts to communicate with the K8055
card.
This function can also be used to selects the active K8055 card to read and write the data. All the
communication routines after this function call are addressed to this card until the other card is
selected by this function call.
Example
var h: longint;
BEGIN
h:=OpenDevice(0); // Opens the link to card number 0
END;




ReadAnalogChannel
Syntax
FUNCTION ReadAnalogChannel (Channel: Longint): Longint;
4 Description of the DLL
© 2003 ... Velleman
Parameter
Channel: Value between 1 and 2 which corresponds to the AD channel whose status is to be read.
Result
Longint: The corresponding Analogue to Digital Converter data is read.
Description
The input voltage of the selected 8-bit Analogue to Digital converter channel is converted to a value
which lies between 0 and 255.
Example
var data: longint;
BEGIN
data := ReadAnalogChannel(1);
// AD channel 1 is read to variable 'data'
END;

MANY THANKS
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 25

Expert Comment

by:imitchie
ID: 20332526
try in Sub opencard()

i = OpenDevice(0)
Text1.Text = i
i = OpenDevice(1)
Text1.Text = Text1.Text & " " & i
i = OpenDevice(2)
Text1.Text = Text1.Text & " " & i
i = OpenDevice(3)
Text1.Text = Text1.Text & " " & i

FUNCTION OpenDevice(CardAddress: Longint):
CardAddress: Value between 0 and 3 which corresponds to the jumper (SK5, SK6) setting on the K8055 board. See table 1.

you may have the wrong CardAddress?
0
 

Author Comment

by:Parvez_Siddiqui
ID: 20334878
HI imitchie,
its showing me again -1...when the card is connected...i can see that it is connected via that k8055d card software...its also showing me the default value...but when i m calling through visual basic..it is giving me -1...plz help

0
 
LVL 25

Accepted Solution

by:
imitchie earned 500 total points
ID: 20335999
i'm afraid either
- the DLL has a problem, because we've tried the OpenDevice with all four CardAddresses and none are connecting
- or it cannot connect while you have the Card software connected (I hope you're not trying it with other software connecteD!)
0
 

Author Comment

by:Parvez_Siddiqui
ID: 20336797
hey imitchie...thanks dear....thank-you very very much...previuosly i was trying when the other software was connected...no i tried without that...and it worked...once again thanks dear...
bye
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This is about my first experience with programming Arduino.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now