Click here to Skip to main content
15,918,268 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
MY C++ APPLICATION is reading data form device.e.g Temperature sensor. Sensor is transmitting update after 1 seconds. But I want to insert the sensor update data only when temperature changed with current timestump into CSV file using java script.For the first time i need to create a new file and afterwords just update the previous file.
Required CSV file
Time                     Temp(C)
12:30:12:325              57
12:30:15:351              56
12:30:17:453              57


What I have tried:

HTML+JS.
----------
<html>
<script type="text/javascript">
function createCSV() {
csvRows = [["label first","details of label 1"],["label sec","details of label 2"],["label 3","details of label 3"],["label 4","details of label 4 and 3"],["label 5","details of label 5"],["label 6","details of label 6"],["label 7","details of label 7"],["label 8","details of label 8"],["label 9","details of label 9"]];

var csvString = csvRows.join("%0A");
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + csvString;
a.target = '_blank';
a.download = 'myFile.csv';
document.body.appendChild(a);
a.click();

}
</script>
<body>
<form action="" method="post">
<input type="button" value="Create" >
</form>
</body>
</html>
Posted
Updated 4-Aug-16 4:39am
v3
Comments
ZurdoDev 3-Aug-16 10:17am    
What code?

I know of no way to use JavaScript to modify files. You can call into a webservice using JavaScript and have the webservice, written in C#, modify files on the server. That is easy to do.
Mohibur Rashid 3-Aug-16 19:09pm    
NodeJS may be :) but WTP?
ZurdoDev 3-Aug-16 21:02pm    
NodeJS is still javascript. If you want to modify files on the client side you have to find another way.

1 solution

Javascript isnt crafted for writing files. It is a security feature to ensure that browsers dont manipulate any PC.

But when you have a C++ App you already have the full native power. Here is some tutorial for coding file access. In your app you must have some variables or better objects with the last values and if changed you append the data.
 
Share this answer
 
Comments
XamBEE 4-Aug-16 3:22am    
<html>
<script type="text/javascript">
function createCSV() {
csvRows = [["label first","details of label 1"],["label sec","details of label 2"],["label 3","details of label 3"],["label 4","details of label 4 and 3"],["label 5","details of label 5"],["label 6","details of label 6"],["label 7","details of label 7"],["label 8","details of label 8"],["label 9","details of label 9"]];

var csvString = csvRows.join("%0A");
var a = document.createElement('a');
a.href = 'data:attachment/csv,' + csvString;
a.target = '_blank';
a.download = 'myFile.csv';
document.body.appendChild(a);
a.click();

}
</script>
<body>
<form action="" method="post">
<input type="button" value="Create" >
</form>
</body>
</html>
XamBEE 4-Aug-16 3:25am    
This is the method of writing text into CSV file.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900