Hi!
I'm currently working on a project that requires me to be able to send data and control a remote Arduino Yun system using a C# programme.
I've read some lines saying that configuring Bridge/Console is the right way to go but I'm not particularly sure what specific steps I need to take.
Is there an additional library I need to download?
How exactly do I go from controlling the Yun through the console (serial monitor) to doing the same thing in a C# environment?
How do I set up my programme to link it together with the Yun?
Any help is appreciated.
Many thanks!
There are several ways to talk to the Yun, your first step is to decide how you want to do it. Some variations that immediately come to mind are
- Via the USB cable, talking to the sketch through the Serial class
- Via the network, making a TCP connection to the sketch using the Console class
- Via the network, making a TCP connection to the sketch using YunServer/YunClient.
- Via the network, making a TCP connection to the Linux side
- Via the network, making REST API calls to the sketch
- Via the network, making REST API calls to the Linux side
- Via the network, making more complicated web requests to the Linux side (forms, cgi, etc.)
Option 1 uses the serial port in C#, but you must set some handshaking lines to get the Yun to listen (I'm away from my computer so I can't give more detail at the moment.) I have done this, and while using the serial port in C# is not tricky on the surface, it gets more complicated if you want it to be reliable and asynchronous.
Options 2, 3, and 4 use basically the same C# code, the difference is the port number you use, and how you program the Yun. I've also done this, and while the networking code is a bit more difficult than serial, it's usually worth it to get rid of the USB cable tether.
Options 5 and 6 use the same C# code, again the difference is in the Yun. I've not done a lot of this.
On the Yun side, handling things in the sketch is simpler, but handling it on the Linux side is much more powerful and capable. Unless it's a trivial application, it's often worth the effort of learning how to do it with Linux.
ShapeShifter:
- Via the network, making a TCP connection to the sketch using the Console class
- Via the network, making a TCP connection to the sketch using YunServer/YunClient.
Thanks for the quick reply. I'm really embarrassed that a beginner like me can't figure this out on my own. I'm assuming the YunServer/YunClient is controlling the Yun by uploading certain webpages, right? And passing information that way? I'll try to search up how to make a TCP connection using the Console class. I think that's the route I want to take. 
chuehsamuel:
I'm assuming the YunServer/YunClient is controlling the Yun by uploading certain webpages, right?
Not really. YunServer and YunClient together implement a simple TCP socket. The YunServer listens for an incoming connection, and creates a YunClient to handle the actual socket once a connection is made. The documentation on it is not very good, but it can be used two ways.
One way is to create a REST API as shown in the Bridge library example. In this case, the Linux side listens for web requests, and if it finds one that begins with the token /arduino/ immediately after the node address, it makes a connection to the YunServer in the sketch, and passes it everything after /arduino/token. The result is that a YunClent is created which when read returns the rest of the URL, and anything that is written to the client is sent back as a response to the requesting computer. The key to getting this mode to work is to not specify a port number in the YunServer constructor, and to call server.listenOnLocalhost() before calling server.begin().
On the other hand, if you do specify a port number in the YunServer constructor, and you call server.noListenOnLocalhost() before calling server.begin(), you end up with a generic TCP port server. It will listen for incoming connections on that specified port, and create a YunClient to manage that connection. Anything sent to the Yun from the remote computer can be read through the client, and anything written to the client is received by the remote computer.
YunClient is derived from the Stream class, just like Serial and Console. That means that any of the usual ways of dealing with serial I/O will work in exactly the same way with a YunClient object.
While YunServer/YunClient and Console are coded quite differently, they do similar things: manage a TCP connection over the network, which simulates a serial data stream. The advantage to the Console class is that it is easier to code in the sketch, and easy to connect to using the Arduino IDE, but it is more difficult to make a connection from an external computer (I believe you need to establish an SSH connection first, and then run Telnet on the Linux side of the Yun.) On the other hand, YunServer/YunClient is more work to implement in the sketch, but it allows multiple simultaneous connections (if coded properly) and it's very easy to make a direct connection from another computer.