0

I've got a clarification question regarding the receiving of data from across a serial port from an Arduino. Specifically, I'm using a Sparkfun Pro Micro 5v/16MHz and trying to write a simple GUI in C++ to send messages over the serial port and then receive one of a few responses that are specified in the code running on the Arduino board.

I know the communication and code running on the Arduino works because I have tried using the Serial Monitoring tool in the Arduino IDE and am able to send and receive the appropriate responses.

When sending messages through the C++ GUI I've created I see the traffic LED blinking on message send leading me to believe that send via C++ GUI is working, but nothing regarding receiving messages works.

Some of my code:

private: System::Void serialPort1_DataReceived(System::Object^  sender, System::IO::Ports::SerialDataReceivedEventArgs^  e)
        {
            String^ testStr = serialPort1->ReadExisting();
            log_textBox->Text += testStr + "\n";
        }

It's a very simple event handler that is assigned to the DataReceived event of my SerialPort object that is part of my form. I've set a breakpoint inside of it, and it never gets triggered. I'm kind of at a loss, I've done a nonexistent amount of work with Arduino or hardware so I'm not entirely sure what my options are for debugging.

If anyone has any debugging suggestions or ideas what I'm doing wrong I would very much appreciate it. Additionally, if I haven't provided any information let me know what is needed and I'll edit it in!

Thank You, -K

4

1 回答 1

0

在找到一条关于设置的晦涩评论后终于想通了。

事实证明,我需要将串行端口的 DTREnabled 属性设置为 True 而不是 false,以便触发 DataReceived 处理程序。此设置从未在任何有关串行端口通信的 MSDN 文档中设置。如果您正在阅读本文并遇到类似问题,请确保 DTREnabled、RTSEnabled 都设置为 true,甚至可能将 Handshaking 设置为 RequestToSend。也许其中一项或全部将最终解决它。

就我而言,只有 DTREnabled 需要为真。我不太明白这些设置的作用,但你有它。

于 2013-10-31T23:46:58.257 回答