08-20-2013 06:31 PM
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");
}
}
08-20-2013 07:23 PM
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):
08-21-2013 12:15 AM
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