Hi Leute,
ich habe ein Programm zur Messdatenerfassung mit einem USB-Sensor erstellt. Den Code zum ansprechen des Sensors habe ich vom Hersteller verwendet und erweitert. Funktioniert so weit gut. Jetzt habe ich das Problem, daß bei Aus- und wieder Einstecken des Sensors manchmal dieser Fehler kommt:
CallbackOnCollectedDelegate wurde erkannt.
Message: Für den von der Garbage Collection gesammelten Delegaten vom Typ "GapController!GapController.Oak+tNotifyFct::Invoke" wurde ein Rückruf durchgeführt. Dies kann Anwendungsabstürze, Datenbeschädigung und -verlust zur Folge haben. Beim Übergeben von Delegaten an nicht verwalteten Code müssen die Delegaten von der verwalteten Anwendung beibehalten werden, bis sichergestellt ist, dass sie nie aufgerufen werden.
Der Code beinhaltet einen Connect- und Disconnect-Event, ich habe den m.E. wichtigen Teil mal angehängt.
Ähnliche Probleme wurden im Inet mit z.B. GC.keepalive() gelöst, ich bekomme das ganze aber nicht auf meinem Fall angepasst.
Hat jemand eine Idee ?
Gruß Georg
ich habe ein Programm zur Messdatenerfassung mit einem USB-Sensor erstellt. Den Code zum ansprechen des Sensors habe ich vom Hersteller verwendet und erweitert. Funktioniert so weit gut. Jetzt habe ich das Problem, daß bei Aus- und wieder Einstecken des Sensors manchmal dieser Fehler kommt:
CallbackOnCollectedDelegate wurde erkannt.
Message: Für den von der Garbage Collection gesammelten Delegaten vom Typ "GapController!GapController.Oak+tNotifyFct::Invoke" wurde ein Rückruf durchgeführt. Dies kann Anwendungsabstürze, Datenbeschädigung und -verlust zur Folge haben. Beim Übergeben von Delegaten an nicht verwalteten Code müssen die Delegaten von der verwalteten Anwendung beibehalten werden, bis sichergestellt ist, dass sie nie aufgerufen werden.
Der Code beinhaltet einen Connect- und Disconnect-Event, ich habe den m.E. wichtigen Teil mal angehängt.
Ähnliche Probleme wurden im Inet mit z.B. GC.keepalive() gelöst, ich bekomme das ganze aber nicht auf meinem Fall angepasst.
Hat jemand eine Idee ?
Gruß Georg
VB.NET-Quellcode
- <StructLayoutAttribute(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
- Public Structure tChannel
- <MarshalAsAttribute(UnmanagedType.I1)> Public IsSigned As Boolean
- Public BitSize As Byte
- Public UnitExponent As SByte
- Public Unit As UInteger
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=24)> Public UnitStr As String
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=24)> Public ChannelName As String
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=24)> Public UserChannelName As String
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=24)> Public UserChannelName_NV As String
- <MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=64, ArraySubType:=UnmanagedType.I1)> Public RFU() As Byte
- End Structure
- '
- ' Declaration of the tOak sensor structure that is compatible with the C structure defined in the C header file Oak.h
- '
- <StructLayoutAttribute(LayoutKind.Sequential, CharSet:=CharSet.Ansi)> _
- Public Structure tOakSensor
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=256)> Public DevicePath As String
- Public VID As UShort
- Public PID As UShort
- Public REV As UShort
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=24)> Public SN As String
- <MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=64, ArraySubType:=UnmanagedType.U1)> Public RFU() As Byte
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=24)> Public DeviceName As String
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=24)> Public UserDeviceName As String
- <MarshalAsAttribute(UnmanagedType.ByValTStr, SizeConst:=24)> Public UserDeviceName_NV As String
- Public NumChannels As UShort
- <MarshalAsAttribute(UnmanagedType.ByValArray, SizeConst:=11)> Public Channel() As tChannel
- End Structure
- Public Delegate Sub tNotifyFct(ByRef Sensor As tOakSensor, ByVal lParam As Integer) ' Declaration of the delegate function that will be used as the 'function pointer' for registereing callback
- '
- ' Step 2: Declare of the function that are present in the OakLib, With their parameter 'translated' to VB data types
- '
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Sub Oak_Initialize_a()
- End Sub
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Sub Oak_Hotplug_Enable_a()
- End Sub
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function Oak_Register_Callback_a(ByVal OnConnect As tNotifyFct, ByVal OnDisconnect As tNotifyFct, ByVal PID As UShort, ByVal REV As UShort, ByVal SN As String, ByVal DeviceName As String, ByVal ChannelName As String, ByVal UserDeviceName As String, ByVal UserChannelName As String, ByVal UserParam As Integer) As Boolean
- End Function
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Sub Oak_DestroyNotifications_a()
- End Sub
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Sub Oak_NotifyConnectedDevices_a()
- End Sub
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function Oak_FindSensor_a(ByVal PID As UShort, ByVal REV As UShort, ByVal SN As String, ByVal DeviceName As String, ByVal ChannelName As String, ByVal UserDeviceName As String, ByVal UserChannelName As String, ByRef SensorFound As tOakSensor) As Boolean
- End Function
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function Oak_Feature_a(ByVal DevicePath As String, ByVal RptBuffer() As Byte, ByVal ExpectResult As Boolean) As Boolean
- End Function
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function Oak_GetInReport_a(ByVal DevicePath As String, ByVal RptBuffer() As Byte, ByVal InReportLength As Byte, ByVal Timeout_ms As UShort) As Boolean
- End Function
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function Oak_GetCurrentInReport_a(ByVal DevicePath As String, ByVal RptBuffer() As Byte, ByVal InReportLength As Byte) As Boolean
- End Function
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Function Oak_SendOutReport_a(ByVal DevicePath As String, ByVal RptBuffer() As Byte, ByVal InReportLength As Byte, ByVal Timeout_ms As UShort) As Boolean
- End Function
- <DllImport("oaka.dll", CallingConvention:=CallingConvention.Cdecl)> Public Sub Oak_Cleanup_a()
- End Sub
- End Module
- Class Form1
- Dim MeinSensor As tOakSensor
- Public Sub ConnectCallback(ByRef Sensor As tOakSensor, ByVal lParam As Integer)
- SetSamplingParams(Sensor, 5)
- End Sub
- Public Sub DisconnectCallback(ByRef Sensor As tOakSensor, ByVal lParam As Integer)
- Console.WriteLine(vbCrLf & vbCrLf & "--> Disconnected: <--\n")
- End Sub