Controlling Multiple K8055 Boards

Hi,

I need to develop an application which is capable of controlling/monitoring 4 of the K8055 boards simultaneously.

How does the DLL handle simultaneous commands to different K8055 boards?

For example, Is it possable to read analogue input 1 of card 1 at the same time as setting the digital output 2 of card 3? (as could be the case if my application was multithreaded).

The application i need to develop will need to monitor each analogue input from each of the four boards (8 analogue inputs), each analogue input will be attached to a pressure sensor. The application will need to control 4 digital outputs on each board, (12 digital outputs). Each board will be performing the same function, but each is connected to 2 different pressure sensors. the digital outputs will be set/unset depending on the analogue input value.

i get the impression that i will not be able to process all 4 boards in parallel, but instead i will have to keep switching between which board i wish to control/monitor.

Can someone please inform me how the DLL behaves if used in this mannor?

Kind Regards

Phil

You are right: It is not possible to read or write from/to multiple cards simultaneously.
You have to use SetCurrentDevice function to select the card used.
In this oscilloscope screenshot you’ll see there is about 2ms delay when switching the control to other card.

The complete procedure in Borland C++Builder was:
{
SetCurrentDevice (0);
ClearAllDigital();
SetCurrentDevice (1);
ClearAllDigital();
SetCurrentDevice (0);
SetDigitalChannel(1);
SetCurrentDevice (1);
SetDigitalChannel(1);
}

Thank you for your response.

Just thinking aloud here but would it be possable to avoid this scenario by having multiple DLL’s, one being assigned to each card?

After all, each card can be uniquely identified, and each card will be plugged into its own usb port.

is this feasable?

This multiple DLL solution may work (not tested).
I think there will be anyhow some time difference due to the USB polling interval of 10ms.

Do you think the same function would have to be defined multiple times, for each card/DLL?

My language of choice is VB.NET so an example declaration would look like this for multiple DLL’s:

Private Declare Function OpenDevice1 Lib "k8055d_CARD1.dll" (ByVal CardAddress As Long) As Long
Private Declare Function OpenDevice2 Lib "k8055d_CARD2.dll" (ByVal CardAddress As Long) As Long
Private Declare Function OpenDevice3 Lib "k8055d_CARD3.dll" (ByVal CardAddress As Long) As Long
Private Declare Function OpenDevice4 Lib "k8055d_CARD4.dll" (ByVal CardAddress As Long) As Long

Is there a way for you to test this? for example, have an application to poll an input of card 1 while setting the digital output of card 2 at the same time by using multiple DLL’s. I am unable to test this myself as i dont have access to multiple cards at this time.

Thank you for your continued assistance.

I made an Excel VBA macro to test this multiple DLL operation.
As I assumed there is about 10ms delay between the response of the different cards.

To use several DLLs you have to use Alias names as used in this example.

[code]Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Sub ClearAllDigital Lib “k8055d.dll” ()
Private Declare Sub SetDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)

Private Declare Function OpenDevice1 Lib “k8055d1.dll” Alias “OpenDevice” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice1 Lib “k8055d1.dll” Alias “CloseDevice” ()
Private Declare Sub ClearAllDigital1 Lib “k8055d1.dll” Alias “ClearAllDigital” ()
Private Declare Sub SetDigitalChannel1 Lib “k8055d1.dll” Alias “SetDigitalChannel” (ByVal Channel As Long)

Sub Button1_Click()
Dim h As Long
ActiveSheet.Cells(1, 4) = “”
ActiveSheet.Cells(1, 5) = “”
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 4) = “Card 1 connected”
Else
ActiveSheet.Cells(1, 4) = “Card 1 not found”
End If
h = OpenDevice1(1)
If h = 1 Then
ActiveSheet.Cells(2, 4) = “Card 2 connected”
Else
ActiveSheet.Cells(2, 4) = “Card 2 not found”
End If

End Sub

Sub Button3_Click()
ClearAllDigital
ClearAllDigital1
SetDigitalChannel (1)
SetDigitalChannel1 (1)

End Sub

Sub Button4_Click()
CloseDevice
CloseDevice1
End Sub[/code] Please note: In VB .NET the As Long (of this VB 6 example) must be changed to As Integer.

Thank you for testing the multiple DLL approach.
The code which i think i am going to have to write will have two elements:

I think a timer, or a loop in a seperate thread, will need to read both the analogue channels of all four cards every 500ms or so.

The second part will control the sending of commands to toggle the digital outputs of specific cards.

However, if i use the following code to read the analogue signals:

SetCurrentDevice (1);
ReadAllAnalogue(1); (i am still unfamilier with the function calls, bear with me)

and the following code to toggle digital outputs:

SetCurrentDevice (3);
SetDigitalChannel(2);

I can never be certain that the following will not occur:

SetCurrentDevice (1);
SetCurrentDevice (3);
SetDigitalChannel(2);
ReadAllAnalogue(1); (i am still unfamilier with the function calls, bear with me)

I hope this makes sense to you, i am not sure if i am explaining the problem very well.
I will respond to your replies tomorrow, this will be my last post today.

Kind Regards, Phil

I made changed the Excel VBA macro use a single DLL and function SetCurrentDevice.
There is still about 10ms delay between the response of the different cards.
Looking the oscilloscope screenshots it seems that using the SetCurrentDevice function is slightly faster than using multiple DLLs.

Here is my test code:

[code]Private Declare Function OpenDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib “k8055d.dll” ()
Private Declare Sub ClearAllDigital Lib “k8055d.dll” ()
Private Declare Sub SetDigitalChannel Lib “k8055d.dll” (ByVal Channel As Long)
Private Declare Function SetCurrentDevice Lib “k8055d.dll” (ByVal CardAddress As Long) As Long

Sub Button1_Click()
Dim h As Long
ActiveSheet.Cells(1, 4) = “”
ActiveSheet.Cells(1, 5) = “”
h = OpenDevice(0)
If h = 0 Then
ActiveSheet.Cells(1, 4) = “Card 1 connected”
Else
ActiveSheet.Cells(1, 4) = “Card 1 not found”
End If
h = OpenDevice(1)
If h = 1 Then
ActiveSheet.Cells(2, 4) = “Card 2 connected”
Else
ActiveSheet.Cells(2, 4) = “Card 2 not found”
End If

End Sub

Sub Button3_Click()
SetCurrentDevice (0)
ClearAllDigital
SetCurrentDevice (1)
ClearAllDigital
SetCurrentDevice (0)
SetDigitalChannel (1)
SetCurrentDevice (1)
SetDigitalChannel (1)

End Sub

Sub Button4_Click()
CloseDevice
End Sub[/code]

I have tweeked your code (vb.net)

what would happen if button 3 was clicked while executing the code in the timer? Would a race condition be created where both subs attempt to use the DLL for different purposes? (Imagine the timer is a seperate thread)

Private Declare Function OpenDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long
Private Declare Sub CloseDevice Lib "k8055d.dll" ()
Private Declare Sub ClearAllDigital Lib "k8055d.dll" ()
Private Declare Sub SetDigitalChannel Lib "k8055d.dll" (ByVal Channel As Long)
Private Declare Function SetCurrentDevice Lib "k8055d.dll" (ByVal CardAddress As Long) As Long

Sub Button1_Click()
    Dim h As Long
    ActiveSheet.Cells(1, 4) = ""
    ActiveSheet.Cells(1, 5) = ""
    h = OpenDevice(0)
    If h = 0 Then
        ActiveSheet.Cells(1, 4) = "Card 1 connected"
    Else
        ActiveSheet.Cells(1, 4) = "Card 1 not found"
    End If
        h = OpenDevice(1)
    If h = 1 Then
        ActiveSheet.Cells(2, 4) = "Card 2 connected"
    Else
        ActiveSheet.Cells(2, 4) = "Card 2 not found"
    End If

End Sub


'tick every 500ms
Private Sub tmrPoll_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrPoll.Tick

	SetCurrentDevice (0)
        PollAnalogue(ReadPressure)
	SetCurrentDevice (1)
        PollAnalogue(ReadPressure)  'what would happen if Button 3 was clicked while executing this line?
	SetCurrentDevice (2)
        PollAnalogue(ReadPressure)
	SetCurrentDevice (3)
        PollAnalogue(ReadPressure)
        
End Sub

private sub PollAnalogue

	dim data1, data2 as Long

	data1 = 0
	data2 = 0

	ReadAllAnalogue(Data1,Data2)

	'code to display data1,data2

End Sub

Sub Button3_Click()
    SetCurrentDevice (0)
    ClearAllDigital
    SetCurrentDevice (1)
    ClearAllDigital
    SetCurrentDevice (0)
    SetDigitalChannel (1)
    SetCurrentDevice (1)
    SetDigitalChannel (1)

End Sub

Sub Button4_Click()
    CloseDevice
End Sub

It may be good idea to disable Button 3 operation while the timer operations are in process.

Good Morning,

I do not think i have explained the situation very well.
If you were to create an Excel Macro which polled the analogue input of card 1 in a loop:

OpenDevice(1)
Do while true
     ReadAllAnalogue(1)
loop

And then created a second excel file with a simular macro which read card 2

OpenDevice(2)
Do while true
     ReadAllAnalogue(2)
loop

What would happen if you open both excel files and ran both the macros at the same time with 2 cards connected to your PC? Essentially, i will be creating an application which will control a single card. however, since 4 cards can be connected to a pc, i could have 4 applications, each communicating with a different card. Is this possable?

Maybe you should use the K8061, it would save you a lot of troubles, as it has more inputs and outputs, to avoid the use of multiple cards…

Hi,

I think i would have the same problem even using this card as i would be trying to [read from/write to] the card at the same time. I think i will have to write an interface for the DLL which accepts commands from my application(s) and queues them up before sending the command to the card(s). This should prevent multiple commands being sent to the card(s) at the same time. The test card my company has ordered should arrive in the next couple of days so i can begin experimenting with it.

Thank you very much for your assistance, it is greatly appreciated.

Hi,

My K8055 has arrived and i have downloaded the latest DLL.

where can i find the complete list of available subs/functions within the DLL, all the lists i have seen so far do not include the SetCurrentDevice Function, so i am assuming the lists i have seen are out of date.

Kind Regards

Phil

Please download this package to get the updated document:
k8055_dll_2_001.zip
DLL rev 2 with examples and source code (this source can be uses also with DLL Rev 3.)

The K8061 card reads all the 8 analogue inputs quite simultaneously.
In this thread there are some results displayed:
viewtopic.php?f=3&t=3497

continuing issues with the DLL described here

viewtopic.php?f=3&t=3684