Listening to the debug stream on external program

Hi! I’m trying to create a program that listens for “events” to be fired off by the robot.
For the robot (and sake of proof of concept), I am simply working with this code:

#pragma config(Sensor, dgtl1,  s1,             sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   int count = 0;
   while (true) {
      untilBump(dgtl1);
      char arr[7] = "Bump  ";
      arr[6] = (char) ('a' + (count++ % 26));
      writeDebugStreamLine(arr);
   }
}

This works as expected:
http://puu.sh/ga4Od/a34892823c.png

However, is there any way to listen to that window? Is the log saved somewhere?
Edit: In addition, Spy++ shows that the window is not an edit control so I cannot use WM_GETTEXT.

Edit 2: To clarify my objective, I want to do something (for example, perform a web request) when a new line gets printed in the debug stream. The solution I am looking for does not pertain to RobotC directly, I’m asking for a way to access this stream (be it dll injection, a SendMessage event, or a text file).

This is what my C4 protocol tries to do in a fairly overkill way. Unfortunately C4 isn’t stable enough for me to vet yet. So I’ll suggest another way.

Listen to the TTY outside of ROBOTC, using an external program.

Its not so easy (I’m writing a port of C4 for Windows in my spare time).

This is what I’ve been reading:

https://msdn.microsoft.com/en-us/library/ms810467.aspx

Good luck,
-Cody

If you download a virtual terminal like putty and open a serial connection to the port that the cortex is connected to. After verifying this, you might be able to write a shell script that monitors this for a specific line and does some action based on that.

You say this like you’ve done it before, can you provide some insight?
I am able to connect to the port (COM4 in my case), however, due to obvious reasons, I cannot connect when the program is running.
Have you already done a solution for sniffing or man-in-the-middle? Or is there a way that I’m not seeing to run a program without ROBOTC being connected to COM4?

The debugstream from ROBOTC cannot be used with a conventional terminal, it has to be requested using the “ROBOTC” protocol. You can bypass the debugstream and write to the serial port used by ROBOTC but then normal debugging functions will not work.

Sorry but I’m not following, is there some magical way to run a program on the robot without running it with RobotC “Download to Robot” function?
Thanks in advanced.

Yes - there are two semi-independent concepts going on. But you still have to download the program to the Cortex.

  1. While Robot C is going, the communication from the Joystick or Cortex to the PC uses Robot C specific messaging versus characters streaming across. Probably some compression techniques to get more data to the PC in less time.

  2. Don’t use the Robot C write debug stream line and write messages yourself out the serial port to your PC. This can be run any time the program runs and not while robot C is hooked up.

jpearman explanation here with a link to the code he wrote:
https://vexforum.com/t/communicating-between-two-cortex-dual-cortex-robot/24236/1

If you want to go further with option 2, you can hook that serial connection to an Arduino that is storing the serial data to an SD card or you could use an XBee to communicate back to the PC. Several other choices are available here but involve make your own as well.

Or be semi-lazy like me and write to the debug stream lines and copy/paste into Excel or Open Office to make pretty graphs. This leads to re-downloading programs to the Cortex every time you set a variable to a new value (like the proportional constant in a PID tuning exercise to find the magic Ku value)

Well I want this to happen realtime as events so I can’t cheat like that! :frowning: And I don’t want to resort to OCR (and grabbing an image of the debug stream)…

Either way, I still have some questions. Once a program is “downloaded” to the robot, is it always running if it’s on? Or do I have to fake a RobotC start/terminate command?
Essentially if I simply modify the program write to the serial connection if open, instead of the robotc debug stream, download it, and stop the RobotC debugger, can I just connect, with, say, putty to COM# and see my output magically streaming (raw)?
I would be testing this but I don’t have access to the hardware at the moment, at college and won’t be home for a few hours.

BUMP, Sorry I need this for a project due soon.

I don’t know about the start commands or whether it is always running, I would try it while assuming that it is running and if that doesn’t work try emulating the start command. When I have done this before, I have always been using PROS or ConVex.
I might be able to test this with robotC in an hour or so.

The program will always run.

See this
Send Debug data to Hyper Terminal

What you want to do is harder in ROBOTC that PROS or ConVEX. This is simply because there is a proprietary protocol between the ROBOTC IDE and the ROBOTC virtual machine on which your code is running. 99% of the time we use the debugStream, if you want to send data into a standard terminal or to some type of special program you have two choices.

  1. Use the above example
  2. Use one of the two UARTs on the cortex with a 3.3V logic level to USB serial adapter (or equivalent).

If you are trying to do this wirelessly, then at least one character needs to be sent from the PC to change the wifi mode to “download” mode, keep the effective data rate to about 3000 char/sec or lower otherwise data will probably be lost.

What else does “download” mode do?

Read this
VexNET 2.0 data rate study

Old black keys work a little differently but data from cortex to joystick is disabled when in WiFi mode with both types, send a character from PC to enable.

Thanks a lot! I’ll look into this.
Does this have the same effect, in, say, putty?

It should work the same way, any program that can open the serial port and receive data will work. I should add that (IIRC) you cannot send data from the PC to the cortex in this way with ROBOTC, you can with PROS and ConVEX.

Odd, I can’t seem to read the data anywhere, and the debug stream is still connectable – am I missing something?

#pragma config(Sensor, dgtl1,  s1,             sensorTouch)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

void sendCmd();

task main()
{
	while (true) {
		untilBump(dgtl1);
		sendCmd();
	}
}

void sendCmd()
{
	char msg] = "We got bumped.\r\n";
	char *ptr = &msg;
	for (int i = 0; i < strlen(msg); ++i)
	{
		sendChar(UART0, *ptr++);
		while (!bXmitComplete(UART0)) { }
	}
}

Let me see if that old code still works, it was posted a while ago and something may have changed. Which version of ROBOTC do you have?

Edit:
Just tried your code with ROBOTC V4.30 and it works for me. You may need to power cycle after downloading and, as I said before, if you are using VEXnet then you need to send at least one character from the PC before the cortex will send anything back.

How do I send a character with tera term? I cannot seem to type in it.

Haven’t used terra term in a few years, once the connection is open (select the correct serial port etc.) I think you just type.