I am trying to separate the Voltage and current value coming from serial port using VISA. But only first value is reading. What would be the error? This is my LabVIEW file
This is my Arduino code
void setup() {
Serial.begin(115200);
}
void loop() {
float voltage = analogRead(A0);
float current = analogRead(A1);
Serial.print(voltage);
Serial.print(",");
Serial.println(current);
delay(100);
}
Hi Gappiya,
why do you convert a string of two values into a 2D array of data?
Why do you try to index row 0 and 1?
Why do you use such a format string for this specific conversion function?
Suggestion:
Replace SpreadsheetStringToArray by ScanFromString and use the same format string to get two outputs from your two values (per message)…
The Spreadsheet String To Array function defaults to using the tab as the delimiter while your sketch is using a comma. But that does not matter here since you would be better off here just simply using Scan From String to parse the string into the two values.
@Gappiya wrote:
I am trying to separate the Voltage and current value coming from serial port using VISA. But only first value is reading. What would be the error?
This is my LabVIEW file
This is my Arduino code
void setup() { Serial.begin(115200); } void loop() { float voltage = analogRead(A0); float current = analogRead(A1); Serial.print(voltage); Serial.print(","); Serial.println(current); delay(100); }
For such a simple task, LINX or Hobbyist toolkit will simplify the code a lot.
https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z0000019TmpSAE&l=en-US
Hi Gappiya,
why do you want to apply Waveform functions on scalar samples?
Why do you even need ExpressVIs for the task? (ToDDT is an ExpressVI…)
Why don't you handle errors programmatically?
Did you receive the string as expected by ScanFromString?
Hi GerdW
I used Waveform functions to offset the signal (2.5V to zero)
I used ToDDT because Waveform functions accept Dynamic data
What string should include for the ScanFromString (%f,%f or %f)
Thank you
Hi Gappiya,
@Gappiya wrote:
I used Waveform functions to offset the signal (2.5V to zero)
I used ToDDT because Waveform functions accept Dynamic data
@Gappiya wrote:
What string should include for the ScanFromString (%f,%f or %f)
How does the received string look like when error 1 pops up?
The format string should match the format of the received string (or vice-versa)…
Your code:
Serial.print(voltage);
Serial.print(",");
Serial.println(current);
results in a message like "1.234,5.678\n" (with "\n" marking the LF char added by println), so the format string should be "%f,%f".
Is your computer set to use English numeric format with the point (".") as decimal separator char?
@Gappiya wrote:
I used Waveform functions to offset the signal (2.5V to zero)
I used ToDDT because Waveform functions accept Dynamic data
What string should include for the ScanFromString (%f,%f or %f)
1. Just use the Add function to the sample.
2. The Waveform functions accept Waveforms, which can be coerced from the DDT. But if you just use the Add function instead of the Waveform Scale & Offset, there is no need for the ToDDT.
3. The format string should be "%f,%f". If there is a possibility your system uses the comma decimal separator, you should use "%.;%f,%f". The "%.;" forces the Scan From String to use the period as the decimal separator.
Thank you very much for the comment. I did the modifications but neither "%f,%f" or "%.;%f,%f" working. still i am getting same error