LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

why visa read reads more bytes than sent

Solved!
Go to solution
Hi, i am using visa read and write to communicate with device via RS232. i have to sent several string commands.i just use basic serial communication to read and write the commands.my total string lengh is about 6626. i also used buffer size of about 7000. when i send all the string to visa write ,i will get a output number(byte) sometimes 6626 and sometimes less than this.Also i used property node for bytes at port which i used bytes number for visa read. But as output number here i get somtimes much more such as about more than 6670 and sometimes less than 6620 and sometimes only 4000and some and 5000 and some.it doesnot remain constant. how can i solve this problem?? why do i get more bytes as output from visa read than i have sent?? and sometimes less than??And sometimes more than visa write output number?? waiting for help.thank you. Tadhika,
0 Kudos
Message 1 of 15
(2,954 Views)

Why do you think the number of bytes written would have anything to do with the number of bytes read?  They are two different directions of communication.  I could send a short command, and the response I read might be a very long message.  I could possible send the device a very long message and the response might be something very short such as "OK".

0 Kudos
Message 2 of 15
(2,945 Views)

I assume you are comparing the size of the sent message to the size received at the other end.

 

Can you show us some code? How are you sending and how are you receiving? How does the receiver know that all data has been received?

0 Kudos
Message 3 of 15
(2,940 Views)

Thank you for your answer.But sometimes why i couldn't write all the bytes that i have sent?Sometimes when i slow the speed(using debug bulb) all the bytes will be read but when i turn off the debug light .it will be again the same.and sometimes it will be written only 1000, 1200 byte however all the byte is sent.

0 Kudos
Message 4 of 15
(2,933 Views)

We cannot help until we see your code.

0 Kudos
Message 5 of 15
(2,929 Views)

ya ,sure,i have done exactly the same way like attached VI below.But i combined more than 90 such commands.i am getting a data also like this example.

0 Kudos
Message 6 of 15
(2,925 Views)

Why are you closing the port inside the while loop?

 

You flush the receive buffer inside the loop.  (Why? Should not be necessary.)  You write out data, could be a fairly long message.  You wait 1/2 second.  Check bytes at port and read that many.  Than close the port.

 

At 9600 baud, you are only transmitting about 1000 bytes per second, so about 500 bytes in 1/2 second.  You close the port before they are all sent, I wouldn't be surprised that you lost bytes.

Message 7 of 15
(2,920 Views)

Thank you! I wanted to close the port outside while loop but i used for loop inside while loop.Because of this for loop i couldn't join them together.It says typ error. but now i joined like this Can i do like this too? I applied baudrate of 115200 and send more than 6000 bytes.Is it enough time to transmit all the bytes??

0 Kudos
Message 8 of 15
(2,909 Views)

You don't need the For Loop at all.  It only runs 1 time, so what is the point of it?

 

If you did need the For Loop, then what you need to do is disable auto-indexing on the tunnels leaving the For Loop.

 

115200 is not enough time to transmits 6000 bytes in 1/2 a second.  It would be about 11,520 bytes in a full second, or about 5700 bytes in 1/2 a second.

 

Your baud rate should be whatever your device needs or works best.  What are you really trying to do here?  Do you have a particular goal for how much data you want to pass in a given period of time?  Is there any special reason your wait time is 500 milliseconds?

 

Get rid of the flush buffer function.  You don't need that either.

0 Kudos
Message 9 of 15
(2,900 Views)

Do you really need to send all of those commands all at once?  Seems like a lot of data to send down the serial port in one go.

 

Ravens Fan is right, you need to increase your wait time.  Get rid of the for loop and the indexing on the outside of the wire loop.  The set buffer size only needs to be performed once.  So move it outside of the while loop right after initialing the port.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 15
(2,892 Views)