Ich habe mal mit VB.net und DirectX ein Programm zusammen geflickt das dir weiterhelfen koennte..
Ich schau heute Abend ob ich da noch Quellcodes von habe.
(ist aber Bricolage)
Gruss, Andreas
Ich habe mal mit VB.net und DirectX ein Programm zusammen geflickt das dir weiterhelfen koennte..
Ich schau heute Abend ob ich da noch Quellcodes von habe.
(ist aber Bricolage)
Gruss, Andreas
Nam et ipsa scientia potestas est..
Danke für die Hilfe soweit!
Ich hab jetzt ein Programm gefunden, dass mit meinem Joystick funktioniert:
http://bienert-projects.de/blog/?p=90
Ich bin nur gerade am verzweifeln wie ich das in mein Programm einsetze.
Entweder geht nur der Joystick oder nur der Maestro, zusammen funktioniert es noch nicht.
Also das ist mein Programmcode:
Imports Pololu.UsbWrapper
Imports Pololu.Usc
Imports System
Imports System.Text
Imports System.ComponentModel
Public Class MainWindow
Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs)
TrySetTarget(0, TrackBar1.Value * 4) ' Richtet den Servo 0 nach dem Schieberegler aus.
End Sub
Sub Servo_0_up_down_ValueChanged(ByVal sender As Object, ByVal e As _
System.EventArgs)
TrySetTarget(0, Servo_0_up_down.Value * 4)
End Sub
''' <summary>
''' This function runs when the user clicks the Disable button.
''' </summary>
Sub ButtonDisable_Click(ByVal sender As Object, ByVal e As EventArgs)
' Set target of channel 0 to 0. This tells the Maestro to stop
' transmitting pulses on that channel. Any servo connected to it
' should stop trying to maintain its position.
TrySetTarget(0, 0)
End Sub
Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs)
TrySetTarget(1, TrackBar2.Value * 4) ' Richtet den Servo 1 nach dem Schieberegler aus.
End Sub
Sub Servo_1_up_down_ValueChanged(ByVal sender As Object, ByVal e As _
System.EventArgs)
TrySetTarget(1, Servo_1_up_down.Value * 4)
End Sub
''' <summary>
''' This function runs when the user clicks the Disable button.
''' </summary>
Sub ButtonDisable2_Click(ByVal sender As Object, ByVal e As EventArgs)
' Set target of channel 1 to 0. This tells the Maestro to stop
' transmitting pulses on that channel. Any servo connected to it
' should stop trying to maintain its position.
TrySetTarget(1, 0)
End Sub
Private Sub TrackBar3_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs)
TrySetTarget(2, TrackBar1.Value * 4) ' Richtet den Servo 2 nach dem Schieberegler aus.
End Sub
Sub Servo_2_up_down_ValueChanged(ByVal sender As Object, ByVal e As _
System.EventArgs)
TrySetTarget(2, Servo_2_up_down.Value * 4)
End Sub
''' <summary>
''' This function runs when the user clicks the Disable button.
''' </summary>
Sub ButtonDisable3_Click(ByVal sender As Object, ByVal e As EventArgs)
' Set target of channel 2 to 0. This tells the Maestro to stop
' transmitting pulses on that channel. Any servo connected to it
' should stop trying to maintain its position.
TrySetTarget(2, 0)
End Sub
''' <summary>
''' Attempts to set the target of
''' </summary>
''' <param name="channel">Channel number from 0 to 23.</param>
''' <param name="target">
''' Target, in units of quarter microseconds. For typical servos,
''' 6000 is neutral and the acceptable range is 4000-8000.
''' </param>
Sub TrySetTarget(ByVal channel As Byte, ByVal target As UInt16)
Try
Using device As Usc = connectToDevice() ' Find a device and temporarily connect.
device.setTarget(channel, target)
' device.Dispose() is called automatically when the "Using" block ends,
' allowing other functions and processes to use the device.
End Using
Catch exception As Exception ' Handle exceptions by displaying them to the user.
displayException(exception)
End Try
End Sub
''' <summary>
''' Connects to a Maestro using native USB and returns the Usc object
''' representing that connection. When you are done with the
''' connection, you should close it using the Dispose() method so that
''' other processes or functions can connect to the device later. The
''' "Using" statement can do this automatically for you.
''' </summary>
Function connectToDevice() As Usc
' Get a list of all connected devices of this type.
Dim connectedDevices As List(Of DeviceListItem) = Usc.getConnectedDevices()
For Each dli As DeviceListItem In connectedDevices
' If you have multiple devices connected and want to select a particular
' device by serial number, you could simply add some code like this:
' If dli.serialNumber <> "00012345" Then
' Continue For
' End If
Dim device As Usc = New Usc(dli) ' Connect to the device.
Return device ' Return the device.
Next
Throw New Exception("Der Controller konnte nicht gefunden werden. Überprüfen Sie die USB-Verbindung! ")
End Function
''' <summary>
''' Displays an exception (error) to the user by popping up a message box.
''' </summary>
Sub displayException(ByVal exception As Exception)
Dim stringBuilder As StringBuilder = New StringBuilder()
Do
stringBuilder.Append(exception.Message & " ")
If TypeOf exception Is Win32Exception Then
Dim win32Exception As Win32Exception = DirectCast(exception, Win32Exception)
stringBuilder.Append("Error code 0x" + win32Exception.NativeErrorCode.ToString("x") + ". ")
End If
exception = exception.InnerException
Loop Until (exception Is Nothing)
MessageBox.Show(stringBuilder.ToString(), Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Sub
Sub Maus_Check(ByVal sender As System.Object, ByVal e As System.EventArgs)
If Maussteuerung.Checked = True Then
Maussteuerung.Text = "aktiviert"
Else
Maussteuerung.Text = "deaktiviert"
End If
End Sub
Sub XY_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs)
'Ausgabe des XY-Wertes der Maus
Dim xachse, yachse As String
xachse = e.Location.X
yachse = e.Location.Y
lbl_koord.Text = (500 + xachse * 3) & "-" & (400 + yachse * 2.7)
If Maussteuerung.Checked = True Then
TrySetTarget(0, (2000 - xachse * 2.* 4)
TrySetTarget(1, (400 + yachse * 2.7) * 4)
Else
End If
End Sub
Private Declare Function joyGetPos Lib "winmm.dll" (ByVal uJoyID As Integer, ByRef pji As JOYINFO) As Integer
Private Structure JOYINFO
Dim X As Integer
Dim Y As Integer
Dim Z As Integer
Dim Buttons As Integer
End Structure
Dim JInfo As JOYINFO
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
joyGetPos(0, JInfo) 'Joystick 0
TextBox1.Text = "B :" + Str$(JInfo.Buttons)
TextBox2.Text = "X :" + Str$(JInfo.X)
TextBox3.Text = "Y :" + Str$(JInfo.Y)
End Sub
End Class
Jetzt muss ich noch das andere Programm reinbasteln.
Nur bisher hat er entweder nicht reagiert oder irgendwelche sinnlosen Fehler angegeben.
So..
[neuer Link unten]
Vllt. kannst du daraus ein paar Schnippsel brauchen. (alles was serialport ist kannst du ignorieren..war nur ein Test von mir)
Das verwendet DirectX.DirectInput, du brauchst dafür das DirectX SDK auf dem Rechner.
Auslesen kannst du damit alle DirectInput fähigen Geräte..USB Joysticks, Gamepads, Tastatur, Maus, etc..
Du darfst mich nur nix mehr darüber fragen..das ist ne kleine Ewigkeit her
Gruss, Andreas
Geändert von BastelWastel (08.08.2011 um 22:26 Uhr)
Nam et ipsa scientia potestas est..
@ BastelWastel: Vielen Dank für die Datei! Ich werde das gleich mal ausprobieren.
Nur für was brauche ich das DirectX SDK? Das Beispiel das ich im Internet gefunden habe geht auch so.
Die DirecX.Directimput ist irgendwo im Systemordner von meinem PC. Mein Programm spuckt jedenfalls immer diesen Fehler aus:
Die Datei oder Assembly "Microsoft.DirectX.DirectInput.dll" oder eine Abhängigkeit davon wurde nicht gefunden. ist keine zulässige Win32-Anwendung. (Ausnahme von HRESULT: 0x800700C1)
Die Datei ist aber wie ich schon geschrieben hab da. Kann das daran liegen dass ich ein 64-Bit System habe?
Und wenn ja wie kann ich das in Visual Basic umstellen.
So , hab das Programm nochmal durchgenudelt..alten krams gelöscht und getestet..
https://rapidshare.com/files/3670361...stick_test.rar
Bei mir läufts mit VB2010, mußte nur das .NET Framework auf 3.5 zurück stellen.
Das SDK brauchst du nichtmal..hatte das nur irgendwie noch im Hinterkopf..
Du mußt glaub ich 2 Verweise mit in dein Projekt einbinden..die DirectX.dll und die DirectInput.dll..weiß nicht ob die input allein reicht.
Mit 64bit OS hatte ich noch nichts zu tun
Gruss, Andreas
Nam et ipsa scientia potestas est..
Hallo,
ich habe zurzeit ein ähnliches Problem.
Wir müssen für ein Schulprojekt zwei Schrittmotoren welche mit einem Arduino an einen Computer angeschlossen ist fernsteuern. Der Computer ist mit einem weiteren Computer über Lan verbunden. Am zweiten Computer ist ein USB Joystick angeschlossen welcher die Geschwindigkeit des Schrittmotors regeln soll.
Joystick: Thrustmaster
wir bitten euch um eure Hilfe, da wir am verzweifeln sind!!!!
=(
mfg Wirecam
Lesezeichen