?
Solved

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

Posted on 2007-11-21
7
Medium Priority
?
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
Lithium-ion batteries area cornerstone of today's portable electronic devices, and even though they are relied upon heavily, their chemistry and origin are not of common knowledge. This article is about a device on which every smartphone, laptop, an…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

800 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