??? 03/22/07 13:58 Modified: 03/22/07 14:01 Read: times |
#135585 - This may help Responding to: ???'s previous message |
I'm no Windows expert, but I did manage to do this very thing a couple of months ago.
I'm pretty sure that DataReceived is indeed the function you are looking for. As I understand it, DataReceived is called by the system whenever there is some unspecified amount of data available from the serial port. Within DataReceived, my program uses ReadByte to grab the characters one at a time and pass them off to a separate function for processing. Here's how I did it: (Note that this is C++.) private: System::Void MTCCommPort_DataReceived ( System::Object^ sender, System::IO::Ports::SerialDataReceivedEventArgs^ e ) { while (this->MTCCommPort->BytesToRead) { HandleNewByte(this->MTCCommPort->ReadByte()); } }The next problem that you're going to have is that DataReceived runs in a different thread than the one that created the controls on your forms. When you try to manipulate one of your controls from within DataReceived, the .NET runtime is going to freak out because it won't like the idea of two different threads messing with a single control. You can find a detailed explanation of this problem and its solution in an MSDN article titled "How to: Make Thread-Safe Calls to Windows Form Controls". Here's a link: http://msdn2.microsoft.com/en-us/lib...S.80).aspx -- Russ |
Topic | Author | Date |
serial ports and visual c#? | 01/01/70 00:00 | |
update | 01/01/70 00:00 | |
I once did something like that ... | 01/01/70 00:00 | |
VB2005 and the Serial Port | 01/01/70 00:00 | |
This may help | 01/01/70 00:00 | |
Thanks guys | 01/01/70 00:00 |