Multiple card programming and other Information required

Thankyou

What you have said is very helpful and also sounds like quite a bit of work!!! I would be quite willing to pay a fee if you could provide me with the sample and the component .dll. My email sashah@hotmail.co.uk

I of course understand that what you have done is not meant for or ready for commercial deployment yet however it would be extremely useful for my purposes. .NET is the standard these days and all manufacturers should provide ways and means to support .NET dev out of the box. It frustrates me that I have paid good money for a product but am then expected to downgrade to vb6 in order to develope anything rapidly. :frowning:

To ManniAT.
Do i get this right? You don’t use the K8061(_C).dll, instead you wrote your own code to communicate with the cards?
If so, can you show a bit of that code to help me start writing my own.
I have the (same) problem that the communication to the cards has to be simultanious with multiple threads (faster for all cards together). So i don’t lose to much time by reading each inputgroup after an other.

Hi Rob,

yes you are right - what we did is communicate directly to the card via HID.
The big difference between 8055 and 8061 is the protocol.
The 8055 “always” gives the current data if you read from the device.

With the 8061 you have to write to the device first (some kind of command like “Please send me analog 3 data” an AFTER this write you can read the data from the device.
At the moment we work only with the 8055 - so we have no idea about the timing and other things with the 8061.

About code - snippets would not be enough since (for an example) retriving the address (“filename”) for a HID device takes a lot of code and function calls.

Anyhow - the best way to become familiar with this google for HID programming.
Last not least the steps are easy:
Retrive the “address” of the device, open a (READ) file with async IO (overlapped) for it and than creat a stream out of this which you use to read.

For the 8055 this is quite easy - since read is independent of write.
For the 8061 (I guess) it shall work like this:
Open a file for read/write - write to the file - after completion start a read and adjust the timeout to a value which is big enough to ensure that you get the result.
But this is just an idea - we currently have no 8061 device so we can’t check this out.

Regards

Manfred

Manfred,
thank you for the reply.
Since i am just a beginning programmer (who likes to learn some more, every day) i think i will stick to the velleman dll for awhile.
I will search and test HID programming as you say, but not right now.
I am making a school project (open source domotica app. :wink: ) with these cards and for now i need all the time for the rest of my programming.
After this project i will definitely start with it becuase all inputs haves to be read continously to not miss any short pushes of a pushbutton.

Maybe there is an other way to have some time profit (like mulithreading). I don’t know. We’ll see.

Thanks.

Hi Rob,

HID programming in .NET means a lot of interop, async operations and other “nice” things :slight_smile:
Or in other words - it’s nothing you would do as a “beginners project”.

Anyhow - above I wrote that we decided to build our own wrapper - one of the reasons was timing.
BUT - there are a few things you should think about:
a.) especially the 8055 is not a real fast card (with the 8061 it’s much better)
b.) when we talk about “fast” this is a very relative thing (time is always relative as Albert Einstein proofed :slight_smile:).

So if you use the (I talk about the 8055) velleman DLL you will loose some time or better described - your app has to wait some time for a response.
This is what we avoid (due to full async handling).
To come to relative time - what are we talking about?
We talk about waiting for (let’s assume) 5 to 10 ms.
Or in other words - you make a read and this costs you 5ms - with 100 Reads this would mean half a second.
AFAIK the 8055 has a “read rate” of 40ms (I think I read something like this in the documentation)

  • so 40ms is the shortest time you can get results.
    Which means about 20 reads per second.
    If you use this read frequency you will “lose” - a thent of a second in your app.
    Divided up to 20 pieces of 5ms.
    I’m very sure that no user will have problems with this - this will not result in any “UI delays” (hanging menus or so).

The “problem” will occure on measurement precission - “aquisition rate” (I hope this makes sence - in german I would call it “Datenerfassungsrate”).
BUT - this has nothing to do with the velleman DLL - it depends on the hardware.

So the limit is not the 5ms “UI blocking” - it is the hardware.
5ms means nothing for a UI - it is pretty fast - you won’t see it.

If this “limitation” is to much for the solution you have to think about another hardware :slight_smile: (see below)
What I want to say: the velleman DLLs are OK in the most cases of use.
The negatives: no direct .NET support, some calls are blocking, “difficult” multi board handling.

And about “another hardware” - we had once a very interesting project.
There was an existing machine cutting section tubes with a disk saw.
The problem - if the saw blade becomes bluntish you have to change it (for sharpening).
So the goal was to find out the optimal time when a blade must be changed.
You can’t stop the machine for a check (the tubes are “running out” of the machine - stop means shutdown of the whole system).

So the idea was to measure the current used while cutting.
If the blade becomes blunt - the current will raise.
The process runs like - tube running by (a few seconds) - CUT (about 1 second) - tube running by…
Since tubes have different shapes you can’t say – oh, 7.6 A currency - change blade.
What we had to do was to build a graph of the cutting process.
The blade hit’s on corner - a bit higher currency - the blade hits more corners - higher currency - the blade cut’s the last part of the tube - lower currency.
The final approach was - (learning phase).
The operator uses a new blade to cut profile X.
He tells our system - this is “very OK”.
Than he cuts the same tube with a blunt blade - and tells our system - this is the limit.
Later we check the curves - detect the type of tube cutted - and check if the blade is OK.

To come to a point - to achive this goal we had to get as much measurement points as possible to have “detailed graphs”.
Our first approach - to take a digital sensor failed - the conversion / transmission time was too long.
The final result was a “CPU Board” with two high speed analog converters which measure (overlapped) the current taken by the motor.
–last not least we also measured some other things (blade speed, blade vibration and so on) - but this does not matter.
The “CPU Board” get’s a signal “Cutting starts” - and from that moment on it does nothing than collect values and buffer them.
–interrupts has bee turned of and other things were done to optimize read rate.
AFTER the cut - the board signaled the PC - I have data - and (using the delay to the next cut) it transfers the whole data to the PC system.

What I wanted to tell you with this story - don’t take too much care about timings - if it comes to “very fast reads” the hardware (analog convertors, sensors,…) will be the limit.
And if you talk about “…to not miss any short pushes of a pushbutton…” you talk finally about (relative) lengthy processes.
Even the debounce time (needed for a push button) comes to the ms range :slight_smile:
Assume a “very fast button pusher” - how often can he hit the button per second?
10 Times? - that means 100ms per push.
We talk about 5ms delay - 10ms read rate - so the user could press the button about 100 times per second before you reach the situation where you will loose data (oversee a push).
By the way - this user will be most of the time at the doctor - recreating his “button finger” :slight_smile:

I hope my thoughts could help you a bit.

Regards

Manfred

Hey Manfred,
Good explanation.
It is so that a user’s press on a button will take a long time (in millisecs) but the only thing i am worried about is:
if 8 cards are connected and i have to read each inputgroep one by one (= total of 16 readings) and each read takes 21ms than the fastest readingcycle will be 0,336 sec. This is only if there is no interuption by Windows (like building a userform). So it is that 0,336 sec that worries me. If i can communicate with each card in a separate thread, there is no problem. Then the readingcycle is only 42millisec.

For the moment you are my only help.
Nobody answers my question in this section.

You are right,

with 8 cards the summary brings up some possible timing problem.
I’m not very sure about the 8061 - but AFAIK it uses an extra DLL to communicate with the PIC (I only guess).

And I don’t know how this DLL is acting.
Let’s assume it is threadsafe.
8 Cards - mean 8 different USB devices.
So by design they should be adressable one by one (simul).

What happends (I guess) if you use the velleman DLL - the DLL is loaded once and you always communicate with this one thing.
BUT - if you rename the DLL (copies) and have 8 different named DLLs you should be able to have 8 different instances of them in memory.
Each one initialised to talk with exactly one card.

The next is (very) simple windows programming.
Start 8 Threads. Each Threadfunction calls “its own card DLL” to read the two inputs sections.

Starting such a thread means 3 lines of code - and you are done.
The only thing you should care about is memory handling (access lock) but even this can be done (in such a simple situation) by a “lock” statement.

And if you really worry about windows (blocking) - you can run those threads in RT priority.
Of course this means admin privileg to run the app (or more precise to set this thread priority) but for a “service” this should be no problem.
Even as a “normal” user you can set a quite high thread priority which should at leas “safe you from your own app”.
So what I mean is - another (for an examle a System) Process could block you - but no “lengty DB operation” in your app will be able to do this.
And if you make the system with 3 layers you should be able to avoid data loss.
Layer 1 your app - layer 2 a (buffering) handler for all boards as an own thread.
And finally the “board layer” which is nothing than simple thread (one per board) which reads the data to layer two for buffering.

And yes - it would be “nicer” to work with a full MT .NET component, but it should work with this “hack” also without too much problems.

Regards

Manfred

Hey Manfred.
This will help me a lot.
I just came up with the “brilliant” idea (stupid of me to think about it so late) to e-mail RE-Applications and ask them the capability of multithreading on there dll.
If not (or your solution is faster) i will definitely use it.

You see, i am a beginner who still has to learn a lot. (as if a programmer stops learning after a while :blush: :unamused: )

Anyway, thanks a lot to spend your time on this issue.

Best regards

Rob

Just got the answer that multithreading is not really possible :cry: .
Instance of DLL opens all the cards so it still has to “talk” to all the cards (one by one i assume).

Anyway, lets hope for the best when i start testing.

Inerresting - I would not really beleave this without checking!!!
The DLLs source opens the cards individually.
This is done by a call to mpusbapi.dll.

BUT - I don’t know if this DLL does “preopen” the cards.

In simple words:
The velleman DLL (k8061.dll) opens card by card (you must call CardOpen) via a call to mpusbapi.dll.
This call returns a “handle” - if a write (read) occures the velleman DLL checks if the card is open - if not an error occures.

If the mpusbapi.dll does open all cards - I don’t know - I’v got no source for this DLL.
But since this dll also works with LabView - and there cards are opended one by one - I guess it does not.
So it looks (for me) as if my approach would work.
As long as you ensure, that you do only call CardOpen with one number (specific for each instance of the copied velleman dll).

Regards

Manfred
PS: maybe I should buy such a device to see what’s going on :slight_smile:

Hey Manfred,
again an interresting reply.
For the instance of the DLL i have only one problem. I am learning the c# language in .NET.
A reference to the dll does not work (not a .net dll). Instead i have to use something like (copy-paste result):
[DllImport(“K8061_c.dll”)]
private static extern unsafe UInt32 OpenDevice();
[DllImport(“K8061_c.dll”)]
private static extern unsafe void CloseDevices();
[DllImport(“K8061_c.dll”)]
private static extern unsafe void ReadAnalogChannel(byte CardAddress, byte Channel);

So opening cards must be done several times (only 1 int returns with cardaddress 0 to 7) like you say.
But all are static methods so how do i create several instances (objects i assume) for this. Or do i write my own class with those [DllImport(“K8061_c.dll”)] private static extern unsafe void CloseDevices();… and then create 1 object (from my class) and 1 thread for each card and “communicate” with those object’s static methods. So i have 8 objects for 8 threads. But it still are static methods. You see i am not yet deep in to OO programming.
:question: Is that what i have to do (in a nutshell) ?

Best regards
Rob

The source for the old DLL is available from: vel255.diinoweb.com/files/K8061_DLL_source.zip
This DLL uses the functions of the mpusbapi.dll.
The new DLL (velleman.be/downloads/files/ … 2007v1.zip) doesn’t use mpusbapi.dll - instead it communicates directly with the Microchip’s Custom USB Drivers mchpusb.sys and mchpusb64.sys (I think…).

If you have Vista then this new DLL is the only alternative. Under XP you may try the old and the new one.
BTW: I think that duplicating and renaming the DLL should get the system to run faster…

[quote=“Rob1”]Hey Manfred,
again an interresting reply.
For the instance of the DLL i have only one problem. I am learning the c# language in .NET.
A reference to the dll does not work (not a .net dll). Instead i have to use something like (copy-paste result):
[DllImport(“K8061_c.dll”)]
private static extern unsafe UInt32 OpenDevice();
[DllImport(“K8061_c.dll”)]
private static extern unsafe void CloseDevices();
[DllImport(“K8061_c.dll”)]
private static extern unsafe void ReadAnalogChannel(byte CardAddress, byte Channel);

So opening cards must be done several times (only 1 int returns with cardaddress 0 to 7) like you say.
But all are static methods so how do i create several instances (objects i assume) for this. Or do i write my own class with those [DllImport(“K8061_c.dll”)] private static extern unsafe void CloseDevices();… and then create 1 object (from my class) and 1 thread for each card and “communicate” with those object’s static methods. So i have 8 objects for 8 threads. But it still are static methods. You see i am not yet deep in to OO programming.
:question: Is that what i have to do (in a nutshell) ?

Best regards
Rob[/quote]

Yes - you work with interop - thats right.
Assume you have a class with (for simplicity) 2 cards
(This is very bad design - I just want to show what I mean).
class MyBoards {
[DllImport(“K8061_cRenamedCopyONE.dll”, EntryPoint=“OpenDevice”)]
private static extern unsafe UInt32 OpenDevice1();
[DllImport(“K8061_cRenamedCopyTWO.dll”, EntryPoint=“OpenDevice”)]
private static extern unsafe UInt32 OpenDevice2();

public UInt32 OpenBoardOne() {
return(OpenDevice1());
}
public UInt32 OpenBoardOne() {
return(OpenDevice2());
}

BUT - sorry I have overseen this - OpenDevice takes no parameters :frowning:
And YES it opens all devices.
Which by the way reuqires a “reopen” if a new device is attached.

So sorry for the confusion - I was wrong reading the pascal sourcecode.

And it comes to what you have been told.
The vellman dll opens all devices - and there is no chance to use it in a multithreaded environment.

BUT - I still see a little chance - if the MPU…dll opens the devices in a shared mode.
So still every instance of the velleman dll would open all devices - but shared and you can run multiple instances of it.

This can be easily tried - write two differnt apps - reading some input.
And run them concurrently - if it works - great – if not the devices are not “shared open”.

Regards

Manfred

Hi,

is the source for the new DLL also available?

Regards

Manfred

All right. I will check it out.

Thank already.

The new DLL is developed by RE-Applications and I think that the source is not available.

Hi

I download the new driver pack for vista. I want to use this in XP with the K8055 board. The board automatically installs as a Human interface device, and when I run the sample I get error winusb not installed. How do I use these new drivers and samples in XP with the K8055? p.s. updating the HID driver in XP does not work.

Hi any ideas on using the new .dll and .net samples in XP with K8055 board??? I cannot see how to replace the drivers when its just a standard HID interface.

Any help appreiciated.

Thanks in advance

Sashah

Sorry,
I can’t help. I have only K8061.
RE-Applications told me it (K8061) is not “just a HID”. If your dll is the K8061… there is maybe nothing wrong (but the combination of dll with card).
Maybe thats a hint?

K8055 uses the HID driver.
The HID driver is part of the operating system.
There is no HID driver update available for the K8055

Did you download and extract the packages:
k8055dll_rev3_0_2.zip and k8055_dll_2_001.zip
from velleman.be/be/en/download/files/

There are no drivers in these packages.