![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
reading from comm port and displaing in editbox using MFcHi all,
I want to read from the comm port. Data can be integer, characters or hexa and which are sent randomly. I want to read this data and display in the editbox. I am able to read the file but not able to display all the data. I can able to display any one of these data. i.e I can display integers than not able to display others. I am using. CPP / C++ / C Code:
Also when the application is reading from the comm port and displaying, at that period I am not able to click any other buttons. Can any one help me out. Last edited by LuciWiz : 01-Feb-2005 at 06:16.
Reason: Please insert your C code between [c] & [/c] tags
|
|
#2
|
||||
|
||||
|
Quote:
How do you store your data? Do you use some kind of general container or is there a way by which you can sort your data? Quote:
That is because you need to use a different thread for reading from the com port. That way your application won't hang until the reading is over. Regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#3
|
|||
|
|||
|
Quote:
Dear Luci I am reading one byte each time and putting in buffer. after that displaying in editbox. by using the code which is in my earlier thread. can u tell me how to use different thread for reading from the com port. |
|
#4
|
|||
|
|||
|
Quote:
Use a different thread to wait for a serial event and read. Your main thread can process other tasks. You can have something like: CPP / C++ / C Code:
Make sure if None Overlapping mode is enough for your program otherwise you have to use Overlapping mode. refer to the link below for more information. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnfiles/html/msdn_serial.asp |
|
#5
|
|||
|
|||
|
as for your first question, are you trying to display whatever you got?Then Rich Edit control might be good for this
Then try the following code: CPP / C++ / C Code:
|
|
#6
|
|||
|
|||
|
Quote:
Hi, is there any other way without using multithreading. If not, can u explain more how to use it. |
|
#7
|
||||
|
||||
|
CPP / C++ / C Code:
sorry no time to explain this, its queite straight forward, but i'll explain later or let othr help m explain this.. gtg. __________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
|
#8
|
|||
|
|||
|
Quote:
Depend what project are you on. Basically writting something to a port is easier than reading. If you know when there is data coming in through a COM port and how many bytes they are, one thread is probably ok for you as you could only call your read function at that particular time. But if these are uncertain, then you probably need to call WaitComEvent function which will block your program until there is a Com Event happening (e.g. data arrives or flow control happens) That's why your program appears to be "hung up". In that case you need another thread only for waiting and reading while your main thread is performing other tasks. Another case, if you still want to do some data transfer while your port is on waiting mode, your communication is required to be working in overlapping mode. Or,lets say if your write process is suspending by flow control (CTS line ) you won't be able to access to that port until the write function returns.this also requires overlapping communication. I suggest you looking at the link I gave and see which scenario applies to your project and decide which way to take. let me know your decision and then we can have a further discussion |
|
#9
|
||||
|
||||
|
Quote:
I think Max meant: CPP / C++ / C Code:
Either that, or I didn't completely follow his logic. I agree his example is very good, and if you can't follow it, maybe you should post some of your code (with the reading), and we'll try to integrate that in the whole multithreading thing. And no, I don't see any other way to solve your problem - threads are the solution. As for the displaying of your data, mingcosp's suggestion is very good - I'm just not sure about what your question was. Do you want just to be able to display it "as is", or would you like an "intelligent" display, with data interpretation. 'Cause I don't think you can achieve this without knowing what you are getting from the port. Best regards, Lucian __________________
Please read these Guidelines before posting on the forum "A person who never made a mistake never tried anything new." Einstein |
|
#10
|
||||
|
||||
|
thanks Lucian, for correcting my mistake...
CPP / C++ / C Code:
Quote:
this a very good explanation, just wanna add that u cannot avoid using multi thread here cause reading from com port sure will take some time and and if you don't have a thread to read from the port, your program would certainly hang untill it finishes reading form the port. I'm not sure about the serial thingy mingcosp posted, i'll rather make an infinite thread to read and wait for com event. but mingcosp suggestion might be better way to do it, and look into it.. CPP / C++ / C Code:
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds |
Recent GIDBlog
Developing GUIs with wxPython (Part 4) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The