06-01-2012 08:24 AM
Solved! Go to Solution.
06-01-2012 09:22 AM
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".
06-01-2012 09:27 AM
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?
06-01-2012 09:42 AM
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.
06-01-2012 09:53 AM
We cannot help until we see your code.
06-01-2012 10:09 AM
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.
06-01-2012 10:18 AM
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.
06-01-2012 11:34 AM
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??
06-01-2012 12:21 PM
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.
06-01-2012 12:40 PM
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.