Author Topic: Accessing a serial port from more one form?  (Read 4205 times)

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Accessing a serial port from more one form?
« on: October 26, 2011, 05:31:11 am »
Hi all,
I am writing an app to emmulate a PSION, and have neatly created a front end in C# that relies on multiple forms I now need to send some commands via a serial port when I try I get       
 
"Cross-thread operation not valid: Control 'richTextBox1' accessed from a thread other than the thread it was created on."

I take that to mean I can't open the port on Form1 and talk to via Form2, is the correct method then to create the command string pass it back to Form1 and then pass the data to Form2 as a string?

Thanks
Glenn

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 2848
    • Lakeview Research
Re: Accessing a serial port from more one form?
« Reply #1 on: October 26, 2011, 11:03:05 am »
Use a delegate. See my Com Port Terminal example or do a web search on the error message.

http://www.lvr.com/serport.htm#my_example_code

Jan

GlennP

  • Frequent Contributor
  • ****
  • Posts: 141
Re: Accessing a serial port from more one form?
« Reply #2 on: October 27, 2011, 04:30:59 am »
Thanks Jan, panic then remembered how I got over this problem last time, run the exe and not the debug! I will when I have chance look at the delegate method as that is probably the correct method!

Glenn