Hi There!
Paul, I'm a newbie in C# but very experienced with FSUIPC, making macros, association with a lot of joysticks and so on. But now, I'm trying to make to export the landing gear led from C# to serial.port Arduino and make these leds (all leds : moving and when gear is extend as well total of 6 leds) lit.
I attempted by using your code by turning a led on if avionicsMaster button is checked.
See code below:
namespace FSUIPCWinFormsApp8
{
public partial class frmMain : Form
{
// =====================================
// DECLARE OFFSETS YOU WANT TO USE HERE
// =====================================
private Offset<uint> airspeed = new Offset<uint>(0x02BC);
private Offset<uint> avionicsMaster = new Offset<uint>(0x2E80);
public frmMain()
{
InitializeComponent();
serialPort1.PortName = "COM4"; // inserted by me
serialPort1.BaudRate = 9600; // inserted me
configureForm();
}
// The connect/disconnect buton
private void btnToggleConnection_Click(object sender, EventArgs e)
{
if (FSUIPCConnection.IsOpen)
{
// Connection is currently open
// Stop the main timer
this.timerMain.Stop();
// Close the connection
FSUIPCConnection.Close();
}
else
{
// Try to open the connection
try
{
this.lblConnectionStatus.Text = "Looking for a flight simulator...";
this.lblConnectionStatus.ForeColor = Color.Goldenrod;
FSUIPCConnection.Open();
// If there was no problem, start the main timer
this.timerMain.Start();
}
catch (Exception ex)
{
// An error occured. Tell the user.
MessageBox.Show("Connection Failed\n\n" + ex.Message, "FSUIPC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
configureForm();
}
// This method runs 20 times per second (every 50ms). This is set on the timerMain properties.
private void timerMain_Tick(object sender, EventArgs e)
{
// Call process() to read/write data to/from FSUIPC
// We do this in a Try/Catch block incase something goes wrong
try
{
FSUIPCConnection.Process();
// Update the information on the form
// (See the Examples Application for more information on using Offsets).
// 1. Airspeed
double airspeedKnots = (double)this.airspeed.Value / 128d;
this.txtAirspeed.Text = airspeedKnots.ToString("F0");
// 2. Master Avionics
this.chkAvionicsMaster.Checked = avionicsMaster.Value > 0;
}
catch (Exception ex)
{
// An error occured. Tell the user and stop this timer.
this.timerMain.Stop();
MessageBox.Show("Communication with FSUIPC Failed\n\n" + ex.Message, "FSUIPC", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// Update the connection status
configureForm();
}
}
// This runs when the master avionics tick has been changed
private void chkAvionicsMaster_CheckedChanged(object sender, EventArgs e)
{
// Update the FSUIPC offset with the new value (1 = Checked/On, 0 = Unchecked/Off)
this.avionicsMaster.Value = (uint)(this.chkAvionicsMaster.Checked ? 1 : 0);
// MessageBox.Show("this.avionicsMaster.Value");
// HERE'S THE ISSUE: I just want to send to Arduino and make a led on (if Aviation Master is checked and off if opposite).
Then, The main purpose: install 6 led and make them operate as land gear status.
Could you please, give me a help here??
// serialPort1.Open();
if (serialPort1.IsOpen)
{
serialPort1.WriteLine("1");
}
}