LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial communication with bluetooth

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?

0 Kudos
Message 11 of 23
(1,628 Views)

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.

0 Kudos
Message 12 of 23
(1,624 Views)

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.

 

16867i241A1B82A36AC47E

16869i220B93C0CE3C855F

16871i4B918BC1608F42E5

0 Kudos
Message 13 of 23
(1,607 Views)

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?

0 Kudos
Message 14 of 23
(1,605 Views)

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?

16879i4E63F07E99C2C4A2

0 Kudos
Message 15 of 23
(1,599 Views)

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.

0 Kudos
Message 16 of 23
(1,594 Views)

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!

16909iDD021E9153F041F4

 

 

0 Kudos
Message 17 of 23
(1,586 Views)

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.

0 Kudos
Message 18 of 23
(1,580 Views)

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.

0 Kudos
Message 19 of 23
(1,573 Views)

 

 

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.
  2. As Ravens said, it is going to be random on the first read, why it does not happen with the hyperterminal?
  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.
  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!

 

 

 

 

 

16977iDA72CBA41BC51538

 

0 Kudos
Message 20 of 23
(1,557 Views)