smondal
Australia
Asked
— Edited
Hi I need some help with "Terminal EZB" panel under general skills. I have got a few sensors added at JD's hands through an Arduino board. The sensors are expected to transmit some data and I am able to see it like below.
Now, I'm trying to save this data to a text file and I've written the following code.// Add the filename and use double \\ for the folder separator
var filename = "c:\\temp\\mylog.txt";
while(true){
UART.initHardwareUart(1,9600,0);
var uart_data = UART.hardwareUartReadStringAvailable(1,0);
var d = new Date();
var outStr = d.getHours().toString().padStart(2, '0') + ":" +
d.getMinutes().toString().padStart(2, '0') + ":" +
d.getSeconds().toString().padStart(2, '0') + ":" +
d.getMilliseconds().toString().padStart(3, '0') + "," +
uart_data;
File.appendStringLine(filename,outStr);
}
However, I suspect that this piece of code is not correct as it prints only the timestamps and nothing else. So, can anyone please please point the error in this code?
Thanks.Quote:
13:35:52:357, 13:35:52:370, 13:35:52:380, 13:35:52:392, 13:35:52:403, 13:35:52:414, 13:35:52:425, 13:35:52:437, 13:35:52:448, 13:35:52:459,
Related Hardware JD Humanoid
Related Control
Serial Terminal
The hardware init needs to be outside of the loop. Otherwise you're initializing the uart (and clearing incoming buffer) every time it loops. That'll be happening hundreds of times per second. You only need to initialize once.
The incoming data seems to be terminated by a new line. Do you know if it's a decimal 10, a decimal 13, or both? Because you'll have to parse the data based on the new line character. Look at the arduino code and tell me what terminator it's using.
Because the data is pouring in at some unknown rate, the hardware uart read may only have half a line of data. OR will most likely have many lines of data. So the idea is to add the data to a buffer and then parse through the buffer.
I'll post something more detailed
Okay here you go. I tested this and it works...
I updated my code sniplet to include a \n as terminator because that is what the arduino serial.println() uses
Thank you DJ Sures. I tested the code with my JD. Now it's working perfectly. I'm getting the proper output as follows:
This is the Arduino code that I'm mainly using.