Reputation: 25
So I need to control a RPi from a separate PC running Labview, and serial is the only way I've managed to get any communication working at all (why can't they just implement SSH...).
I've got my python (2.7) program on the raspberry reading the inputs properly, but how can I send a function with parameters through for it to carry out? Each line comes through as a variable called serial_in which isn't callable.
Upvotes: 1
Views: 60
Reputation: 5430
You could serialize the function as a string, send it over the serial port and then use eval()
on the RPi to execute the code. If the function is simple you could just form it as a string to begin with. For example, you could send a function like this:
send("x * x")
Then on the RPi side:
func = receive()
result = eval(func, {x: 1})
Upvotes: 1