Sending data between Windows Applications: Difference between revisions

From Control Systems Technology Group
Jump to navigation Jump to search
No edit summary
Line 16: Line 16:


[[File:Read_file.png|x420px]]
[[File:Read_file.png|x420px]]
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 <code>"C:\\angles.txt"</code> (line '''49'''). It should be replaced by the absolute file path of the file the user would like both applications to use. <code>in</code> is an input stream intialized somewhere else in the code.
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 <code>"C:\\angles.txt"</code> (line '''49'''). It should be replaced by the absolute file path of the file the user would like both applications to use. <code>in</code> is an input stream intialized somewhere else in the code.


Per new line in the text-file, the position of the <code>:</code> is found (line '''56'''). In the lines '''58-61''', the index of the data and its value are stored in <code>dataNr</code> and <code>angle</code> respectively. These are then stored in the <code>data</code> array created in a different part of the code.
Per new line in the text-file, the position of the <code>:</code> is found (line '''56'''). In the lines '''58-61''', the index of the data and its value are stored in <code>dataNr</code> and <code>angle</code> respectively. These are then stored in the <code>data</code> array created in a different part of the code.

Revision as of 18:58, 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

Example of the text-file

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

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.

Read file.png

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.