LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

serial communication with bluetooth

 Hi all,

 

I need to  receive data from a bluetooth module with virtual serial port. Then send those data to do the FFT every 30 seconds. I tried tow different ways as shown in the attachements, however, I failed to get it work.

The first way is to use Instrument I/O assistant as Dennis suggested; After connected to the Bluetooth module and set the port number, the instrument I/O module says no response from instrument.

Then I tried the advanced serial write and read VI, the bluetooth module reading works fine in the example (advanced serial write and read.vi).However, I dont know how to connect the string and danamic data together as shown in the attachment.

So all I want is to obtain the data from bluetooth serial port for 30 seconds, then send off to the FFT.  Could you please help me? Thank you very much.

 

Baicy

Download All
0 Kudos
Message 1 of 23
(6,265 Views)
You need to turn the string information into a value.  Look at the string/number conversion functions in the string palette.  You will want to do this in a loop that runs for 30 seconds.  Each number you convert you will want to build into an array.  Once the while loop stops, then pass this numeric array to the array to dynamic data conversion Express VI.
0 Kudos
Message 2 of 23
(6,255 Views)

I can't believe you did nothing with the Instrument I/O Assistant. You didn't really expect to have me write anything for it, did you? I told you it was a dummy function since you did seem it important enough to provide any details. You could have at least made an effort. You could at least take one of the tutorials. You could at least put your VISA Read inside a loop to get multiple samples.

 

p.s. You are selling LabVIEW code to clients?

0 Kudos
Message 3 of 23
(6,245 Views)
Thank you very much,Ravens
 
To Dennis,
First of all, many thanks for your reply. This is not my major job and I’m not an engineer, but I would really like to improve it by using Bluetooth and Labview. Forgive me if I asked those silly questions and I’m very sorry if I didn’t make this problem clear before.
Here is what I’m trying to do:
1. Read the data (Hex) from the BT module, then send to the FFT module to process the data every 30 seconds.
I tied the Instrument I/O, I can validate the serial port: successfully open a visa session to ASRL20. However, when I tried to run the program, here is the error I got:Error -1073807298 occured at visa write in serial com.
2.Then I tried the advanced VISA.  However, it is not doing what I want neither. The Bluetooth module send the data from 10 bits A/D, the microcontroller send first two bits with 00**, then next 4 bits ****, then last 4 bits **** to the bluetooth, then bluetooth to Labview. I connected the Bluetooth module with Hyperterminal, I get maximum 3FF and minimum 000 as I expected. I used the Hexadecimal String To Number Function, but it is not convert the string correctly.
Could you please help me?  Really appreciate it.
Baicy
Download All
0 Kudos
Message 4 of 23
(6,204 Views)

Your VISA version is going the wrong way.  It is getting worse rather than better.

 

The intialization doesn't belong in the while loop.  The stop button does.  Right now it will either run once or forever because the stop button only gets read at the very beginning of the programming.

 

I don't know why you are wiring the purple VISA resource wire to your Hex string conversion function.  You don't actually use the string coming out of the VISA read at all.  And you are trying to read 5000 bytes.  Whatever value you actually get out of the hex conversion function, you are building a single element of an array and passing that out.  So whatever meaningless number that is, you actuallly only wind up with a 1-element array.  But you only get that if you have th stop button presses before the VI runs.  Otherwise you get nothing because you would be force to abort the VI to get it to stop.

 

As for the Instrument I/O assistant, you haven't done anything with that yet.  You are writing a *IDN? command to it.  That command tells instruments that might understand it to identify itself.  It doesn't give you any real data, assuming it gives you something at all.  Then your Read and Parse step doesn't seem to have anything associated with it.

 

As for your error message, that is "Could not perform operation because of I/O error."  Are you sure you have Hyperterminal closed when you run your VI?  Are you sure it is Com20?

 

I would recommend looking at the online LabVIEW tutorials
LabVIEW Introduction Course - Three Hours
LabVIEW Introduction Course - Six Hours

0 Kudos
Message 5 of 23
(6,199 Views)

baicy,

 

You don't have to be an engineer to use LabVIEW. You do have to take the time to take those tutorials and use Help (i.e. the button in the I/O Assistant). The *IDN? command is just the default when you create a new assistant and you should have been able to do something like in your DASYLab (is it really yours?) program which is just run a query.

 

Hex String to Number is the wrong function. You are not getting ASCII strings where that function is used.

0 Kudos
Message 6 of 23
(6,184 Views)

Thank you very much,Ravens.

I have completed the turorial and modified the VI, I can get some reading from the Bluetooth module, however, it is not entirely correct.

The bluetooth is sending Hex string "1FF" constinuouly, which can be verrified by hyper terminal, however, the readings from the VI is lossing data. For example, the string is something like: 1, 1FF,1FF,1FF,FF,1FF,1FF. Could you please help me? Again, many thanks.

Dennis, the Hexadecimal String To Number Function can convert the Hex string to the right number I want. For example, 1FF is 511. Why do you think that it is the wrong function? Thank you.

Baicy

0 Kudos
Message 7 of 23
(6,150 Views)

As I said before, get the serial port initialization out of the loops.  And also the input buffer setting that you have added since then.  When you initialize the serial port, (and now set the buffer size also) on every loop iteration, you are causing bytes to get thrown away that may have arrived in the buffer since the last read.

 

Dennis probably thought you were getting bytes of values like 01 and FF (two bytes of those values in hex) as opposed to 3 ASCII characters of "1" "F" and "F". If you are getting "1FF" that is  human readable in hyperterminal, then you are using the correct function to convert it to a number that you can work with in the calculations.

0 Kudos
Message 8 of 23
(6,147 Views)

Thank you very much for your quick replay!

I get the serial port initialization out of the loops as you segguested.

However, it doesn't improve anything. There are still missing bit. what do you think problem is?

 

Baicy

16819i976DBCD1A9462004

0 Kudos
Message 9 of 23
(6,139 Views)

NO NO NO!

 

All you did was move the controls out of the inner most loop.  You need to take the entire initialization function out of all loops.  You really don't need to set the buffer size.  And you need to close your VISA resource at the end and wire up all error wires.

 

 

 

 

0 Kudos
Message 10 of 23
(6,137 Views)