Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

inconsistent visa read

Solved!
Go to solution

Hey I'm using an Arduino Uno and have 4 thermocouples connected. The code I have seems to work fine but every ~15 readings, at random intervals the program returns 0 for two or three of the thermocouples. I added a delay to this program because it wasn't working without it, but could it also be the source of the problem? I have a 3 second delay programmed to the Arduino and a 1 second delay to the LabView code. 

Thanks!

 

Arduino 1.0.5 code:

 

 

#include "Adafruit_MAX31855.h"

int thermoDO = 3;
int thermoCS1 = 4;
int thermoCS2 = 4;
int thermoCS3 = 4;
int thermoCS4 = 4;
int thermoCLK = 5;

//Adafruit_MAX31855 thermocouple(thermoCLK, thermoCS, thermoDO);
Adafruit_MAX31855 thermocouple1(thermoCLK, thermoCS1, thermoDO);
Adafruit_MAX31855 thermocouple2(thermoCLK, thermoCS2, thermoDO);
Adafruit_MAX31855 thermocouple3(thermoCLK, thermoCS3, thermoDO);
Adafruit_MAX31855 thermocouple4(thermoCLK, thermoCS4, thermoDO);
//Adafruit+MAX31855 thermocouple5(thermoCLK, thermoCS5, thermoDO);
void setup() {
Serial.begin(9600);

Serial.println("MAX31855 test");
// wait for MAX chip to stabilize
delay(500);
}

void loop() {
// basic readout test, just print the current temp
//Serial.print("Internal Temp = ");
//Serial.println(thermocouple.readInternal());


double c1 = thermocouple1.readCelsius();
double c2 = thermocouple2.readCelsius();
double c3 = thermocouple3.readCelsius();
double c4 = thermocouple4.readCelsius();

if (isnan(c1)) {
Serial.println("Something wrong with thermocouple!");
} else {
Serial.println(c1);
Serial.println(c2);
Serial.println(c3);
Serial.println(c4);

}

delay(3000);
}

0 Kudos
Message 1 of 3
(3,693 Views)
Solution
Accepted by jerm

I would recommend using the termination character for the VISA Read.  That way you won't need the Bytes at Port function.  Just set the bytes to read to something rediculously high.  You will need to have your Arduino output a line feed at the end of each transmision.  That tends to clear up a lot of communication issues.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 3
(3,670 Views)

Thanks! The Termination Character worked when I included an extra blank line with Serial.println() and the line feed to the Instrument property node. The only thing was that I just set the number of bytes at port to 30, because when I tried large numbers, (first guess was 1000), the program wouldn't run correctly. Used the probes to determine what input it already was, and just copied in.

0 Kudos
Message 3 of 3
(3,657 Views)