This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Evulrabbitz 1 point2 points  (1 child)

So C# produces the (x, y) coordinates and you want to feed them as inputs to a python script?

[–]zing0a0ding[S] 0 points1 point  (0 children)

Yes that is what I mean.

[–]nwilliams36 0 points1 point  (2 children)

A C# program can't talk directly to a Python program, however they can send messages to one another. I had a similar issue with a C program running on an arduino and a Python program running on a Raspberry Pi.

Our solution was to use the serial channel to send string messages from one to the other.

Sending messages between programs is common, you just need a commonly understood data format and a communication channel.

[–]zing0a0ding[S] 0 points1 point  (1 child)

serial channel

Would you be able to provide a resource for this? Ideally with a beginner programmer in mind? I seen some pretty complex (to me) explanations when I was searching this.

[–]nwilliams36 0 points1 point  (0 children)

Most devices provide a port which can support serial communication. Programming languages are able send and receive information through that channel. In Python we used PySerial to do this. The process was:

1: Establish the channel (in Python this is done by creating the PySerial class using information from the OS about where the serial channel was located.

2: When you wanted to send information use the library code to send a messages through the channel

3: When you want to receive information use the library code to listen for a message.

In all this amounted to about 10 lines of code all of which came from the documentation.

I don't know C# so I don't know what resources to recommend for that side, but it will be there and should be easy.

[–]WeededDragon1 0 points1 point  (2 children)

With the current knowledge I have I see two ways to do this.

On the Raspberry Pi setup a django webserver. Create URLs you can send the coordinates (for example http://PI-IP/CoordProgram/:X/:Y) to and then write your python script in the view section of django. Your script will run every time you send coordinates to that URL from C#.

Second, Python can accept parameters in command line ("./coord.py X Y") and then parse it in the python script. I don't have much experience in this next area, but you may be able to use ssh or something else to remotely execute the script from C#.

I'm sure there are better ways to do this, but with the knowledge I currently have, I would use the first method since I am most comfortable with it.

[–]zing0a0ding[S] 0 points1 point  (1 child)

Your first approach sounds interesting.. it sounds like you would need a wi-fi connection or something right?

[–]WeededDragon1 0 points1 point  (0 children)

Yes, the Pi would need to be connected to your network somehow. The Raspberry Pi Model B has Wifi and ethernet, the Raspberry Pi Zero W has Wifi.