LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Labview port com problem

Hi,

I have a problem with a serial instrument and Labview 7.0. I’m using a device (om3 keyboard) that appears as a Prolific 2 USB to Serial Bridge on the device manager (port COM 4).

I use two different methods to read and write. In order to read data, I use VISA READ vi.
To write data, I call a dll. I didn’t succeed in writing data from the pc to the device using VISA WRITE as I don’t know what to write.
The problem is that I can’t use both functions at the same time.
When I run the reading function, I can then run the writing function. However, once I have run the writing function I can’t open the visa session anymore. I have the error number BFFF0072 (VI_ERROR_RSRC_BUSY). The only way to be able to read is to close entirely Labview.
In the writing function, I’m doing the following step :
- power on device.
- init device.
- send commands.
- power off device.
Is there a way to close the port at the end of the writing function without closing Labview? I thought that when I was powered off the device, the port will be free but it is not the case as I can’t open the visa session. It seems that the port is discharged only when the software is close.

I have also the protocol communication of my device but I don’t know how to use it in order to get back data from the device in Labview. (see attached file).

Thank you,

Cecile
0 Kudos
Message 1 of 9
(3,096 Views)

There is a visa close right next to the visa read function in the serial pallet

Message Edited by James R on 04-03-2007 08:41 AM

- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 2 of 9
(3,084 Views)
If the problem occcurs after using the dll, then VISA is not the problem and doing a close won't help. It sounds like the dll is holding the port open. If that's the case, then the only solution I see is to not use the dll at all, or use the dll to do the read as well as the write. Windows does not allow two different processes to have access to the same port so talk to the vendor about finding out how to use their software to release the port or figure out how to use their protocol with a VISA Write. You didn't attach any file so no one can help with that.

Message Edited by Dennis Knutson on 04-03-2007 07:58 AM

0 Kudos
Message 3 of 9
(3,074 Views)
If you want to read and write in parallel and only close the visa session when your program finishes try to use parallel loops and use queues, or notifiers.  One loop will be the receive and one loop would be the transmit  You communicate between the two loops with a queue or notifier.  look at the producer/consumer , master/slave, or queued message handler design patterns. 
 
you can get to these by clicking file>new...> and select one of these design patterns
- James

Using LV 2012 on Windows 7 64 bit
0 Kudos
Message 4 of 9
(3,072 Views)

First of all, thank you for your replies.

 

I understand that I have two choices : try to write from the pc to the device thanks to visa write.vi or implement the dll. In the first case, it seems to be difficult because I don’t know how to write to the device. I have a protocol but it is not really clear. (see attached file)

I find an example that use the dll in C# so perhaps it will be the easiest way to proceed. The problem is that I’m not sure if Labview can do what I want.

The program proceed like that :

 

      class IOptimusMini

       {

             const string DRIVER="OptimusMini.dll";

 

             public const int SCREEN_SIZE=96;

             public const int SCREEN_BUFFER_SIZE=SCREEN_SIZE*SCREEN_SIZE*3;

 

             public delegate void OnKeyDownCallbackDelegate(int key);

             public delegate void OnDeviceStateChangedCallbackDelegate(int state);

 

             [DllImport(DRIVER)]

public static extern int  RegisterEventHandler(OnKeyDownCallbackDelegate dk, OnDeviceStateChangedCallbackDelegate ds);

       }

 

... 

0 Kudos
Message 5 of 9
(3,051 Views)

...

class UsageExample

       {

             static void OnKeyDownCallbackHandler(int key)

             {

                    Console.Write("Keydown {0}\n", key);

             }

 

             static void OnDeviceStateChangedCallbackHandler(int state)

             {

Console.Write( state > 0 ? "Connected.\n" : "Disconnected.\n");

             }

static void Main( string[] args )

                    {

                    byte[] img = new byte[IOptimusMini.SCREEN_BUFFER_SIZE];

 

/* register callback handlers if you want to process keypresses */

                    IOptimusMini.RegisterEventHandler(

new IOptimusMini.OnKeyDownCallbackDelegate( OnKeyDownCallbackHandler ),

new IOptimusMini.OnDeviceStateChangedCallbackDelegate( OnDeviceStateChangedCallbackHandler )

                    );

       }

 

I have access to the function RegisterEventHandler thanks to my dll but the input parameter are functions (with in addition a delegate class which is not accessible from Labview 7.0).

So I would like to know if it is possible to have a CIN block which has as outputs the functions I need in input of my dll.

Thank you in advance.

0 Kudos
Message 6 of 9
(3,048 Views)
This is the second time you said you attached a file and the second time there was no attachment. Try it again. This time though, do not click the preview post after attaching the file.
0 Kudos
Message 7 of 9
(3,035 Views)
hi C

i understand you are using the Dll to 'write ' to your device by RS 232 .

A suggestion would be to introduce a passive snoozer to monitor the TX line and feed the signal back to RX line on other com port.
Thus you then can break down the structure of your TX string commands to enable you to build the appropiate labview command strings.

I have used this method to identify salient tolkens hided in encrptied CRC16 alogorithem.

xseadog
0 Kudos
Message 8 of 9
(3,029 Views)
I'm sorry but I don't know what is a passive snoozer? Is it a sotfware, an hardware??
0 Kudos
Message 9 of 9
(3,010 Views)