Ik dacht dat je al een .NET library had die je gebruikte maar vergeten was bij de references toe te voegen. Maar waarschijnlijk heb je helemaal geen library.
In dat geval moet je de functies zelf declareren
Kijk in de header file (.h) naar de functies. Bijvoorbeeld:
VOID __stdcall ReadAnalogChannel(unsigned char CardAddress, unsigned char Channel);Plaats dan in je C# class de functie declaratie:
[DllImport("K8061_c.dll")]
private static extern unsafe void ReadAnalogChannel(byte cardAddress, byte channel);Daarna kun je gewoon de functie aanroepen. Voor de declaraties moet je wel wat types anders neerzetten:
char -> byte
unsigned char -> byte
long -> UInt32
long * -> ref UInt32edit
Even snel wat knip en plakwerk, probeer dit eens:
[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);
[DllImport("K8061_c.dll")]
private static extern unsafe byte PowerGood(byte CardAddress);
[DllImport("K8061_c.dll")]
private static extern unsafe byte Connected(byte CardAddress);
[DllImport("K8061_c.dll")]
private static extern unsafe void ReadVersion(byte CardAddress, ref UInt32 Buffer);
[DllImport("K8061_c.dll")]
private static extern unsafe void ReadAllAnalog(byte CardAddress, ref UInt32 Buffer);
[DllImport("K8061_c.dll")]
private static extern unsafe void OutputAnalogChannel(byte CardAddress, byte Channel, byte Data);
[DllImport("K8061_c.dll")]
private static extern unsafe void OutputAllAnalog(byte CardAddress, ref UInt32 Buffer);
[DllImport("K8061_c.dll")]
private static extern unsafe void ClearAnalogChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
private static extern unsafe void SetAllAnalog(byte CardAddress);
[DllImport("K8061_c.dll")]
private static extern unsafe void ClearAllAnalog(byte CardAddress);
[DllImport("K8061_c.dll")]
private static extern unsafe void SetAnalogChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
private static extern unsafe void OutputAllDigital(byte CardAddress, byte Data);
[DllImport("K8061_c.dll")]
private static extern unsafe void ClearDigitalChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
private static extern unsafe void ClearAllDigital(byte CardAddress);
[DllImport("K8061_c.dll")]
private static extern unsafe void SetDigitalChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
private static extern unsafe void SetAllDigital(byte CardAddress);
[DllImport("K8061_c.dll")]
private static extern unsafe bool ReadDigitalChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
private static extern unsafe byte ReadAllDigital(byte CardAddress);
[DllImport("K8061_c.dll")]
private static extern unsafe void OutputPWM(byte CardAddress, UInt32 Data);
[DllImport("K8061_c.dll")]
private static extern unsafe void Version();
[DllImport("K8061_c.dll")]
private static extern unsafe byte ReadBackDigitalOut(byte CardAddress);
[DllImport("K8061_c.dll")]
private static extern unsafe void ReadBackAnalogOut(byte CardAddress, ref UInt32 Buffer);
[DllImport("K8061_c.dll")]
private static extern unsafe UInt32 ReadBackPWMOut(byte CardAddress);Bovenin:
using System.Runtime.InteropServices;En bij je project settings onder build 'allow unsafe code' aanzetten.
[Bericht gewijzigd door madwizard op ]
free_electron
Silicon Member
Professioneel ElectronenTemmer - siliconvalleygarage.com - De voltooid verleden tijd van 'halfgeleider' is 'zand' ... US 8,032,693 / US 7,714,746 / US 7,355,303 / US 7,098,557 / US 6,762,632 / EP 1804159 - Real programmers write Hex into ROM
het eenvoudigste is gewoon die SLN file eens te openen. gans dat project laadt dan. en dan kan je zien hoe het werkt.
je zult in ieder geval een reference moeten toevoegen naar die DLL. ( hopelijk is dat een .NET DLL en geen ouwbollig ding. anders ga je prototypes moeten binnhalen.
nuja als je die SLN opent zul je zien hoe het ding werkt.
Zet er even bij wat er op die regel staat dan, anders is het gokken voor ons.
De sln (solution file) is voor C++.NET. De DLL is geen .NET DLL maar een normale DLL (met stdcall conventie). Dat kan nog altijd door meer software gebruikt worden dan een .NET DLL.
Maar prototypes zijn doodeenvoudig, wat ik postte is alles wat je nodig hebt.
Wel die DllImport erbij gezet? Nouja hoe dan ook is het nog beter om die functies in een aparte class te zetten. Maak een K8055D.cs bestand aan (zorg dat ie in je project komt) en kopieer dit letterlijk:
using System;
using System.Runtime.InteropServices;
namespace _055tim
{
class K8055D
{
[DllImport("K8061_c.dll")]
public static extern unsafe UInt32 OpenDevice();
[DllImport("K8061_c.dll")]
public static extern unsafe void CloseDevices();
[DllImport("K8061_c.dll")]
public static extern unsafe void ReadAnalogChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
public static extern unsafe byte PowerGood(byte CardAddress);
[DllImport("K8061_c.dll")]
public static extern unsafe byte Connected(byte CardAddress);
[DllImport("K8061_c.dll")]
public static extern unsafe void ReadVersion(byte CardAddress, ref UInt32 Buffer);
[DllImport("K8061_c.dll")]
public static extern unsafe void ReadAllAnalog(byte CardAddress, ref UInt32 Buffer);
[DllImport("K8061_c.dll")]
public static extern unsafe void OutputAnalogChannel(byte CardAddress, byte Channel, byte Data);
[DllImport("K8061_c.dll")]
public static extern unsafe void OutputAllAnalog(byte CardAddress, ref UInt32 Buffer);
[DllImport("K8061_c.dll")]
public static extern unsafe void ClearAnalogChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
public static extern unsafe void SetAllAnalog(byte CardAddress);
[DllImport("K8061_c.dll")]
public static extern unsafe void ClearAllAnalog(byte CardAddress);
[DllImport("K8061_c.dll")]
public static extern unsafe void SetAnalogChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
public static extern unsafe void OutputAllDigital(byte CardAddress, byte Data);
[DllImport("K8061_c.dll")]
public static extern unsafe void ClearDigitalChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
public static extern unsafe void ClearAllDigital(byte CardAddress);
[DllImport("K8061_c.dll")]
public static extern unsafe void SetDigitalChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
public static extern unsafe void SetAllDigital(byte CardAddress);
[DllImport("K8061_c.dll")]
public static extern unsafe bool ReadDigitalChannel(byte CardAddress, byte Channel);
[DllImport("K8061_c.dll")]
public static extern unsafe byte ReadAllDigital(byte CardAddress);
[DllImport("K8061_c.dll")]
public static extern unsafe void OutputPWM(byte CardAddress, UInt32 Data);
[DllImport("K8061_c.dll")]
public static extern unsafe void Version();
[DllImport("K8061_c.dll")]
public static extern unsafe byte ReadBackDigitalOut(byte CardAddress);
[DllImport("K8061_c.dll")]
public static extern unsafe void ReadBackAnalogOut(byte CardAddress, ref UInt32 Buffer);
[DllImport("K8061_c.dll")]
public static extern unsafe UInt32 ReadBackPWMOut(byte CardAddress);
}
}In je hoofdprogramma kun je de functies dan zo gebruiken:
K8055D.Version();timmie
niet met me uitspraken(of opmerkingen) eens mail me.K8048 guide
nog een stomme vraag waarom maak je gebruik van de K8061_c.dll? en niet van de K8055D.dll? het zal aan mij liggen maar dacht zal het ff navragen.
jdjere
If I had asked people what they wanted, they would have said "faster horses".
Heb mij ook zo'n k8061 kit besteld en die zou ik ook willen aansturen uiteraard met de pc...
Ik maak hier de bewuste keuze voor dat in visual basic te doen, kwestie van een gebruikersinterface te kunnen tekenen en de ervaring die ik er al mee heb opgedaan in de les is een pluspunt...
en dan nu de vraag::
hoe kun je, ergens in je code van visualbasic, de link leggen naar de usb interface... dat is iets waar ik totaal gene kaas van gegeten heb, dus alle info daarrond zou welkom zijn 
ergens heb ik al iets opgevangen over DLL files, maar daar weet ik ook al niet genoeg over...
alvast bedankt
timmie
niet met me uitspraken(of opmerkingen) eens mail me.K8048 guide
ff de manual van de DLL lezen als je er dan nog niet aan uit kmot kun je even contact met me opnemen ik ben er mee bezig maar nog geen tijd gehad voor een VB progje in elkaar te draaien voor de K8061
in de manual staat hoe je moet beginnen in VB Bladzijde 12