LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial Comms interrupt

Nubie -

 

I am not familiar with the NI thread pool functions, sorry.  Yup, the help is limited.

 

I am familiar with threading concepts and regulalry write muilti-threaded code, but I use Win32 calls directly, not the NI thread functions.

 

One way is to have a  mutex or semaphore that must be "owned" by a thread before it can read / write to the buffer.  A thread can wait for and become owner of a mutex or semaphore in Win32 with a WaitForSingleObject call, and release it with a ReleaseMutex() call (for a mutex anyway).

 

I create threads with the Win32 CreateThread ()  function.

 

There's quite a bit to all of this, writing a correct multi-threaded program isn't necessarily easy.

 

There are a couple of threads here on the forum dealing with multi-threading, and there's an NI whitepaper on how to use their threading functions.  The Win32 SDK has quite a bit on multi-threading too.

 

Beveridge & Weiner, ISBN 0-201-44234-5 is a bit dated but still a good reference.

 

Menchar

0 Kudos
Message 11 of 15
(1,272 Views)

The serial comm callbacks as suggested will work for getting the data from the serial port.  Use them to stuff the data into a Thread Safe Queue.  This is a buffer structure available in CVI that can replace your global buffers.  They implement a ring buffer and handle all the thread safe aspects for you.  Your main thread can then use an async timer or whatever method you choose to access the data from the output side of the Thread Safe Queue for processing as needed.  You can implement all of this without the need to handle thread pools at all. 

There is also a Thread Safe Variable which can be used as a type of semaphore or flag if you need to pass additional information between threads that does not easily work with a queue type structure.

0 Kudos
Message 12 of 15
(1,247 Views)

Hi.

 

The thread safe Queue is the way to go.

However the embedded Help shows no hits as to how to write the code base.

So far LabWindows Help leaves little to be desired. What I would like is a Programmers Reference Guide but it seems one does not exist.

I have used the Help alot but most of the time I do not know the correct keywords and usually cannot find the information until I post and a kind soul responds with the correct information.

 

For example your mention of thread safe Queue did not result with any useful information such as:

1. How to set up the thread safe Queues.

2. How to access the treadsafe Queues both in the RxData interrupt (insert items) and the timer routine that processes the data (remove items).

3. Any overhead required with the Queues.

 

This kind of information is what I would expect in a 300-400 page Programmers Reference Guide (there are lots of books for LabView).

Trying to find this type of information in Help is next to impossible.

 

Any ideas where I can find the answers to these questions would be greatly appreciated.

 

 

 

 

0 Kudos
Message 13 of 15
(1,239 Views)
I'm not at a computer with CVI right now, but there are a lot of example programs that will help point you in the right direction.  To find them look under the help menu for something like "find examples"  this will call up a list with various example projects that you can load an look at.  I think there is one for a thread safe queue example probably under a category tagged multithreading.  If anyone can take a quick look on their system and post the location that would be helpful.
0 Kudos
Message 14 of 15
(1,237 Views)

Hi mvr.

 

I found the samples.

 

Again, THANKS very much.

0 Kudos
Message 15 of 15
(1,231 Views)