WPF, Serial Port, MutliThreading
-
Hi I am working on a project in which Computer interact with some Microcontroller Computer sends some commands in a particular protocol, and receive some data in turn There is a problem: we have lots of Microcontroller connected to a computer via serial port, because serial port is another thread, we send command from computer but we don't know when exactly we receive the response of MicroController as we have lots of MicroController connected to computer, we can not have lots of delay for each command sending so I used a Interrupt based (Event Oriented) code, but you suppose I send a command to a MicroControler , but don't wait for response and send another command to another MicroController, ... at the other hand , we are receiving some data, that they are the responses the problem is here: we can not distinguish which response belong to with MicroContoller is there a solution for this problem? is it a multiThreading problem?
-
Hi I am working on a project in which Computer interact with some Microcontroller Computer sends some commands in a particular protocol, and receive some data in turn There is a problem: we have lots of Microcontroller connected to a computer via serial port, because serial port is another thread, we send command from computer but we don't know when exactly we receive the response of MicroController as we have lots of MicroController connected to computer, we can not have lots of delay for each command sending so I used a Interrupt based (Event Oriented) code, but you suppose I send a command to a MicroControler , but don't wait for response and send another command to another MicroController, ... at the other hand , we are receiving some data, that they are the responses the problem is here: we can not distinguish which response belong to with MicroContoller is there a solution for this problem? is it a multiThreading problem?
its not clear from what you've said what the relationshop between serial port and microcontroller is - without that, questions like 'is there a solution for this problem' && 'is it a multihreading problem' are real hard to answer - and to throw multithreading into the mix may make you're life harder !! So, if one serial port has multiple microcontrollers attached to it, Im guessing there must be a way of adressing each microcontroller on the serial port. As you say,
cppwxwidgetsss wrote:
we can not distinguish which response belong to with MicroContoller
which I find hard to visualise, so the only way I see of handling this is to have 1 to 1 relationship between serial-ports and microcontrollers, unless the response from a microcontroller can be improved to say which one its coming from .. It must be a fairly common issue, so Im wondering if there's a serial I/O board you can use between the serial interface of the pc and the microcontrollers, that you'll know which microcontroller to address and get a unique response back from it sorry I cant help more 'g'
-
its not clear from what you've said what the relationshop between serial port and microcontroller is - without that, questions like 'is there a solution for this problem' && 'is it a multihreading problem' are real hard to answer - and to throw multithreading into the mix may make you're life harder !! So, if one serial port has multiple microcontrollers attached to it, Im guessing there must be a way of adressing each microcontroller on the serial port. As you say,
cppwxwidgetsss wrote:
we can not distinguish which response belong to with MicroContoller
which I find hard to visualise, so the only way I see of handling this is to have 1 to 1 relationship between serial-ports and microcontrollers, unless the response from a microcontroller can be improved to say which one its coming from .. It must be a fairly common issue, so Im wondering if there's a serial I/O board you can use between the serial interface of the pc and the microcontrollers, that you'll know which microcontroller to address and get a unique response back from it sorry I cant help more 'g'
actually we have a bus-like serial port which means that we use the serial port in share with lots of microController and as the protocol is implemented before, we have not any mean to find out which device is sending a message (it is not expected before in protocol) so that I think this is a multithreading problem if someone have useful info help me please
-
actually we have a bus-like serial port which means that we use the serial port in share with lots of microController and as the protocol is implemented before, we have not any mean to find out which device is sending a message (it is not expected before in protocol) so that I think this is a multithreading problem if someone have useful info help me please
Hi, I think I understand your problem I take it you are using interrupts with your serial comms as in my article:Serial Communication using WPF, RS232 and PIC Communication[^] . I'm an electrical engineer so I do a lot of work with micro-controllers and programming on UI levels. From my understanding at the moment the you can not determine which micro-controller has sent the data of which the interrupt loads and displays. There are a few solutions to you problem which depend on your ability to reprogram the micro-controllers. 1st I will assume this is not an option: If you can ensure that the micro-controllers respond one after each other the you could try the older approach of creating another thread and reading all the data into a buffer this more common in C# applications. I can provide an example of this if required however it's not used that often any more. This will attempt to read the data in a let you deal with it a bit at a time however is less efficient than interrupts and your likely to to loose data. The best option to ensure data integrity is simply to wait after polling each micro-controller until data is received however I understand this may not be possible if at time the micro-controller does not respond with data. If this is true you will have to introduce a timer to continue after if no data is received. 2nd If you can reprogram the micro-controllers: This is far easier, 1st simply ensure each micro-controller sends and ID tag before sending any data this way you can determine the start of each package and the device. An alternative which is the bus standard norm is a busy line. It requires an extra connection between your micro-controllers when a controller receives a request for data it will set this line high. Before any other micro-controller can send it's data it must wait for this line to go low. This method again relies on data always being sent on request and has inherent problems such as if one micro-controller takes a considerable time to transmit for example it has a long string of data to send you could find yourself polling for data from micro-controllers before they have had time to send there previous data. This timing issues are important to deal with and I would recommend the first option for ease as you could still end up