Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

CWSerial Test tab

In the CWSerial control, there is a test tab.
There are three buttons on the tab, execute (writes and then reads) write,
and read
When I issue a command in the test tab, (\00, sends chr 0x00h) and then hit
execute,
the correct byte array is displayed in the box below.

When I execute code
...
CWSerial1.Configure
data = chr$(00)
CWSerial1.write data
inputdata = CWSerial1.read
....

I get error 30304 IO in progress error.

1. Why am i getting this error?
2. Is there example VB code that contains the same sequence as the test tab
on the control?

TIA

Steven Stiller
0 Kudos
Message 1 of 3
(3,913 Views)
Interesting. I could not reproduce this problem as you have it above. The CWSerial control is setup for synchronous and asynchronous operation. You are using synchronous which should mean that your above code should work because the write should finish before getting to the read statement.

I would try asynchronous operation with the events and see if that works. You would call WriteAsync and then get a WriteComplete event. When getting the WriteComplete, you could do a ReadAsync. Then you will get a DataReady event when the read completes. The Test page is most likely using async operation. There is an example under samples\instr\basic serial that shows how to program sync and async operation.

Best Regards,

Chris Matthews
National Instru
ments
0 Kudos
Message 2 of 3
(3,913 Views)
What I think may be happening in your case is that the serial port is using the 'default' number of bytes (1000) as its read buffer size. Unless explicitly set as CWSerial1.Read(CWSerial1.BytesWritten) or something of that nature, if you write fewer bytes than the read-buffer size, then the port will wait until more bytes are written to the serial port. If no more bytes are written (to complete the operation), the program hangs and waits indefinitely. This is why you're getting the "in progress" error, since it is still waiting for you to finish writing when you are requesting a read. If you set a shorter timeout or the number of read bytes to be equal to the bytes written, this error should go away.

For more information on this topic you may want to consult the
Resources Library > Instrument Connectivity > Serial > Serial Communication Starting Point page.

Good Luck.

Elaine R.
Applications Engineer
http://www.ni.com/ask
0 Kudos
Message 3 of 3
(3,913 Views)