serial port, threads, events
-
hi guys love this site so helpful. i have a c++/cli program im writing. im not going to post no code at this time cause i hope my problem can be solved with just a explanation. in my main form i run some code that controls a pic chip that runs some servo motors, communicating through the serial port. all runs fine. the problem im having is that well you know serial port is on another thread. so i use invoke and run a data received method on the ui. now that has a switch statement that may call some other functions in my ui thread that all works fine until one of the functions actually needs some input from the serialport. but i dont get any data in until the invoke completes. i tryed to run it with begininvoke which seems to work fine for the serialport but the ui doesnt update the form at all during the invoktion. so i thought i would just try to have the datareceived funtion fire an event on the ui. but then i get a crossthread error. maybe im not doing the event correctlly im still trying to get my head around delegates and events. question? does this seem reasonable? what i need to do is get that serialport freed up so that it can receive data again while the ui runs its code. Please bear with me im learning. and i have been reading post after post about threads, delegates, and events. ive problebly seen the answer and didnt know it. ill be happy to read im just not sure of the correct implementation. and im writing this in c++/cli cause i copied some code from an old borland c++ program. thanks in advance. yes i could post some code but ill have to clean it up first and pick out important parts right now its quite sizable.
-
hi guys love this site so helpful. i have a c++/cli program im writing. im not going to post no code at this time cause i hope my problem can be solved with just a explanation. in my main form i run some code that controls a pic chip that runs some servo motors, communicating through the serial port. all runs fine. the problem im having is that well you know serial port is on another thread. so i use invoke and run a data received method on the ui. now that has a switch statement that may call some other functions in my ui thread that all works fine until one of the functions actually needs some input from the serialport. but i dont get any data in until the invoke completes. i tryed to run it with begininvoke which seems to work fine for the serialport but the ui doesnt update the form at all during the invoktion. so i thought i would just try to have the datareceived funtion fire an event on the ui. but then i get a crossthread error. maybe im not doing the event correctlly im still trying to get my head around delegates and events. question? does this seem reasonable? what i need to do is get that serialport freed up so that it can receive data again while the ui runs its code. Please bear with me im learning. and i have been reading post after post about threads, delegates, and events. ive problebly seen the answer and didnt know it. ill be happy to read im just not sure of the correct implementation. and im writing this in c++/cli cause i copied some code from an old borland c++ program. thanks in advance. yes i could post some code but ill have to clean it up first and pick out important parts right now its quite sizable.
Unfortunately your manner to describe the problem, you need the assistance with, does not help to help you. Or, maybe your keyboard failed to work properly (so neither Shift, nor Caps Lock, nor Enter key does work?)
-
Unfortunately your manner to describe the problem, you need the assistance with, does not help to help you. Or, maybe your keyboard failed to work properly (so neither Shift, nor Caps Lock, nor Enter key does work?)
My apologies: Let me try this again. I'm wondering if there is a way to free my serial port thread after i invoke to my UI thread. Once i Invoke from the Data Received event on the Serial port Thread to a receive function on the UI thread, my switch statement in the receive function may call a function that sends data to the pic program. Now the pic responds immediately but the data doesn't appear cause the invoke method hasn't quite exited yet. any suggestions would be Appreciated.