LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

viRead Delay

I'm using LabWindows/CVI 8.1

 

My application is a simple serial communication to a circuit.

Previously, the serial application used Windows 32 serial communication (w32sc), which worked well.

 

Old Code Sample: 
    status = w32sc_open(comm, baud); // open the desired comm at the selected baud
    status = w32sc_setparity(parity);

.

.

.

   out_buf[0] = 0x19;

   bytes_sent = w32sc_write(&out_buf[0], 1);  // send the address
   bytes_read = w32sc_read(&echo_buf[0], 1);

 

The byte is sent and the circuit responds within 3 msecs. More data is sent after that.

 

Now the application requires Visa for the serial communications:

 

New Code Sample:

 

  // create a VISA session to the serial port and return a handle to it
  int  init_comm(long baud, int parity)

  {

   status = viOpen (defaultRM, (ViRsrc)Ports[comport-1], VI_NULL, VI_NULL, &serialHandle);
   status = viSetAttribute (serialHandle, VI_ATTR_ASRL_PARITY,    (ViUInt16)parity); // Parity is Mark
   status = viSetAttribute (serialHandle, VI_ATTR_ASRL_DATA_BITS, 8);
   status = viSetAttribute (serialHandle, VI_ATTR_ASRL_BAUD,      (ViUInt32)baud);  // Baud is 4800
   status = viSetAttribute (serialHandle, VI_ATTR_ASRL_STOP_BITS, VI_ASRL_STOP_ONE);
   status = viSetAttribute (serialHandle, VI_ATTR_ASRL_FLOW_CNTRL,VI_ASRL_FLOW_NONE);
   status = viSetAttribute (serialHandle, VI_ATTR_ASRL_END_IN,    VI_ASRL_END_NONE);

   status = viSetAttribute(serialHandle, VI_ATTR_TMO_VALUE, 5000);  

 }

 

 sts = viOpenDefaultRM (&defaultRM);
 sts = init_comm(4800, VI_ASRL_PAR_MARK);

.

.

.

 out_buf[0] = 0x19;

 vistatus = viWrite (serialHandle, &out_buf[0], 1, &bytes_sent); // send the address 
 vistatus = viRead (serialHandle, &echo_buf[0], 1, &bytes_read); 

 

After the byte is written it now takes over 12 msecs for the byte to be read in viRead, causing a timeout on the cricuit that the data is being sent to.

 

Why is there such a bigger delay reading the byte that was written compared to the old way? A difference of 9msecs.

 

Hope this is enough information.

 

Thanks!

John W.

 


 

 

0 Kudos
Message 1 of 7
(3,483 Views)

Hello John,

NI-VISA is an API that is much more complex then the w32sc. It allows us to communicate with any instrument over any bus, and move code from one bus or platform to another without making many changes. I am pretty sure this additional delay you are experiencing is related to the additional complexity of the VISA API and perhaps additional function calls that haven't been as optimized for serial communication as the serial specific Windows API.

For more details, I would need to talk to R&D. What version of NI-VISA are you using?

Jacob R. | Applications Engineer | National Instruments

0 Kudos
Message 2 of 7
(3,468 Views)

Thanks for the reply.

The visa version is 4.1

If the Visa doesn't work out, can you recommend a different serial comm. for me to use?

 

Thanks!

JW

 

0 Kudos
Message 3 of 7
(3,463 Views)

Have you already tried using CVI standard RS232 library?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 7
(3,458 Views)

That's probably what I am going to have to do.

 

Thanks
JW

 

0 Kudos
Message 5 of 7
(3,450 Views)

I quickly implemented a simple RS232 interface usin the CVI standard rs232 library.

 

Here is the problem I am now having.

 

We use the parity bit to distinguish between an Address and Data. We use "Mark Parity" for Address and "Space Parity" for Data

 

Ist setup the comm port using Mark Prity to send the address:

sts = OpenComConfig(1, "COM1", 4800, 3, 8, 1, 10, 10);

 

Write the Address:

 result = ComWrt (1, &out_buf[0], 1);

 

Then change to Data using Space Parity:

sts = OpenComConfig(1, "COM1", 4800, 4, 8, 1, 10, 10);

 

Write the data:

result = ComWrt (1, &out_buf[1], 2);

 

The problem is that it is taking a long time, about 30msecs to close and open the comm port to change the parity bit.

 

Is there a way to change the parity bit without closing and re-opening the comm port?

 

Thanks!
John W.

 

 

 

 

 

0 Kudos
Message 6 of 7
(3,427 Views)

Hello John,

Looking at the given RS-232 functionality the only way to change the Parity in the connection would be closing and reopening.

Daniel

0 Kudos
Message 7 of 7
(3,410 Views)