In your serial port receive event, Test class, add an event:
private void Test\_DataReceived(object sender, EventArgs e)
{
// do RxText here...
OnEventRxCompleted(RxText);
}
public delegate void TestEventHandler(string Text);
public event TestEventHandler EventRxCompleted;
protected void OnEventRxCompleted(string RxText)
{
if (EventRxCompleted != null)
{
EventRxCompleted(RxText); // Fire event now
}
}
in Parent from: add this in constructor,
Test.EventRxCompleted+= new Test.TestEventHandler(EventDataReceived);
and also,
void EventDataReceived(string Text)
{
SetText(Text);
}
delegate void SetTextCallback(string text);
private void SetText(string text)
{
if (txtParent.InvokeRequired) // txtParent is TextBox in parent form
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object\[\] { text });
}
else
{
txtParent.Text = text;
}
}
Kelvin
modified on Friday, March 20, 2009 5:14 AM