06-18-2010 03:13 PM
My code does wait for the first "enter". One problem though is that you do not have the VI configured for a CR (ASCII 13). You have it configured for a LF (ASCII 10).
What the VISA Read does is automatically terminate it's read when the termination character is detected. That is one of the things done with the VISA Configure Serial Port. You can then set the number of bytes to read to some large number - you do not have to specify 3 bytes (do not count the termination character).
p.s. The array constant is used to initialize the shift register. That is done so that the Build Array will start with fresh data each time the for loop starts.
06-18-2010 03:38 PM
@baicy wrote:
Thank you very much, guys.
Please bear with me a little longer, because I’m still baffled.
1. First of all, I run the Dennis’s VI, here is what I got. The output of the visa read is still broken. Forgive me if I was wrong, what you trying to do is use the case statement to discard the first reading and build the rest of the reading into an array, then pass the array to the FFT module. But I don’t quite get it why using the array constant as highlighted in the screen shot.
I think Dennis got his cases backwards. It looks like it should have been iteration 0, do nothing (thus discarding the reading), all other iterations to build the new value onto the array. The empty array you circled is to initialize the shift register with an empty array.
2. As Ravens said, it is going to be random on the first read, why it does not happen with the hyperterminal?
It probably does happen on hyperterminal. You'll only see it on the very first line read in after you open the port.
3. I kept the the termination character always enabled. I got the wrong concept of wait until next ms multiple function. So all I can control is how many strings read from the VISA READ. If I want to get 100 readings, I need to set the iteration number to 100.
Yes. Termination character enabled. 100 to the For Loop constant will read 100 packets of data.
4. About the byte count, it should be 4 in my case, isn’t it? I check the code of the microcontroller, it send the the bit data in following way: take the first two highest bits and send off, then take the next four bits and send off, then the lowest four bits, at last send a ascii “13” as an enter. So could we do it this way: detect the first “enter” then start visa read?
Many thanks,guys!
Actually I would say it sends off a character that is the hex value of the first four bits, then a character for the hex value of the next 4, then the next 4, then an ASCII character for the end of the packet. You say your ASCII character is 13? Then the termination character should be 13 decimal (0D hex) which is a carriage return. Your earlier screen shot showed it set for 0A hex or 10 decimal which is a line feed character (/n or new line in /codes display). Make sure you set that input to the serial initialization function correctly. If your device is sending ASCII 13, and you set the termination for ASCII 10, then you've effectively disabled the termination character. Then it will go to the max 4 characters you are requesting on every read. If you start off out of sync, you'll get FF <cr>1, and keep getting that over and over. Set it to 13, and you 'll get FF<cr> on the first read, then will be in sync at 1FF<cr> thereafter.
If your termination character is enabled and set properly, it won't matter what number of bytes you need to read as long as it is at least 4.
06-18-2010 03:40 PM
Sorry, I did get the cases swapped.