@ mPatterson557 - Not exactly secure but you could simply mark the member as a public static and init it outside of using the gadgeteer designer:
namespace StaticMember
{
public partial class Program
{
public static GTM.GHIElectronics.RS232 SerialObject;
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
/*******************************************************************************************
Modules added in the Program.gadgeteer designer view are used by typing
their name followed by a period, e.g. button. or camera.
Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
button.ButtonPressed +=<tab><tab>
If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
timer.Tick +=<tab><tab>
timer.Start();
*******************************************************************************************/
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
SerialObject = new GTM.GHIElectronics.RS232(1);
}
}
}
And then access will be as you expected it initially:
namespace StaticMember
{
class TestAccess
{
public void Init()
{
Program.SerialObject.serialPort
}
}
}
public class MyClass{
void Function(RS232 rs232){
rs232.BaudRate = 9600;
}
}
Or use it as a property off your main program.
public partial class Program
{
void ProgramStarted()
{
// Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
Debug.Print("Program Started");
}
public RS232 RSPort
{
get
{
return rs232;
}
set
{
rs232 = value;
}
}
}
public class MyClass
{
void Function()
{
Program.RSPort.BaudRate = 9600;
}
}
It allows you to set your own properties on the object declaration. The designer will use its own properties and will not accomplish what you want without a reference to either Program or the object itself.
It is, but the reference itself consumes memory, just not as much as the object itself. In most cases, there will be no need to optimize memory consumption to that extent. I only offered it as an option as I do not know the full extent of his project nor the hardware he is using.