hallo alle miteinander,
ich hab folgendes Problem:
ich habe in mein c# Projekt die usb2.dll (Version 1.7 von www.braintechnology.de) eingebunden! Die Funktionen habe ich auch extern deklariert! Nur wenn ich die Funktionen aurufe, ausser Usbinit( die funktioniert), bekomme ich als Rückgabewert false! (also Funktion wurde nicht erfolgreich ausgeführt!!
Ich hab keine Ahnung was ich dabei falsch gemacht gabe!
Vielleicht hat jemand ja das gleiche Problem wie ich und kann mir dabei helfen!
Danke für eure hilfe!
gruß dengel
ich hab folgendes Problem:
ich habe in mein c# Projekt die usb2.dll (Version 1.7 von www.braintechnology.de) eingebunden! Die Funktionen habe ich auch extern deklariert! Nur wenn ich die Funktionen aurufe, ausser Usbinit( die funktioniert), bekomme ich als Rückgabewert false! (also Funktion wurde nicht erfolgreich ausgeführt!!
Ich hab keine Ahnung was ich dabei falsch gemacht gabe!
Vielleicht hat jemand ja das gleiche Problem wie ich und kann mir dabei helfen!
Danke für eure hilfe!
gruß dengel
Code:
dll einbinden:
[DllImport("usb2.dll")]
public extern static bool UsbInit(byte DevNum);
[DllImport("usb2.dll")]
unsafe public extern static bool UsbSetLicense( char* Filename);
[DllImport("usb2.dll")]
public extern static bool UsbCheckSpeed(byte DevNum, byte Speed);
[DllImport("usb2.dll")]
public extern static bool UsbGetIOState(byte DevNum, byte LineNum, byte State);
[DllImport("usb2.dll")]
public extern static bool UsbI2CWriteByte(byte DevNum,byte SlaveAddr,byte Data);
[DllImport("usb2.dll")]
public extern static bool UsbI2CReadByte(byte DevNum,byte SlaveAddr,byte Data);
[DllImport("usb2.dll")]
public extern static bool UsbI2CWriteBytes(byte DevNum, byte SlaveAddr, short Length, int P);
[DllImport("usb2.dll")]
public extern static bool UsbI2CReadBytes(byte DevNum, byte SlaveAddr, short Length, int P);
[DllImport("usb2.dll")]
public extern static byte UsbGetError();
[DllImport("usb2.dll")]
unsafe public extern static bool UsbGetErrorStringByNr(byte ErrNr, char* PString);
funktionsaufruf:
public void USBinit()
{
bool result;
string datei = Application.StartupPath + @"\license.dat";
char[] filename = new char[datei.Length];
for(int j = 0; j < datei.Length; j++)
{
filename[j] = datei[j];
}
//unsicherer Code (Pointer)
unsafe
{
fixed (char* pfilename = filename)
{
//Licensefile einbinden
result = UsbSetLicense(pfilename);
}
}
errornr = UsbGetError();
if (UsbInit(DevNum) == true)
{
byte speed = 0;
if (UsbCheckSpeed(DevNum, speed) == true)
{
if (speed == 0)
MessageBox.Show("USB- Interface is connected to a \"full-speed\" Bus",
"message",MessageBoxButtons.OK, MessageBoxIcon.Information);
else
MessageBox.Show("USB- Interface is connected to a \"high-speed\" Bus",
"message",MessageBoxButtons.OK, MessageBoxIcon.Information);
for (int i=0; i<16; i++)
UsbGetIOState(DevNum, 0, speed);
}
else
{
MessageBox.Show("USB speed could not be determined!", "ERROR",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
else
{
MessageBox.Show("UsbInit failed!", "ERROR",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
errornr = UsbGetError();
}
Zuletzt bearbeitet: