So Jetzt ist er endlich Fertig Alles 4 Achsen und die Button Position
Gruß Tjark
Code:
'
' Erstellt mit SharpDevelop.
' Benutzer: Tjark Möller •.•
' Datum: 03.03.2012
' Zeit: 20:32
'
' Sie können diese Vorlage unter Extras > Optionen > Codeerstellung > Standardheader ändern.
'
Imports System
Imports System.Windows.Forms
Imports Microsoft.DirectX.DirectInput
Imports Microsoft.DirectX
Public Partial Class MainForm
Public Sub New()
' The Me.InitializeComponent call is required for Windows Forms designer support.
Me.InitializeComponent()
serialport1.open
'
' TODO : Add constructor code after InitializeComponents
'
End Sub
Private applicationDevice As Device = Nothing
Public Shared state As New JoystickState()
Public Function InitDirectInput() As Boolean
dim instance As DeviceInstance
For Each instance In Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly)
applicationDevice = New Device(instance.InstanceGuid)
Exit For
Next instance
applicationDevice.SetDataFormat(DeviceDataFormat.Joystick)
applicationDevice.SetCooperativeLevel(Me, CooperativeLevelFlags.Exclusive Or CooperativeLevelFlags.Foreground)
Dim d As DeviceObjectInstance
For Each d In applicationDevice.Objects
If 0 <> (d.ObjectId And CInt(DeviceObjectTypeFlags.Axis)) Then
' Set the range for the axis.
applicationDevice.Properties.SetRange(ParameterHow.ById, d.ObjectId, New InputRange(+1000, +2000))
End If
Next d
Return True
End Function 'InitDirectInput
Public Sub GetData()
If Nothing Is applicationDevice Then
Return
End If
Try
applicationDevice.Poll()
Catch inputex As InputException
If TypeOf inputex Is NotAcquiredException Or TypeOf inputex Is InputLostException Then
Try
applicationDevice.Acquire()
Catch
Return
End Try
End If
End Try
Try
state = applicationDevice.CurrentJoystickState
Catch
Return
End Try
End Sub
Sub Button1Click(ByVal sender As Object, ByVal e As EventArgs)
InitDirectInput
End Sub
Sub Timer1Tick(ByVal sender As Object, ByVal e As EventArgs)
GetData()
label1.Text="X = "+state.X.ToString()
label2.Text="Y = "+state.Y.ToString()
label3.Text="Z = "+state.Z.ToString()
label4.Text="Rz = "+state.Rz.ToString()
Label5.Text ="Button1 = "+state.GetButtons(0).Tostring
if serialport1.IsOpen then
serialport1.Write ("X" + (state.X).tostring + Chr(13))
serialport1.Write ("Y" + (state.Y).tostring + Chr(13))
serialport1.Write ("Z" + (state.Z).tostring + Chr(13))
serialport1.Write ("Rz" + (state.Rz).tostring + Chr(13))
SerialPort1.Write(state.GetButtons(0) & chr(13))
end if
End Sub
Sub Label1Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
End Class
Lesezeichen