Hier mein VB code (ich weiß gehört hier nicht rein aber ich wollte keinen Anderen Tread eröffnen.
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(+1, +255))
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()
'Axis----------------------------------------------------
label1.Text="X = "+state.X.ToString()
label2.Text="Y = "+state.Y.ToString()
label3.Text="Z = "+state.Z.ToString()
label4.Text="Rz = "+state.Rz.ToString()
'Buttons--------------------------------------------------
Label5.Text ="Button1 = "+state.GetButtons(0).Tostring
Label6.Text ="Button2 = "+state.GetButtons(1).Tostring
Label7.Text ="Button3 = "+state.GetButtons(2).Tostring
Label8.Text ="Button4 = "+state.GetButtons(3).Tostring
Label9.Text ="Button5 = "+state.GetButtons(4).Tostring
Label10.Text ="Button6 = "+state.GetButtons(5).Tostring
Label11.Text ="Button7 = "+state.GetButtons(6).Tostring
Label12.Text ="Button8 = "+state.GetButtons(7).Tostring
Label13.Text ="Button9 = "+state.GetButtons(8).Tostring
Label14.Text ="Button10 = "+state.GetButtons(9).Tostring
Label15.Text ="Button11 = "+state.GetButtons(10).Tostring
Label16.Text ="Button12 = "+state.GetButtons(11).Tostring
'Serialport Write-----------------------------------------
If serialport1.IsOpen Then
'Axis-----------------------------------------------------
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))
'Buttons--------------------------------------------------
SerialPort1.Write ("B1" + (state.GetButtons(0)).ToString & Chr(13))
SerialPort1.Write ("B2" + (state.GetButtons(1)).ToString + Chr(13))
SerialPort1.Write ("B3" + (state.GetButtons(2)).ToString + Chr(13))
SerialPort1.Write ("B4" + (state.GetButtons(3)).ToString + Chr(13))
SerialPort1.Write ("B5" + (state.GetButtons(4)).ToString + Chr(13))
SerialPort1.Write ("B6" + (state.GetButtons(5)).ToString + Chr(13))
SerialPort1.Write ("B7" + (state.GetButtons(6)).ToString + Chr(13))
SerialPort1.Write ("B8" + (state.GetButtons(7)).ToString + Chr(13))
SerialPort1.Write ("B9" + (state.GetButtons(8)).ToString + Chr(13))
SerialPort1.Write ("B10" + (state.GetButtons(9)).ToString + Chr(13))
SerialPort1.Write ("B11" + (state.GetButtons(10)).ToString + Chr(13))
SerialPort1.Write ("B12" + (state.GetButtons(11)).ToString + Chr(13))
end if
End Sub
Sub Label1Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Sub MainFormLoad(ByVal sender As Object, ByVal e As EventArgs)
End Sub
End Class
Gruß Tjark
Lesezeichen