K8055-QB64 ReadDigitalChannnel

I cannot find the right code in QB64 for reading the 5 input channels. All tries were not successful.

You can use the function “ReadAllDigital”.
Here an example code:[code]DIM h AS LONG

DECLARE DYNAMIC LIBRARY “k8055d”
FUNCTION OpenDevice& (BYVAL CardAddress AS LONG)
FUNCTION ReadAllDigital& ()
SUB CloseDevice
SUB SetAllDigital
SUB ClearAllDigital
END DECLARE

PRINT “Press any key to open device”
WHILE INKEY$ = “”
WEND

h = OpenDevice(0)
PRINT h
IF h = 0 THEN
PRINT “Card 0 opened”
ELSE
PRINT “Card 0 not found”
END IF

PRINT “Press any key to read all digital”
WHILE INKEY$ = “”
WEND

h = ReadAllDigital
PRINT h
PRINT "Input 1: "; (h AND 1)
PRINT "Input 2: "; (h AND 2) / 2
PRINT "Input 3: "; (h AND 4) / 4
PRINT "Input 4: "; (h AND 8) / 8
PRINT "Input 5: "; (h AND 16) / 16

PRINT “Press any key to close device”
WHILE INKEY$ = “”
WEND

CloseDevice

END[/code]

Thanks for support, will try asap. KR RWD

WOW! Thanks for that short program! It is exactly what I needed! I have been pulling my hair out trying to program this with visual basic in excel. I found I do NOT excel at that. I have done a lot of programming in QB45 and just found QB64. I am having fun with the K8055, I wasn’t a fan of the DLL’s however…

I’m glad you found this thread helpful.
Nice to be of assistance :slight_smile:

I am now having the same problem with Declare to Write all Digital to the output of the K8055.
If I declare it as " SUB WriteAllDigital () "
When I try to use it with “WriteAllDigital 1” I get the error Sub does not require an argument.
If I try to declare it as “SUB WriteAllDigital (byval data as long)” Qb64 says the declare statement is incorrect “Expected ) on the line”(line of the sub).
What is the proper way to Declare this sub?
Thanks,
Rog

Now it works.
You can’t use word “data” as a variable name.
“Data” seems to be reserved word of the QB64.

[code]DIM h AS LONG

DECLARE DYNAMIC LIBRARY “k8055d”
FUNCTION OpenDevice& (BYVAL CardAddress AS LONG)
SUB CloseDevice
SUB SetAllDigital
SUB ClearAllDigital
SUB WriteAllDigital (BYVAL data1 AS LONG)
END DECLARE

PRINT “Press any key to open device”
WHILE INKEY$ = “”
WEND

h = OpenDevice(0)
PRINT h
IF h = 0 THEN
PRINT “Card 0 opened”
ELSE
PRINT “Card 0 not found”
END IF

PRINT “Press any key to set all digital”
WHILE INKEY$ = “”
WEND

SetAllDigital

PRINT “Press any key to write all digital &H55”
WHILE INKEY$ = “”
WEND

WriteAllDigital (&H55)

PRINT “Press any key to clear all digital and close device”
WHILE INKEY$ = “”
WEND

ClearAllDigital

CloseDevice

END[/code]
Here are the lists of QBASIC and QB64 reserved words:
ousob.com/ng/qbasic/ng39706.php
qb64.net/wiki/index.php?titl … phabetical

Thanks,
Wow, that was confusing, I appreciate the help!
Rog

Ok I got my program to read 1 K8055 card just fine reading contact and adc inputs and making digital outputs. I can have more than 1 K8055 board attached, but, I am only refreshing my data from 1 card every second. This works GREAT!
Then I added 3 more boards. I am looking at the contact inputs on all 3 cards every second, using the qb64 “_LIMIT 1” command to delay and read the k8055 boards every second.
My problem is that my computer begins to slow down. If I watch the task manager the cpu usage was running at 30% then after a 30 minutes it was up to 60% and slowly climbing. The computer gets unusable and I need to reboot.
I then changed the command to " _LIMIT 2" and my task manager cpu time started at 8-9% then after 20 minutes the cpu usage was up to 15-16%.

Why is this happening when I am talking to more than 1 K8055 board?
Also when using more than 1 k8055 card, when I plug in the 2nd or third card it tells me that that usb device failed?
After plugging in the device a few times I am able to communicate with the device, even if the computer had told me that the device failed…

Thanks for your help,
Rog

Are you opening the communication to all the cards first using the OpenDevice(CardAddress) ?
Alternatively you can use the function SearchDevices() to open all the cards.
Then to switch the control between the cards are you using the function SetCurrentDevice(CardAddress) ?

For more info please see:
viewtopic.php?f=3&t=7427
viewtopic.php?f=3&t=9904

Thanks for your prompt reply!
yes, I am opening the channels with the opendevice command, this is used to find which devices are attached.
FOR a = 0 TO 3: H = OpenDevice(a): x = ReadAllDigital: CLOSE device
IF H = a THEN DEV(a) = 1: ELSE DEV(a) = 0:
NEXT a

What is the syntax for the functions SearchDevices() and SetCurrentDevice(CardAddress).

Is there a listing of syntax for using the qb64 commands for the K8055 like the pdf MAN_UK_K98055_DLL.pdf on the Velleman site for the K8055?

Do you know why my pc has a problem when I plug in the USB cable for the k8055’s and says the device failed, but, then after a few attempts I am able to connect to the device?

Well, I did some more messin’ with the device and I was able to use some of the commands that you requested, I could NOT get the SearchDevices() to work (could not get the correct syntax, I have kit boards they are numbered p8055-1 VELLEMAN 2003, are they old??).
I used H= SetCurrentDevice(a) to get the correct device required then ReadAllDidgital and WriteAllDigital.
This is working great cpu usage is staying low.

When I plug in a K8055 device located 45-50 feet from my pc, the pc gives an alarm “USB Device not recognized” if I replug the connector, I still get the alarm but it starts communicating. This may be because of the distance, the problem does not happen with a shorter cable.

Then I started trying to read the analog data. using the following program with device number 3. I could not get it to read analog no matter which command I used, What am I doing wrong???

DECLARE DYNAMIC LIBRARY “k8055d”
FUNCTION SetCurrentDevice& (BYVAL a AS INTEGER)
FUNCTION OpenDevice& (BYVAL a AS INTEGER)
FUNCTION ReadAllDigital& ()
FUNCTION ReadAnalogChannel (b AS INTEGER)
SUB ReadAllAnalog (c AS INTEGER, d AS INTEGER)
SUB WriteAllDigital (BYVAL e AS INTEGER)
SUB CloseDevice
SUB SetAllDigital
SUB ClearAllDigital
END DECLARE
LOCATE 5, 5: DEV = 3
H = OpenDevice(DEV): PRINT " open h="; H
'H = SetCurrentDevice(DEV): PRINT " setcurrentdevice h="; H
H = ReadAnalogChannel(DEV): PRINT " readanalogchannel h="; H
ReadAllAnalog c, d
CloseDevice:
PRINT " dev= "; H; " stop line 23 c= "; c; " d= “; d: INPUT " press enter”, k$:
STOP

Here’s a working example how to read the analog channels:

[code]DIM c AS LONG
DIM d AS LONG
DIM h AS LONG
DIM DEV AS LONG

DECLARE DYNAMIC LIBRARY “k8055d”
FUNCTION SetCurrentDevice& (BYVAL a AS LONG)
FUNCTION OpenDevice& (BYVAL a AS LONG)
FUNCTION ReadAllDigital& ()
FUNCTION ReadAnalogChannel& (BYVAL b AS LONG)
SUB ReadAllAnalog (c AS LONG, d AS LONG)
SUB WriteAllDigital (BYVAL e AS LONG)
SUB CloseDevice
SUB SetAllDigital
SUB ClearAllDigital
END DECLARE

DEV = 0
h = OpenDevice(DEV)
PRINT “open h=”; h

h = ReadAnalogChannel(1)
PRINT “Analog channel #1 value h=”; h

ReadAllAnalog c, d
PRINT “Analog channel #1 value c=”; c
PRINT “Analog channel #2 value d=”; d

INPUT “press enter”, k$
CloseDevice

END[/code]

The argument b of the function ReadAnalogChannel& (BYVAL b AS LONG) is the analog channel number, 1 or 2.

Please use data type ‘Long’ instead of ‘Integer’.

For more info please see QB64 Data types:
qb64.net/wiki/index.php?title=Data_types

The SearchDevices() works also with the old K8055 version with the K8055D.DLL version 4.0.0.0 or newer.

Thanks,
I appreciate your help!
Rog

[quote=“rogsyk”]Thanks,
I appreciate your help!
Rog[/quote]

how to send analog outputs

Hello guys…just found a great site where we can get amazing online resources. It is called WIN SOURCE. I encourage everyone here to try them out.They are very cheap.