05-26-2021 02:30 PM
Hi guys,
When I want to activate a LED with the Visa Write, it changes the values of the sensors. I tried different methods, different delay values... But nothing seems to work. I don't know if it has to do something with my arduino or labview code. The Led shouldn't have an impact on the values.
Could you guys help me out with this.
I'm Going to put the whole project here, you guys should only pay attention to the 'Visa write and read' part.
Hope you guys can help me out.
My arduino code:
int LedY1 = 12;
int LedY2 = 13;
int LedG1 = 11;
int LedG2 = 10;
int LedR = 9;
String L1;
String L2;
String T1;
int data;
String string, c;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(LedY1,OUTPUT);
pinMode(LedY2,OUTPUT);
pinMode(LedG1,OUTPUT);
pinMode(LedG2,OUTPUT);
pinMode(LedR,OUTPUT);
}
void loop() {
if(Serial.available()>0)
{
data=Serial.read();
if(data=='1')
{
digitalWrite(LedY2,HIGH);
}
else if(data=='0')
{
digitalWrite(LedY2,LOW);
}
}
delay(200);
// reads the input on analog pin A0 (value between 0 and 1023)
int analogValue = analogRead(A0); //lichtsensor 1
int analogValue2 = analogRead(A1); //lichtsensor 2
int analogValue3 = analogRead(A2); // temp
L1 = analogValue;
L2 = analogValue2;
T1 = analogValue3;
Serial.println("T=" + T1 + "L2=" + L2 + "L1=" + L1);
}
05-26-2021 02:33 PM
Here is also my subvi if needed
05-26-2021 04:18 PM
Please use block diagram cleanup. There is a lot of white space. It takes it from 4 screens of code down to something that fits in 1 screen with just a single click!
What exactly are your sensors? The only thing I see is a sort of simulation with your subVI.
Why do you have the i terminal of the while loop wired to the VISA read?
First iteration read 0 bytes, 2nd read 1 byte, 3rd read 2 bytes, .... 1,000,000 iteration read 999,999 bytes (which will take forever and time out!) It makes no sense.
05-26-2021 05:21 PM
@RavensFan wrote:
Please use block diagram cleanup. There is a lot of white space. It takes it from 4 screens of code down to something that fits in 1 screen with just a single click!
What exactly are your sensors? The only thing I see is a sort of simulation with your subVI.
Why do you have the i terminal of the while loop wired to the VISA read?
First iteration read 0 bytes, 2nd read 1 byte, 3rd read 2 bytes, .... 1,000,000 iteration read 999,999 bytes (which will take forever and time out!) It makes no sense.
I'd have to say that's pretty ugly code for a self-proclaimed "Labview" master.
05-26-2021 08:01 PM
The first thing I would do is change the format of the data you are sending form the Arudino. I would change it to:
Serial.println(T1 + ";" + L2 + ";" + L1);
With that update, you can eliminate the code you use to format your file data. You can just write the string straight from the VISA Read.
As far as your serial port usage, I don't see why you need 2 ports; you should just be using the one port. A single port can read and write.
Next, get rid of all of the VISA Clear and Flush IO Buffer functions. They are not needed.
For the read, just tell the VISA Read to read more bytes than you expect in a message. You have the termination character turned on and set correctly since the println command will append the termination character for you. So just wire a constant 50 to the number of bytes to read and the read will stop when the termination character is read.
For parsing the read data, just use the Scan From String with a format of "%f;%f;%f" (assuming you follow my advice above).
There is no reason to use a shift register to store string data you already wrote to the file.
You should consider using the actual File IO functions to create/open the file and write the header before the loop, close the file after the loop, and use Write To Text File to write the data as much as you want inside of the loop.
05-27-2021 07:20 AM
@billko wrote:
@RavensFan wrote:
Please use block diagram cleanup. There is a lot of white space. It takes it from 4 screens of code down to something that fits in 1 screen with just a single click!
What exactly are your sensors? The only thing I see is a sort of simulation with your subVI.
Why do you have the i terminal of the while loop wired to the VISA read?
First iteration read 0 bytes, 2nd read 1 byte, 3rd read 2 bytes, .... 1,000,000 iteration read 999,999 bytes (which will take forever and time out!) It makes no sense.
I'd have to say that's pretty ugly code for a self-proclaimed "Labview" master.
There is now no reason for my post because the user chose a new user name that no longer describes a level of experience. 😄