Alex1987 Geschrieben October 2, 2015 at 00:08 Geschrieben October 2, 2015 at 00:08 Hallo Ich möchte in einer ListView / UID - Position - FW ... usw. anzeigen wie sollte man da am besten vorgehen, alles über AddHandler oder gibt es da eine dynamischere Lösung. Das mit "GetIdentity" hab Ich nicht so recht verstanden, wie das funktioniert. Würde mich über Ratschläge freuen. Imports Tinkerforge Public Class clsBrickCB Public ipcon As IPConnection = Nothing #Region "Bricks" Public BrickDC As BrickDC = Nothing Public BrickIMU As BrickIMU = Nothing Public BrickIMUV2 As BrickIMUV2 = Nothing Public BrickMaster As BrickMaster = Nothing Public BrickRED As BrickRED = Nothing Public BrickServo As BrickServo = Nothing Public BrickStepper As BrickStepper = Nothing #End Region #Region "Bricklets" Public BrickletAccelerometer As BrickletAccelerometer = Nothing Public BrickletAmbientLight As BrickletAmbientLight = Nothing Public BrickletAmbientLightV2 As BrickletAmbientLightV2 = Nothing Public BrickletAnalogIn As BrickletAnalogIn = Nothing Public BrickletAnalogInV2 As BrickletAnalogInV2 = Nothing Public BrickletAnalogOut As BrickletAnalogOut = Nothing Public BrickletAnalogOutV2 As BrickletAnalogOutV2 = Nothing Public BrickletBarometer As BrickletBarometer = Nothing 'Public BrickletBreakout As BrickletBreakout = Nothing Public BrickletColor As BrickletColor = Nothing Public BrickletCurrent12 As BrickletCurrent12 = Nothing Public BrickletCurrent25 As BrickletCurrent25 = Nothing Public BrickletDistanceIR As BrickletDistanceIR = Nothing Public BrickletDistanceUS As BrickletDistanceUS = Nothing Public BrickletDualButton As BrickletDualButton = Nothing Public BrickletDualRelay As BrickletDualRelay = Nothing Public BrickletDustDetector As BrickletDustDetector = Nothing Public BrickletGPS As BrickletGPS = Nothing Public BrickletHallEffect As BrickletHallEffect = Nothing Public BrickletHumidity As BrickletHumidity = Nothing Public BrickletIndustrialAnalogOut As BrickletIndustrialAnalogOut = Nothing Public BrickletIndustrialDigitalIn4 As BrickletIndustrialDigitalIn4 = Nothing Public BrickletIndustrialDigitalOut4 As BrickletIndustrialDigitalOut4 = Nothing Public BrickletIndustrialDual020mA As BrickletIndustrialDual020mA = Nothing Public BrickletIndustrialDualAnalogIn As BrickletIndustrialDualAnalogIn = Nothing Public BrickletIndustrialQuadRelay As BrickletIndustrialQuadRelay = Nothing Public BrickletIO16 As BrickletIO16 = Nothing Public BrickletIO4 As BrickletIO4 = Nothing Public BrickletJoystick As BrickletJoystick = Nothing Public BrickletLaserRangeFinder As BrickletLaserRangeFinder = Nothing Public BrickletLCD16x2 As BrickletLCD16x2 = Nothing Public BrickletLCD20x4 As BrickletLCD20x4 = Nothing Public BrickletLEDStrip As BrickletLEDStrip = Nothing Public BrickletLine As BrickletLine = Nothing Public BrickletLinearPoti As BrickletLinearPoti = Nothing Public BrickletLoadCell As BrickletLoadCell = Nothing Public BrickletMoisture As BrickletMoisture = Nothing Public BrickletMotionDetector As BrickletMotionDetector = Nothing Public BrickletMultiTouch As BrickletMultiTouch = Nothing Public BrickletNFCRFID As BrickletNFCRFID = Nothing Public BrickletPiezoBuzzer As BrickletPiezoBuzzer = Nothing Public BrickletPiezoSpeaker As BrickletPiezoSpeaker = Nothing Public BrickletPTC As BrickletPTC = Nothing Public BrickletRemoteSwitch As BrickletRemoteSwitch = Nothing Public BrickletRotaryEncoder As BrickletRotaryEncoder = Nothing Public BrickletRotaryPoti As BrickletRotaryPoti = Nothing Public BrickletRS232 As BrickletRS232 = Nothing Public BrickletSegmentDisplay4x7 As BrickletSegmentDisplay4x7 = Nothing Public BrickletSolidStateRelay As BrickletSolidStateRelay = Nothing Public BrickletSoundIntensity As BrickletSoundIntensity = Nothing Public BrickletTemperature As BrickletTemperature = Nothing Public BrickletTemperatureIR As BrickletTemperatureIR = Nothing Public BrickletTilt As BrickletTilt = Nothing Public BrickletVoltage As BrickletVoltage = Nothing Public BrickletVoltageCurrent As BrickletVoltageCurrent = Nothing #End Region Public Sub RConnection(Optional ByVal HOST As String = "localhost", Optional ByVal PORT As Integer = 4223) ipcon = New IPConnection() While True Try ipcon.Connect(HOST, PORT) Exit While Catch e As System.Net.Sockets.SocketException System.Console.WriteLine("Connection Error: " & e.Message) System.Threading.Thread.Sleep(1000) End Try End While AddHandler ipcon.EnumerateCallback, AddressOf EnumerateCB AddHandler ipcon.Connected, AddressOf ConnectedCB While True Try ipcon.Enumerate() Exit While Catch e As NotConnectedException System.Console.WriteLine("Enumeration Error: " & e.Message) System.Threading.Thread.Sleep(1000) End Try End While End Sub Private Sub ConnectedCB(ByVal sender As IPConnection, ByVal connectedReason As Short) If connectedReason = IPConnection.CONNECT_REASON_AUTO_RECONNECT Then System.Console.WriteLine("Auto Reconnect") While True Try ipcon.Enumerate() Exit While Catch e As NotConnectedException System.Console.WriteLine("Enumeration Error: " & e.Message) System.Threading.Thread.Sleep(1000) End Try End While End If End Sub Private Sub EnumerateCB(ByVal sender As IPConnection, ByVal uid As String, _ ByVal connectedUid As String, ByVal position As Char, _ ByVal hardwareVersion() As Short, ByVal firmwareVersion() As Short, _ ByVal deviceIdentifier As Integer, ByVal enumerationType As Short) If enumerationType = IPConnection.ENUMERATION_TYPE_CONNECTED Or enumerationType = IPConnection.ENUMERATION_TYPE_AVAILABLE Then If enumerationType = IPConnection.ENUMERATION_TYPE_DISCONNECTED Then System.Console.WriteLine("DISCONNECTED") Return End If 'Bricks / 7 If deviceIdentifier = BrickDC.DEVICE_IDENTIFIER Then Try BrickDC = New BrickDC(uid, ipcon) System.Console.WriteLine("BrickDC initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickDC init failed: " & e.Message) BrickDC = Nothing End Try ElseIf deviceIdentifier = BrickIMU.DEVICE_IDENTIFIER Then Try BrickIMU = New BrickIMU(uid, ipcon) System.Console.WriteLine("BrickIMU initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickIMU init failed: " & e.Message) BrickIMU = Nothing End Try ElseIf deviceIdentifier = BrickIMUV2.DEVICE_IDENTIFIER Then Try BrickIMUV2 = New BrickIMUV2(uid, ipcon) System.Console.WriteLine("BrickIMUV2 initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickIMUV2 init failed: " & e.Message) BrickIMUV2 = Nothing End Try ElseIf deviceIdentifier = BrickMaster.DEVICE_IDENTIFIER Then Try BrickMaster = New BrickMaster(uid, ipcon) System.Console.WriteLine("BrickMaster initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickMaster init failed: " & e.Message) BrickMaster = Nothing End Try ElseIf deviceIdentifier = BrickRED.DEVICE_IDENTIFIER Then Try BrickRED = New BrickRED(uid, ipcon) System.Console.WriteLine("BrickRED initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickRED init failed: " & e.Message) BrickRED = Nothing End Try ElseIf deviceIdentifier = BrickServo.DEVICE_IDENTIFIER Then Try BrickServo = New BrickServo(uid, ipcon) System.Console.WriteLine("BrickServo initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickServo init failed: " & e.Message) BrickServo = Nothing End Try ElseIf deviceIdentifier = BrickStepper.DEVICE_IDENTIFIER Then Try BrickStepper = New BrickStepper(uid, ipcon) System.Console.WriteLine("BrickStepper initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickStepper init failed: " & e.Message) BrickStepper = Nothing End Try End If 'Bricklets If deviceIdentifier = BrickletAccelerometer.DEVICE_IDENTIFIER Then Try BrickletAccelerometer = New BrickletAccelerometer(uid, ipcon) System.Console.WriteLine("BrickletAccelerometer initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletAccelerometer init failed: " & e.Message) BrickletAccelerometer = Nothing End Try ElseIf deviceIdentifier = BrickletAmbientLight.DEVICE_IDENTIFIER Then Try BrickletAmbientLight = New BrickletAmbientLight(uid, ipcon) System.Console.WriteLine("BrickletAmbientLight initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletAmbientLight init failed: " & e.Message) BrickletAmbientLight = Nothing End Try ElseIf deviceIdentifier = BrickletAmbientLightV2.DEVICE_IDENTIFIER Then Try BrickletAmbientLightV2 = New BrickletAmbientLightV2(uid, ipcon) System.Console.WriteLine("BrickletAmbientLightV2 initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletAmbientLightV2 init failed: " & e.Message) BrickletAmbientLightV2 = Nothing End Try ElseIf deviceIdentifier = BrickletAnalogIn.DEVICE_IDENTIFIER Then Try BrickletAnalogIn = New BrickletAnalogIn(uid, ipcon) System.Console.WriteLine("BrickletAnalogIn initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletAnalogIn init failed: " & e.Message) BrickletAnalogIn = Nothing End Try ElseIf deviceIdentifier = BrickletAnalogInV2.DEVICE_IDENTIFIER Then Try BrickletAnalogInV2 = New BrickletAnalogInV2(uid, ipcon) System.Console.WriteLine("BrickletAnalogInV2 initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletAnalogInV2 init failed: " & e.Message) BrickletAnalogInV2 = Nothing End Try ElseIf deviceIdentifier = BrickletAnalogOut.DEVICE_IDENTIFIER Then Try BrickletAnalogOut = New BrickletAnalogOut(uid, ipcon) System.Console.WriteLine("BrickletAnalogOut initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletAnalogOut init failed: " & e.Message) BrickletAnalogOut = Nothing End Try ElseIf deviceIdentifier = BrickletAnalogOutV2.DEVICE_IDENTIFIER Then Try BrickletAnalogOutV2 = New BrickletAnalogOutV2(uid, ipcon) System.Console.WriteLine("BrickletAnalogOutV2 initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletAnalogOutV2 init failed: " & e.Message) BrickletAnalogOutV2 = Nothing End Try ElseIf deviceIdentifier = BrickletBarometer.DEVICE_IDENTIFIER Then Try BrickletBarometer = New BrickletBarometer(uid, ipcon) System.Console.WriteLine("BrickletBarometer initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletBarometer init failed: " & e.Message) BrickletBarometer = Nothing End Try ElseIf deviceIdentifier = BrickletColor.DEVICE_IDENTIFIER Then Try BrickletColor = New BrickletColor(uid, ipcon) System.Console.WriteLine("BrickletColor initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletColor init failed: " & e.Message) BrickletColor = Nothing End Try ElseIf deviceIdentifier = BrickletCurrent12.DEVICE_IDENTIFIER Then Try BrickletCurrent12 = New BrickletCurrent12(uid, ipcon) System.Console.WriteLine("BrickletCurrent12 initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletCurrent12 init failed: " & e.Message) BrickletCurrent12 = Nothing End Try ElseIf deviceIdentifier = BrickletCurrent25.DEVICE_IDENTIFIER Then Try BrickletCurrent25 = New BrickletCurrent25(uid, ipcon) System.Console.WriteLine("BrickletCurrent25 initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletCurrent25 init failed: " & e.Message) BrickletCurrent25 = Nothing End Try ElseIf deviceIdentifier = BrickletDistanceIR.DEVICE_IDENTIFIER Then Try BrickletDistanceIR = New BrickletDistanceIR(uid, ipcon) System.Console.WriteLine("BrickletDistanceIR initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletDistanceIR init failed: " & e.Message) BrickletDistanceIR = Nothing End Try ElseIf deviceIdentifier = BrickletDistanceUS.DEVICE_IDENTIFIER Then Try BrickletDistanceUS = New BrickletDistanceUS(uid, ipcon) System.Console.WriteLine("BrickletDistanceUS initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletDistanceUS init failed: " & e.Message) BrickletDistanceUS = Nothing End Try ElseIf deviceIdentifier = BrickletDualButton.DEVICE_IDENTIFIER Then Try BrickletDualButton = New BrickletDualButton(uid, ipcon) System.Console.WriteLine("BrickletDualButton initialized") Catch e As TinkerforgeException System.Console.WriteLine("BrickletDualButton init failed: " & e.Message) BrickletDualButton = Nothing End Try End If End If End Sub End Class Zitieren
photron Geschrieben October 2, 2015 at 07:51 Geschrieben October 2, 2015 at 07:51 Die dynamische Lösung ist über den Enumerate Callback, so wie du sie da hast. Der Enumerate Callback gibt dir alle Informationen und erlaubt dir alle Bricks und Bricklets zu finden ohne vorher wissen zu müssen welche vorhanden sind und welche UIDs sie haben. Im Enumerate Callback findet GetIdentity keine Anwendung, da dir Enumerate schon alle Information gibt, die dir GetIdentity geben kann. GetIdentity ist für den Fall nützlich, dass du mit einem bestimmten Brick(let) arbeiten willst und dessen UID und Typ schon kennst. Dann kannst du ein entsprechendes Brick(let) Objekt erstellen, anhand der UID, und mit GetIdentity weitere Informationen über das Brick(let) erhalten. Zum Beispiel, seine Firmware Version oder die Position im Stack. Zitieren
XZ3RO Geschrieben October 28, 2015 at 10:17 Geschrieben October 28, 2015 at 10:17 Delegate Sub SetTextCallback([type] As String, [uid] As String, [connectedUid] As String, [position] As String, [hardwareVersion] As String, [firmwareVersion] As String, [deviceIdentifier] As String, [enumerationType] As String) Private Sub SetText(ByVal [type] As String, ByVal [uid] As String, ByVal [connectedUid] As String, ByVal [position] As String, ByVal [hardwareVersion] As String, ByVal [firmwareVersion] As String, ByVal [deviceIdentifier] As String, ByVal [enumerationType] As String) ' InvokeRequired required compares the thread ID of the ' calling thread to the thread ID of the creating thread. ' If these threads are different, it returns true. If Me.ListBox1.InvokeRequired Then Dim d As New SetTextCallback(AddressOf SetText) Me.Invoke(d, New Object() {[type], [uid], [connectedUid], [position], [hardwareVersion], [firmwareVersion], [deviceIdentifier], [enumerationType]}) Else Me.ListBox1.Items.Add([type] & " " & [uid] & " " & [position] & " " & [hardwareVersion] & " " & [firmwareVersion] & " " & [deviceIdentifier] & " " & [enumerationType]) End If End Sub 'im EnumerateCB Dim hwv As String = hardwareVersion(0) & "." & hardwareVersion(1) & "." & hardwareVersion(2) Dim fwv As String = firmwareVersion(0) & "." & firmwareVersion(1) & "." & firmwareVersion(2) SetText("BrickMaster", uid, connectedUid, position, hwv, fwv, deviceIdentifier, enumerationType) Zitieren
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.