-> Hier kostenlos registrieren
Hallo Leute!
Habe hier nen Versuchaufbau mit ner 315-2 PN/DP-CPU und programmiere mit C# die AGLink-Funktionen. So als kleinen Miniteil meiner Diplomarbeit, soll ich alle möglichen Funktionen von AGLink in C# verfügbar machen.
Leider hänge ich an der AGL_SetJobNotification fest, weil diese mir statt einer Benachrichtigungsinfo nur eine "System.AccessViolationException". Das kann wohl daran liegen, dass diese Methode nicht Asynchron aufgerufen wird.
Die Struktur für NOTIFICATION existierte in der AGL4DotNET.cs noch nicht, also habe ich sie von Hand definiert:
Und die Fkt. in der Form1.cs
Die Fkt. SetDevNotification und SetConnNotification sind entsprechend ähnlich aufgebaut. Diese liefern jedoch eh nur nullen, weil sicher der asynchrone Callback fehlt oder falsch programmiert ist. Da ich heute den ganzen Tag schon mit asynchronen Aufrufen und Delegaten herumgespielt habe und mir nicht im geringsten ein Lösungsansatz einfällt, bin ich schon langsam am verzweifeln.
Googlen brachte mir in diesem Fall nicht den gewünschten Erfolg.
Vielleicht hat jemand sowas ja mal für LibNoDave programmiert und kann mir dahingehend tips geben. Bin für jeden Hinweis/ Ratschlag etc. dankbar!
Grüße, Casi
Habe hier nen Versuchaufbau mit ner 315-2 PN/DP-CPU und programmiere mit C# die AGLink-Funktionen. So als kleinen Miniteil meiner Diplomarbeit, soll ich alle möglichen Funktionen von AGLink in C# verfügbar machen.
Leider hänge ich an der AGL_SetJobNotification fest, weil diese mir statt einer Benachrichtigungsinfo nur eine "System.AccessViolationException". Das kann wohl daran liegen, dass diese Methode nicht Asynchron aufgerufen wird.
Die Struktur für NOTIFICATION existierte in der AGL4DotNET.cs noch nicht, also habe ich sie von Hand definiert:
Code:
[SIZE=2][[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]StructLayout[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]LayoutKind[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].Sequential)][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]struct[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]NOTIFICATION[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]{ [/SIZE]
[SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] Siehe Handbuch Seite 135 [/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] Fensterhandle für Benachrichtigung über Message[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]HWND[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] hwnd;[/SIZE]
[SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] Nummer der Nachricht[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]uint[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] WndMessage;[/SIZE]
[SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] Falls Nachricht direkt an einen Thread geschickt werden soll[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]UInt32[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] dwThreadID;[/SIZE]
[SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] Gewünschte Nachricht für Thread[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]uint[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ThreadMessage;[/SIZE]
[SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] Benachrichtung über Event[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]HANDLE[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] hEvent;[/SIZE]
[SIZE=2][COLOR=#808080][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000] Callback-Implementierung[/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]IntPtr[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] cb; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// oder public delegate void CB_Func(); :confused: [/COLOR][/SIZE]
[/COLOR][/SIZE][SIZE=2]} [/SIZE]
Code:
[SIZE=2][[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]DllImport[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"AGLink40.dll"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2])][/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]static [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]extern [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]unsafe [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Int32[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] AGL_SetJobNotification([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Int32[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] JobNr, [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]NOTIFICATION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]* pN);[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]static [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]unsafe [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Int32[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] SetJobNotification([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]Int32[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] JobNr, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]out [/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]NOTIFICATION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] pN )[/SIZE]
[SIZE=2]{ [/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] RetVal = AGL40_SUCCESS;;[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]fixed[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]NOTIFICATION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]* notific = &pN)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]RetVal = AGL_SetJobNotification(JobNr, notific);[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (RetVal); [/SIZE]
[SIZE=2]}[/SIZE]
Und die Fkt. in der Form1.cs
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] DoSetJobNotification()[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] iRet;[/SIZE]
[SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]AGL4[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]NOTIFICATION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] pN = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]AGL4[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].[/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]NOTIFICATION[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]();[/SIZE]
[SIZE=2]AddMessageLine([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Nummer des Auftrages: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + iJobNo.ToString());[/SIZE]
[SIZE=2]AddMessageLine([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"ThreadID: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + pN.dwThreadID.ToString());[/SIZE]
[SIZE=2]AddMessageLine([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Event-Handle: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + pN.hEvent.ToString());[/SIZE]
[SIZE=2]AddMessageLine([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"Window-Handle"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + pN.hwnd.ToString());[/SIZE]
[SIZE=2]AddMessageLine([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"ThreadMessage: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + pN.ThreadMessage.ToString());[/SIZE]
[SIZE=2]AddMessageLine([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"WindowMessage: "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + pN.WndMessage.ToString());[/SIZE]
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ((iRet = [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]AGL4[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].SetJobNotification(iJobNo, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]out[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] pN)) == [/SIZE][SIZE=2][COLOR=#2b91af][SIZE=2][COLOR=#2b91af]AGL4[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].AGL40_SUCCESS)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]
Die Fkt. SetDevNotification und SetConnNotification sind entsprechend ähnlich aufgebaut. Diese liefern jedoch eh nur nullen, weil sicher der asynchrone Callback fehlt oder falsch programmiert ist. Da ich heute den ganzen Tag schon mit asynchronen Aufrufen und Delegaten herumgespielt habe und mir nicht im geringsten ein Lösungsansatz einfällt, bin ich schon langsam am verzweifeln.
Googlen brachte mir in diesem Fall nicht den gewünschten Erfolg.
Vielleicht hat jemand sowas ja mal für LibNoDave programmiert und kann mir dahingehend tips geben. Bin für jeden Hinweis/ Ratschlag etc. dankbar!
Grüße, Casi
Zuletzt bearbeitet: