LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Acquiring serial communication data with VISA and Arduino at ms iterations

My current objective is to write some timestamps from my arduino uno to Labview using VISA for the serial communication as in the attached vi. When I have my timer set to higher values the value sent to ("String") is usually right. When lowering the timer value the number of bytes sent through "VISA Read" fluctuates wildly. e.g. at roughly 4000000 microseconds, sometimes the output will be ~4000000 other times I'll get 60000,or 900000000. 

 

Also, if I uncomment the //Serial.print 1,DEC); line and comment the //Serial.print (micros(),DEC);. line and have the timer set to a  value of 7 or lower then sometimes string will output "1", other times "11", and other times a blank. So from what i can tell the serial writes are being delayed from 1 iteration to the next. 

 

Note that if I just run the arduino code alone and look at the outputted values in the Serial monitor I get consistently increasing output: e.g. 336000, 336547, 337003, etc. (iterations of less than a ms)

 

I was wondering if it was possible to get the same consistent output in labview.

 

Note: I first run the arduino sketch in the Arduino IDE and then run the labview program. 

 

 

long a, ivalue;
void setup (){
// 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200
Serial.begin (38400);
}

void loop()
{
a=1;
Serial.print (micros(),DEC);

//Serial.print 1,DEC);

Serial.print("\n");

if (Serial.available()>0){
// a=Serial.read()-'0';
//Serial.print (micros(),DEC);
//Serial.print("\n");
}

}

0 Kudos
Message 1 of 3
(4,488 Views)

One problem is that Windows (and other desktop OSes) has a preemptable kernel. So you can't rely on better than roughly 40ms accuracy. Another problem is that not all of the Bytes are not present when you call "Bytes at Serial Port". Since you have the serial termination character turned on, just ask for more Bytes than you expect. When the term char is seen, the read will finish. (Snippet's in 2012, but it's one panel):

 

arduino timer serial_BD.png

 

 

0 Kudos
Message 2 of 3
(4,474 Views)

Time at which uno is sending time and labview is reading may not be synchronized but in monitor they are. To verify that Write arduino program in such a way when you write something then only it should send time....

In arduino 

if(Serial.available() >0)

{

   Write time to serial port.

}

 

Try this

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 3 of 3
(4,462 Views)