lihua20
Posts: 4
Joined: Thu Nov 15, 2007 12:48 am
Location: USA

Need to change parent of serial port when the port

Thu Nov 15, 2007 12:54 am

We have used SerialTools .NET v1.2 with C# to develop our pocket PC application. In the application, we have multiple screens (forms) using serial port for blue tooth connection. And we do use OnRead and OnForceClose events for each screen. Since we can't change parent of the enabled serial port, we have to enable and disable serial port when we switch screens. For Windows Mobile Version 5, it just takes some time to switch. That's not too bad. But for Windows Mobile Version 4 (HP), if there are multiple blue tooth devices in the radio range, enabling port pops up a screen to select the device every time. That screen is the window system screen. It's very annoying, makes the application useless.

How can we switch screens without disabling and re-enabling the serial port? Does the new version of SerialTools support this?

Thank you very much.

lihua20
Posts: 4
Joined: Thu Nov 15, 2007 12:48 am
Location: USA

RE: Need to change parent of serial port when the port

Thu Nov 15, 2007 1:08 am

I probably know how to do it now.

lihua20
Posts: 4
Joined: Thu Nov 15, 2007 12:48 am
Location: USA

RE: Need to change parent of serial port when the port

Thu Nov 15, 2007 1:46 am

No, it didn't work. That's what I tried. I didn't set parent screen before enabling the port, just attached and dettached OnRead events without disabling the port when switching screens. I got exception: Control.Invoke must be used to interact with controls created on a separated thread.

User avatar
johan
GpsGate
Posts: 14389
Joined: Wed Aug 04, 2004 10:40 pm
Location: Sweden
Contact: Website

RE: Need to change parent of serial port when the port

Thu Nov 15, 2007 12:08 pm

Set Port.Parent to null. Then handle events to different forms using Control.Invoke.

Regards,
Johan

Franson Support

lihua20
Posts: 4
Joined: Thu Nov 15, 2007 12:48 am
Location: USA

RE: Need to change parent of serial port when the port

Thu Nov 15, 2007 7:48 pm

Johan,
Thank you.
I'm new to C#. Could you give me a little more detail how and where to add Control.Invoke?
In my Form, I have (SerialNET.Port port = new SerialNET.Port()) and (SerialNET.OnRead on_read = = new SerialNET.OnRead(port_OnRead)). void port_OnRead(string) is the real working function in my Form. Should I call Invoke from my Form? And what is the argument of the Invoke?


Originally posted by johan

Set Port.Parent to null. Then handle events to different forms using Control.Invoke.

Regards,
Johan

Franson Support

Return to “SerialTools”