using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.DirectInput;
using System.IO.Ports;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Codigo para iniciar el Joystick
private Device joystick;
private void carga_panzer(object sender, EventArgs e)
{
this.InitDevices();
}
// Iniciando el Joystick
private void InitDevices()
{
//Cargando todos los joysticks posibles
foreach (
DeviceInstance di in
Manager.GetDevices(
DeviceClass.GameControl,
EnumDevicesFlags.AttachedOnly))
{
joystick = new Device(di.InstanceGuid);
break;
}
if (joystick == null)
{
//Si no encontramos ningún Joystrick
throw new Exception("No joystick found.");
}
////Configurando los dispositivos
//Configurando los ejes del Joystick
foreach (DeviceObjectInstance doi in joystick.Objects)
{
if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
{
joystick.Properties.SetRange(
ParameterHow.ById,
doi.ObjectId,
new InputRange(-100, 100));
}
}
joystick.Properties.AxisModeAbsolute = true;
//Nivel cooperativo
joystick.SetCooperativeLevel(
this,
CooperativeLevelFlags.NonExclusive |
CooperativeLevelFlags.Background);
//Adquiriendo datos del joystick
joystick.Acquire();
}
private void UpdateJoystick()
{
string coordenada_x = "Eje: ";
string coordenada_y = "Eje: ";
string coordenada_z = "Eje: ";
string info = "Joystick: ";
//Estado del joystick
JoystickState state = joystick.CurrentJoystickState;
//Posición
coordenada_x += "X:" + state.X + " ";
coordenada_y += "Y:" + state.Y + " ";
coordenada_z += "Z:" + state.Z + " ";
//Botones
byte[] buttons = state.GetButtons();
for (int i = 0; i < buttons.Length; i++)
{
if (buttons != 0)
{
info += "Boton:" + i + " ";
}
}
label1.Text = info;
label2.Text = coordenada_x;
label3.Text = coordenada_y;
label4.Text = coordenada_z;
}
private void timer1_Tick(object sender, EventArgs e)
{
UpdateJoystick();
}
}
}
Este es todo el código, y lo que realmente quiero es que las coordenadas x,y me las envie al pic por el puerto com.
Las coordenadas son state.X, state.Y,state.Z, como puedo hacer eso?