10-25-2010 10:13 AM
Hi
I have a number of bluetooth virtual serial ports that stream data very quickly as soon as you open them with the VISA configure port. I configure/open these ports one after another and it takes a considerable amount of time (2 mins), i think it is because they are bluetooth virtual com ports. However, as soon as one port is open, the data streams in and fills the buffer (ultimately crashing the program) while I am opening the other ports. I was invisioning something similar to a microprocessor based interrupt to clear the buffer whenver it exceeds 2000 bytes at port, my friend told me about event structures being similar to interrrupts. So, ideally I would like to create a custom user event, defined by the property node (bytes at port) of a VISA com port when it exceeds 2000 bytes. I would just want to run code that would clear the buffer whenever the even occurs. Seems like a simple idea, I looked everywhere and could not find what I wanted to do. Any help would be appreciated
Thanks,
Chris
Solved! Go to Solution.
10-25-2010 11:50 AM
Probably a long shot, but:
Instead of configuring/opening the ports one-after-another, could you put the routines into separate loops and threads... and then execute them independantly? That way your application could immediately begin processing/empyting the buffers after the ports are opened.
10-25-2010 12:35 PM
Thanks for the ideas, but that would require a compete architectural revamp of the code, which im not sure we could get the functionality we need. I would think it would be possible to trigger an event off a boolen condition.
10-25-2010 01:12 PM
Hmmm. I think you could probably implement something similar to my first solution quite quickly, with very little changes to your underlying architecture. You could implement it like this:
Simply spawn a small "buffer monitor" VI that runs in parallel while you open all your COM ports. Let it run while you open all the serial ports. Have it poll the size of your serial buffers, and if the buffers get too big, just clear them. Then stop the VI when all the ports are open and ready to go. That would not require much changes to your underlying code. You'd just need to open and run the VI in parallel using VI Server. And then the VI could even shut itself down once it detected that all the ports were opened.
However, if you want to use events, see here:
http://zone.ni.com/reference/en-XX/help/371361G-01/lvinstio/visa_events/
And here:
http://zone.ni.com/reference/en-XX/help/371361G-01/glang/event_structure/
10-25-2010 01:19 PM
Will it truly run in parallel? If one loop is off in a subvi wiating for a response from the com ports will the other loop be running?
10-25-2010 01:56 PM
Its tricky, but I think it would work.
LV allows multithreading, so you can certainly run VIs in parallel that are totally independant of each other. But the challenge is that your code can not access the same COM port simultaneously. But the way you described the problem, that could be worked around. I think your "COMPortMonitor" could sit and wait for each port to open before monitoring them... while your main loop continues onward to open the next COM port.
Here's how the flow would look:
MAIN VI PORTMONITOR.VI
0 Begin execution of this loop
1 Launch separate PORTMONITOR.VI
2 Open COM1 Begin execution of this loop
3 Tell PORTMONITOR that COM1 is open
4 Begin monitoring COM1
5 Open COM2 Empty COM1 buffer when it gets big
7 Tell PORTMONITOR that COM2 is open
8 Begin monitoring COM2
9 Empty COM1 & COM2 when they get big
10 Shutdown this loop when last COM is open
11 Continue...
In Step 5, your parallel loop will be working with COM1 ... while your main loop is busy opening COM2. In theory, I would expect them to run independantly. And you could try put them in separate threads, too. This links talks about parallel serial loops:
Btw: I think you need to make sure your VISA calls are asynchronous for this to work (right-click on them).
10-25-2010 01:57 PM
I guess you've thought of this, but:
Could you just increase the size of your serial port buffer? Make it so big that it doesn't fill up while opening subsequent ports?