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:
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).
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.
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.
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:
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! 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.
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.
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.
Use the above example
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.
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.
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.
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.