06-17-2010 11:10 PM
Sorry, the problem remains, I double checked with hyper terminal. The results I got is 1FF,1FF continually. However, the VI you give to me keep lossing bis.What else could be wrong?
06-17-2010 11:26 PM - edited 06-17-2010 11:28 PM
No idea.
Post a screen shot of what it looks like in Hyperterminal.
Run NI-Spy while running the VI and post that log file.
Also, run the string wire from the VISA read out of the for loop and let it autoindex. Then wire that 1-D array to a write to spreadsheet file and post that. (Also put an indicator on that array of strings.) Let's see how the raw string data looks.
06-18-2010 04:57 AM
Hi Revans,
The Hyperterminal screen shot and VISA read out probe are presented as below. There are alsways repeatable missing bits. However, I tried the advanced serial write and read in the example, it seems to be alright. Do you know what is going on here? Thanks.
06-18-2010 05:12 AM
Another confusing thing is that if I change the input to the Wait Until Next ms Multiple Function in the advanced serial write and read.vi. The similar results happened as your VI. I'm really confused, any other solutions for reading the serial port?
06-18-2010 07:32 AM
When I run the advanced visa write and read.vi, I found the data reading is random.
For example, the string is supposed to 1FF,1FF,1FF,1FF. However, the string from the visa read could start with 1, 1FF,1FF,1FF,FF or 1F,1FF,1FF,1FF,F.
I stop the program and run it again, I can get different results. That is why I get right results from the previous advanced visa write and read.vi. The screen shot shows three different results from three different runs. Has anyone come across situation like this?
06-18-2010 07:42 AM
Your first byte is random because you are not yet synched to the transmission. This is normal. Discard the first byte if it is not the correct length.
06-18-2010 08:17 AM
Hi, Dennis,
Unfortunately, I don't think that I can discard the first byte.
I set Wait Until Next ms Multiple Function to 2ms, in order to get a 500hz smapling frequency.
And I set the iterative number to 500, in order to get 1 second sample to FFT.
Then I set the byte court of visa read to be 4, thus I can get only one whole reading from Bluetooth in 2ms.
The problem is that the readings are not synch as shown in screen shot. How can I get them synchronised.
Thank you!
06-18-2010 09:08 AM - edited 06-18-2010 09:09 AM
As Dennis said, it is going to be kind of random as to how many bytes you get on the first read. It all depends on exactly what precise time the Serial port initialization occurrs. If you get lucky and the port is opened in the period of time between messages getting sent, then your first read will be an entire packet. If the port opens during the period of time after a character, or two, or three has arrived, then the first packet read will be incomplete.
He really should have said discard the first read, rather than "discard the first byte". After your initialization and before you start the loop, do a sing VISA read that will grab the first packet and do nothing with it. Then all reads after that should be completed packets of 3 bytes followed by the termination character.
I don't know why your earlier graph showed good bytes for so long and a bad byte in the middle. Unless it is a chart and you had stopped your VI and restarted it. And the data point in the middle is actually the first packet read after restarting.
In your latest screen shot, do you still have the termination character enabled? You should. You did earlier. If you don't, then the read did not stop at the LF character, but proceeded to read the next 2 bytes of the next packet since you requested 4 bytes.
A VISA read will end when one of three things happen, in this order:
1. The termination character has been received (but only if the termination character has been enabled.)
2. The requested number of bytes have been read.
3. Neither 1 nor 2 has happened, and the timeout value has been reached.
I don't understand your comment "I set Wait Until Next ms Multiple Function to 2ms, in order to get a 500hz sampling frequency". You can't control your sampling frequency. It is determined by the rate that the instrument sets the data. There is no need to set a Wait or a Wait for Next msec function in there. At best it does nothing. At worst, it causes your loop to take too long and you get data building up in your VISA buffer causing the next data to read to just be old data and then older and older data, until the buffer eventually fills up and overflows. You need to keep reading as fast as you can so it doesn't happen. The sending instrument is what ultimately determines the rate and throttles the loop.
06-18-2010 09:16 AM - edited 06-18-2010 09:18 AM
Of course you can, you just don't know how. One way is with a shift register and a Build Array function. Place the Build Array in a case statement.
Edit-Ravens is correct, I meant the first read and not the first byte.
06-18-2010 02:43 PM
Thank you very much, guys.
Please bear with me a little longer, because I’m still baffled.
Many thanks,guys!