Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Serial comms: Delay between Read & Write

Hi,
I am experiencing trouble with my LabVIEW app running in winXP. My app needs to receive a character/command from a polling device and reply with a character string. The polling device will send out a character/command every 100ms.

My problem is that the app cannot reply quick enough. The string sent by my app overlaps the next character/command from the device, because of the delay is about 34ms.

I am trying to replace an older, less friendly VC++ app, which does the exact same thing when run on XP. (There is a 34ms delay.) But when running on Win98 the delay is about 2ms. ??? I think it has to do with API calls. Transition between Read and Write commands.

Is there a way to reduce this delay? It is impor
tant. My other option is to put a faster comms interface between the device and my LabVIEW app.

Any help would be appreciated.
Jerry.
Message 1 of 16
(9,012 Views)
Hey Tarun,

I am assuming that you are using NI-VISA, since you are using LabVIEW. If that is the case, I would recommend you upgrade to the latest version first (NI-VISA 3.2 currently). We have made some changes to increase the speed of the serial communication. The next thing you might want to try is to change the VISA Read and Writes to synchronous, instead of asynchronous. Refer to the link below for more information.

http://digital.ni.com/public.nsf/websearch/ECCAC3C8B9A2A31186256F0B005EEEF7?OpenDocument

-Josh
Message 2 of 16
(9,004 Views)
Hi,

I had solved this problem by using a Win98 pc with LabVIEW 6i, which did the quick comms loop for me.
It was updated serially by my WinXP pc every 5 secs, or every time I forced update.

Now I always thought that it was the OS, WinXP. And I also confirmed my suspicion when I recently ran my apps on Linux.

Now, I have a PXI controller 8156B with Real-Time, I still have this delay when the application is deployed on the PXI target.

Anybody knows what is the problem?

I have a feeling its a setting. I fiddled with FIFO settings on com ports, but no difference was noticed.
Its such a simple application. I can't believe that there is a problem at 1200 baud?

Any help would be appreciated.
Thanks.
Message 3 of 16
(8,820 Views)
Hi Tarun,

You said that the Windows 98 PC was running LabVIEW 6i. What version of LabVIEW are you running on the Windows XP machines? The VI you posted apeared to be saved as a LabVIEW 7.1 version. I'm also curious to know if you are using the same version of VISA on all machines?

Thanks,
Message 4 of 16
(8,797 Views)
Thanks for the quick response.

These are the setups I've used so far.

Setup 1 Slow:
(PC P4 2.4GHz - LabVIEW 7.1)
Win XP machine - Visa 3.2

Setup 2 Slow:
(PC P4 2.4GHz - LabVIEW 7.1)
Win XP machine - Visa 3.2
RT PXI NI-8156B - NI Serial V2.5.4

Setup 3 Fastest:
(PC P4 2.4GHz - LabVIEW 7.1)
Linux - Visa 3.1

Setup 3 Fast:
(PC P2 400MHz - LabVIEW 6i)
Win 98 - traditional serial (CD doesn't have VISA, but Serial sub-dir ??)
Message 5 of 16
(8,798 Views)
Hi there,

I've stumbled across something. I'm not sure if its my code or the driver .. ?

I have a DIO card on my pc.
I was trying to make a output a toggle signal on one of the lines on it every time the write executes.
I was hoping to prove that the delay is being caused in hardware or OS and not my code.

All of a sudden, there is no delay anymore!! Anybody no why?
Message 6 of 16
(8,775 Views)
Tarun,

using a serial port or a DIO card are two totally different things. You can not expect to see a similar behaviour (except that both devices can be written to and read from). The DIO card is controlled via a NI-DAQ or DAQmx driver and basically all actions are deterministic. I mean, when you read or write a value, this one will be acquired or send from/to the apropriate port directly and immediately by the driver.
Serial comm is per se asynchronous; it relies on some OS drivers and the comm partner (your device). NI-VISA acts as the driver, but relies on the OS system driver. Which one is the cause of the delay is hard to say. You might try using NI-Spy when trying to do serial comm. Maybe this one can help you determining where the delay comes from.

Greetings from Germany!
--
UweGreetings from Germany!
--
Uwe
0 Kudos
Message 7 of 16
(8,771 Views)
Hi Lul,

Just restarted my pc and the delay has come back. 😞

The DIO toggle output follows the beginning of the serial write output, i.e. both the DIO card and the serial write are delayed.

I have LabVIEW RT running on a PXI controller, using the same code on this, I get the same delay.

I ran NI-SPY (for the first time - great tool), according to that, from the receive byte event to the write done event is about 18ms. According to the hardware signals I see, its more like 50ms.

The OS is delaying it by 35ms?? Well, I can live with that for the XP machine, but not for the PXI-RT. The common thing is the code, i.e VISA drivers used to access com ports.

I think I'm gonna go nuts with this problem... 🙂

Message Edited by Tarun on 06-10-2005 08:15 AM

Message 8 of 16
(8,771 Views)
Hi Tarun,

You can try running the LabVIEW 6i VI from the Windows 98 machine on the Windows XP machine. Be sure to copy the Serial library file over to the Windows XP machine. The .llb file can be found at:

C:\Program Files\National Instruments\LabVIEW 6.0\vi.lib\instr\serial.llb

Just copy this to "C:\Program Files\National Instruments\LabVIEW 7.1\vi.lib\instr\", and you should have access to the Serial VIs.

Also, VISA has it's own buffer that lies between the serial port FIFO and LabVIEW. Try decreasing the buffer size from it's default value. The VI for this can be found in the functions palette at:

All Functions » Instrument I/O » VISA » VISA Advanced » Interface Specific » VISA Set I/O Buffer Size.vi

Regards,
Message 9 of 16
(8,759 Views)
The delay you are seeing during a write operation is probably caused when NI-VISA is telling the port to flush. Different drivers/operating systems implement this differently. To work around this and increase the speed of the VISA Write command, call VISA Set I/O Buffer Size directly after the VISA Open for the COM port. You will need to set the mask to 32 or 48 depending on whether you want to also set the receive buffer. I would suggest setting the size to something like 4k or the maximum data length that you will ever use with a VISA Write, if this is a known amount. If the buffer size is set NI-VISA will not call the flush command and this should speed up your application on other targets like RT.

-Josh
Message 10 of 16
(8,737 Views)