Is it possible to send double values using the TCP/IP client block in the Simulink Support Package for Raspberry Pi?
I have been stuck for a while trying to get this to work:
but using printf("%f %f %f", *((double *)tcp_buffer)), *((double *)tcp_buffer + 1)), *((double *)tcp_buffer + 2)))
only prints zeros.
This, however, works ok (printing an int):
After trying to get this working for quite a while, I am under the impression that it will not work (or there is a rather obscured way of doing it). I wound up implementing my own TCP/IP client device driver (i.e. a Simulink block similar to the ones provided by the package) to do the trick and thought I'd leave my implementation here for anyone that's looking. (I think it's better that way anyway as you can really define how you want your client to work.)
To create the device driver, one would need to follow the instructions found on the MATHWORKS site here.
My C implementation for the client is as follows:
and
Next, you'd need you System Object (I named mine TcpClient):
Now you can send doubles and if you create your server correctly using the code from here which I adapted to create a function that reads the TCP buffer:
you can read and print the doubles correctly.