As mentioned in the first part of this article, it is possible to send data from the EV3 to the PC application. In this part, I describe how I try to learn the syntax of Direct Command programming.
I used two documents that I found on the web:
Understanding the examples
In chapter 4 of the first document, some examples are shown how to use a Direct Command. For example, if you convert the example from chapter 4.2.3…
… into C# code like this and send these bytes to the EV3 over your open WiFi connection…
… the connection indicates that return bytes are available and if you read them, they contain the actual sensor value.
By trying to understand the examples and trying different values for the parameters, I tried to figure out how these Direct Commands work. The documentation however is (as said before) very brief. The text below is a small excerpt from the second document and is the generic description of the same sensor example:
Reading an existing mailbox
The Direct Command overview indicates that it should be possible to read to and write from a mailbox using the “opMailbox_Open”, “opMailbox_Read” and “opMailbox_Write” codes. Since writing is already possible with a System Command, my focus was now on creating a Direct Command to read from an existing mailbox. If I would get this working, then I could send a message from my EV3 application to the PC application.
But that was easier said than done. Instead of understanding the documentation from a working example, I had now to find out the correct bytes based on the documentation.
The Direct Commands that I need are “opMailbox_Open” and “opMailbox_Read”:
My idea was to open the “Outbox” mailbox which sends data messages from the EV3 to the outside world. Hopefully, the opMailbox_Read would then be able to read this data. Until now, I have not succeeded to get this working😦. What I really find disturbing, is the fact that there is no way (or at least: I don’t know it) to debug these Direct Commands. Either it works (“Yes!”) or, and that happens most of the time, it doesn’t. You don’t get a user friendly text message with “Sorry, that name doesn’t exist” or “Sorry, mailbox is not accessible by this user”. If you are lucky, the return value was indeed 0x04 (failure). Sometimes the return value was 0x02 (success) but I still don’t know what the success was… And since you’re poking around in memory space of the Brick, it happened more than once that the complete EV3 was dead and a reboot was needed. In case you don’t know: you can reboot by pressing the following three buttons simultaneously: MIDDLE+LEFT+ESC.
After too much time behind my laptop, I started to feel like Wile E Coyote from Road Runner: lots of effort but no catch.
I started to think about a workaround. Well, I found one and even better: I got it working! Yes!!!!
I will tell you more about this workaround in the next chapter!