I apologize if my title-problem text is not correct... My problem: The first class posted under works fine and I can send data to a control processor through Crestron.ActiveCNX. The line shown containing "Hello world" sends data to the control processor, and here it works fine. In this same class I start this ActiveCNX communication and there is also event handling(Not shown here). But I have a lot of code and need to send data trough this same ActiveCNX connection from another class. This class is shown with the necessary code to explain my problem. When I try to send data from this second class i get the Nullreference exception code -1 error.
What am I doing wrong?
Sorry if this is a stupid question. I am an all around programmer, this time I needed to use the C# language.
Thanks for any help! Erik.
using Crestron.ActiveCNX;
namespace Server
{
public partial class Form1 : Form
{
public ActiveCNX cnx;
public Form1()
{
InitializeComponent();
}
public void Form1_Load(object sender, EventArgs e)
{
//Initialize ActiveCNX
cnx = new ActiveCNX();
cnx.Connect("10.0.0.32", 3);
MethodInvoker simpleDelegate = new MethodInvoker(AsynchronousSocketListener.StartListening);
simpleDelegate.BeginInvoke(null, null);
} //Form1_Load
private void button2_Click(object sender, EventArgs e)
{
cnx.SendSerial(1, 1, "Hello World!"); //This works fine from this location.(sending text to a control processor).
}
} //Class : Form1
} //Namespace
//////////////////////////////////////////////////////////////////////////////////////////////
namespace Server
{
class SendCNXUpdate
{
public void Update()
{
Form1 form1 = new Form1();
//Here it usually is code to receive data from another server, parsing it and then this class is supposed to send the parsed data to the processor.
form1.cnx.SendSerial(1, 1, "Hello World!"); //I am using the exact same code as in the form1 class, but get the nullexception error..
}
}
}