I have a form with controls that bind to an object declared in
the form.
I have a communications class that is receiver driven. (to get
data I have to send a command).
How can I have the receiver thread manipulate the object my form
controls are bound to?
Eg.
namespace myApp
{
public partial class myMainForm : Form
{
public dataClass myData = new dataClass();
// Constructor
public myMainForm()
{
InitializeCompo nent();
this.myDataBind ingSource.DataS ource = this.myData;
}
// ...
private void Read_button_Cli ck(object sender,
EventArgs e)
{
comm.myDevice dev = comm.myDevice() ;
dev.Open();
if (dev.IsOpen)
{
byte[] packet;
... // Create packet
dev.Transaction (packet);
}
}
}
namespace comm
{
private class responseData
{
public bool IsValid { ... }
}
public class myDevice : SerialPort
{
public void Transaction(byt e[] packet)
{
try { base.Write(pack et, 0, packet.Length); }
catch (TimeoutExcepti on) { return; }
System.Threadin g.Thread rdThrd;
rdThrd = new System.Threadin g.Thread(Respon se);
rdThrd.Start();
}
public void Response()
{
repsonseData resposne = new responseData();
while (!response.IsVa lid)
{
byte[] data = new byte[512];
try { base.Read(data, 0,
Math.Min(this.B ytesToRead,512) ); }
catch (TimeoutExcepti on) { return; }
response.scan(d ata);
}
// *************** *************** **********
// bind something akin to this:
// *************** *************** **********
myApp.myMainFor m.myData.elemen t1 = response.elemen t1;
}
}
}
}
the form.
I have a communications class that is receiver driven. (to get
data I have to send a command).
How can I have the receiver thread manipulate the object my form
controls are bound to?
Eg.
namespace myApp
{
public partial class myMainForm : Form
{
public dataClass myData = new dataClass();
// Constructor
public myMainForm()
{
InitializeCompo nent();
this.myDataBind ingSource.DataS ource = this.myData;
}
// ...
private void Read_button_Cli ck(object sender,
EventArgs e)
{
comm.myDevice dev = comm.myDevice() ;
dev.Open();
if (dev.IsOpen)
{
byte[] packet;
... // Create packet
dev.Transaction (packet);
}
}
}
namespace comm
{
private class responseData
{
public bool IsValid { ... }
}
public class myDevice : SerialPort
{
public void Transaction(byt e[] packet)
{
try { base.Write(pack et, 0, packet.Length); }
catch (TimeoutExcepti on) { return; }
System.Threadin g.Thread rdThrd;
rdThrd = new System.Threadin g.Thread(Respon se);
rdThrd.Start();
}
public void Response()
{
repsonseData resposne = new responseData();
while (!response.IsVa lid)
{
byte[] data = new byte[512];
try { base.Read(data, 0,
Math.Min(this.B ytesToRead,512) ); }
catch (TimeoutExcepti on) { return; }
response.scan(d ata);
}
// *************** *************** **********
// bind something akin to this:
// *************** *************** **********
myApp.myMainFor m.myData.elemen t1 = response.elemen t1;
}
}
}
}
Comment