Sending data between Windows Applications: Difference between revisions
(4 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
== Writing to the text-file == | == Writing to the text-file == | ||
This part of the code belongs to the application responsible for calculating the angles controlling the AMIGO's arms from input from the Kinect sensor. Additional information about this application's code can be found [http://cstwiki.wtb.tue.nl/index.php?title=Kinect_Angles_Calculation_Script here]. | |||
[[File:Write file.png|x420px]] | |||
Before new data is written onto the file, the old data is erased in the lines '''710-712'''. Then, in the lines '''715-717''', the standard output of this application is changed to the text-file and the old output is saved to restore it later. In line '''719''', the precision for printing doubles is set. Following these are the lines '''722-724''' where the actual data is output using the format explained above. The final line resets the original standard output of this file. | |||
To get this code working properly, the absolute file path of the text file should be used instead of the file path <code>"C:\\angles.txt"</code>. The same file path should also be used in the code below as well. | |||
== Reading the text file == | == Reading the text file == |
Latest revision as of 20:18, 20 June 2016
This is a brief explanation of code used to send data between Windows applications using a simple text-file that is being written and read by the communicating programs.
This code is part of a project to create a robot technique that allows users to hug someone when separated by a disctance like a phone call.
We do realise that this is an ad hoc method and that there are better ways out there to do this, but it suffices for our prototype.
Data format
An example of the format of the data to be written to and read from the text file is as follows: 0:3.1415926
. The number before the :
is the index of the value in the data array. The number following the :
is the actual value of the data, in this case [math]\displaystyle{ \pi }[/math].
Writing to the text-file
This part of the code belongs to the application responsible for calculating the angles controlling the AMIGO's arms from input from the Kinect sensor. Additional information about this application's code can be found here.
Before new data is written onto the file, the old data is erased in the lines 710-712. Then, in the lines 715-717, the standard output of this application is changed to the text-file and the old output is saved to restore it later. In line 719, the precision for printing doubles is set. Following these are the lines 722-724 where the actual data is output using the format explained above. The final line resets the original standard output of this file.
To get this code working properly, the absolute file path of the text file should be used instead of the file path "C:\\angles.txt"
. The same file path should also be used in the code below as well.
Reading the text file
This part of the code belongs to the application responsible for sending ROS messages to a Ubuntu machine from a Windows machine. Additional information about this application's code can be found here.
These lines are responsible for reading the data from the text-file with the absolute file path known to both applications. In this code, the absolute file path is "C:\\angles.txt"
(line 49). It should be replaced by the absolute file path of the file the user would like both applications to use. in
is an input stream intialized somewhere else in the code.
Per new line in the text-file, the position of the :
is found (line 56). In the lines 58-61, the index of the data and its value are stored in dataNr
and angle
respectively. These are then stored in the data
array created in a different part of the code.