Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

PDA: Problem with Bluetooth/virtual serial port connection

Hello,
 
I'm trying to write a VI to communicate with a DAQ system via Bluetooth on my PDA, but I'm having problems establishing a connection while my LabVIEW program is open.  Here's my hardware/software:
 
LabVIEW 7.1
LabVIEW PDA Module 7.1
Dell Axim x50
  Windows Mobile 2003 Second Edition
  Bluetooth for Windows CE, BT-PPC Version 1.5.0 Build 2601
 
I read "Does LabVIEW for PDA support Bluetooth?" and have tried to establish BT connection 2 different ways:
 
1) bluetooth functions
  1. open connection:  I know my DAQ system's device address to I input that and get a connection ID.  I found that I get an error if the PDA-DAQ BT connection is established beforehand, so I start with no connection.
  2.  bluetooth write: I know the channel number for serial communications on the DAQ system, so I input that when I send commands to the DAQ system-- commands such as turn on pump, open valve, or output a datastream, for a set period of time
 3.  no response to my commands and no error messages.  whether or not I close the Bluetooth connection in the LabVIEW program, after I close the program, there is no PDA-DAQ BT connection.  However, if I establish the PDA-DAQ BT connection after the program is closed, the DAQ system performs the last command sent in the LabVIEW program-- the pump turns on or valve opens-- I can't tell whether there is data output because I can't read/collect it.
 
2) serial port functions
  1.  intialize serial port: I know the virtual serial port assigned for outbound BT communications is COM7 (port index 6) so I input this and the DAQ system's baud rate.  Like with the bluetooth functions, I get errors if the PDA-DAQ BT is connected before initializing the port, so I start with no connection.
  2.  serial port write: write DAQ commands to COM7
  3.  no response to my commands and no error messages.  no PDA-DAQ BT connection found after I close the LabVIEW program.  However, once again, if I establish the PDA-DAQ BT connection after I close the LabVIEW program, the last command sent in the program is performed.
 
I've attached both VIs.  I'm able to connect and communicate PDA-DAQ BT on an mToken terminal (kind of a hyperterminal for PDAs), so I know the virual serial port (COM7) and bluetooth should work.  I've also tried a combination of bluetooth and serial functions in a LabVIEW program, but get lots of errors.  I've read a few posts about Axim and/or windows BT driver problems with LabVIEW, but didn't understand the issues.  So, sorry if I'm asking about problems that have already been addressed. 
 
Any help is much appreciated,
 
thanks in advance,
Luan 
Download All
0 Kudos
Message 1 of 5
(6,386 Views)
Luan,
So the good news is that we're sure you are connecting to your DAQ system from your PDA. We know this because at least one command is being acted upon (the last one sent!). I would trouble shoot by first removing ALL race conditions from your code. I noted that you are using a lot of Local Variables in your code and your code isn't sequenced based on data flow. So I recommend two things:
 
1. Write a very simple program that opens a blue tooth (BT) connection, waits, writes out one of your  BT commands, waits and then closes. This sequence should be done without user interaction. If this program works then we know that BT isn't the problem and there's a programming issue.
 
2. Rewrite your current code and remove all local variables (a deadly source of race conditions in the way that you're using them). A race condition means you're both reading from and writing to a variable at the same time. So what happens if you read from it before you've written to it? Bad news.
 
Your code should be organized in the following way.
1. Establish a connection to the DAQ system via blue tooth. Until this happens, nothing else should happen. In your current code, a user could push the "send" button before a connection is even made. Then the BT connection ID local variable would be empty and your program would throw an error.
2. Respond to user requests, like pressing a button.
3. Read data ( be aware that there is no multithreading on a PDA).
4. When the user presses exit, stop your looping structure and then close the BT connection.
 
You'll probably want to either use an event structure or a state machine architecture for your program. These are a little advanced but there are a ton of examples in the example finder (Help>>Find Examples). Also there are templates of these architectures in LabVIEW (File>>New...>>VI>>From Template>>Frameworks>>Design Patterns).
 
I hope this is helpful. Post to let us know how it goes!
 
Chris C
 
Message 2 of 5
(6,371 Views)

Thanks, Chris!  I appreciate all your feedback.  I've previously written a few LV programs and looking back at all the race conditions in my code, it's a wonder that I got anything to work before now!

So, I completed your recommendation #1 and I'm getting the same delayed DAQ system response as before.  The following functions execute sequentially:  Bluetooth Open Connection, Bluetooth Write, then Close Bluetooth Connection.   While the PDA program is open, nothing happens, but after I close the program and then establish the PDA-DAQ BT connection, the last command will execute. 

I did get 1 error code.  When I wrote this program in a flat sequence structure, I got an error during the Close Connection function: App failed. Unable to lock memory chunk.  Error code: 130513003.   Despite the error, after the LV PDA program closed, the final DAQ system command still executed with PDA-DAQ BT connection.  I wasn't sure what was wrong, so I wrote the program in a State Machine structure as you'd suggested.  With this structure all 3 functions executed without error, even though the program still isn't doing what I want.

Any thoughts?  I'm attaching both programs.

thanks again, Luan      

0 Kudos
Message 3 of 5
(6,348 Views)
Luan,
I think at this point we should remove the DAQ system from the equation and just see what commands are getting issued from the PDA. Create a "Listener Program" on your development PC that consists of an ""Create listener", "Wait on Listener", "Bluetooth read". Then have your PDA connect to your PC (I'm assuming that you have bluetooth on your pc) and issue your commands. If that works then we know the problem is with the DAQ system. Let us know what you find.
 
 
Chris C
 
0 Kudos
Message 4 of 5
(6,308 Views)

Chris,

I just figured out what I was doing wrong-- I wasn't adding a carriage return to the end of my commands to the DAQ system in my program.  That's all the setup needed to work.  I feel silly, but now I know better and can move on.

Thanks for both your replies.

 

all the best,

Luan  

0 Kudos
Message 5 of 5
(6,304 Views)