Scenario 1: I’ve connected a WiFly card to the Robot Kit. When I click Start Debugging in VS2010, everything works fine. The card is on the network and I can communicate with the robot wirelessly. I then disconnect the USB cable and device continues to work fine on its own power (e.g. the batteries in the robot kit).
Scenario 2: However, if I simply switch off the device and switch it back on, it seems like the Robot is not communicating with the WiFly card. I know that the WiFly card itself is on the network because I can see data coming into it (I’ve connected LEDs to various sensors on the car).
Scenario 3: If I then reconnect the USB cable to the Robot Kit and click Start Debugging again, the first thing that happens is that the application receives a dump of data from the WiFly card that it got while in Scenario 2.
What is different between debug mode and non-debug mode? Does something happen there that I should watch out for?
I’ve added a bunch of debug statements all over the place, connected to the device via MFDeploy and now I am more confused than ever. In fact, I stripped out most of the code just to leave the essentials and included the project with the post. http://www.angryhacker.com/toys/reproproblem.zip
I have 2 comports. COM1 is my terminal port (through which I can send commands) and COM2 is connected to a WiFly card. And I have a generic class which wraps SerialPort class. Everything works great when I am in debug mode. However, when I start up the device on its own, the following occurs:
I send a command to COM1 of the device from the PC. The DataReceived event of the associated SerialPort does NOT fire. Instead I get a dump of data from COM2 (when WiFly card is powered up, it spits out a bit of data), that WiFly card has been apparently buffering. Note that it’s not all of the data dump, just a part of it. After that no more data arrives, either on COM1 or COM2.
It’s like something is jiggered by data being received on COM1.
If I go to MFDeploy and select Plugin/Debug/Reboot CLR, after rebooting everything works fine.
_port = new SerialPort("COM2", 19200, Parity.None, 8, StopBits.One);
_port.ReadTimeout = 0;
_port.ErrorReceived += new SerialErrorReceivedEventHandler(_port_ErrorReceived);
_port.Open();// If you open the port after you set the event you will endup with problems
_port.DataReceived += new SerialDataReceivedEventHandler(_port_DataReceived);