serial port read - returns before finished?

O

Ole

I got a problem with serial port read which I use like this:

sp.Read (byteBuffer, 0, 100);

but the problem is that it returns before it has read the 100 bytes - is
there a way to set up the port in a syncronious state so that it wont return
before it has finished? And no - I can't use the work around to smaple until
I got all 100 bytes read because I use the timeout option in my app.

Thanks
Ole
 
N

Nicholas Paldino [.NET/C# MVP]

Ole,

Why not use the workaround? You can perform the read, and keep track of
how much time has elapsed. Then, on the next read, you could decrement the
amount of time that you are willing to wait by the next amount of time left.

So, for example, if your timeout is initially 10 seconds, and you are
reading 100 bytes, then what you need to do is store the time before you
start the read.

If the first read returns 10 bytes, and it takes 2 seconds, then you
issue the second read for 90 bytes, and set the timeout to 8 seconds.

Hope this helps.
 
O

Ole

Thanks - but it won't work in my application - trust me (it's to complicated
to explain why). If syncronious mode aren't possible can anybody explain why
on earth it is possible to set the sp.ReadTimeOut parameter and what it is
used for????

Thanks
Ole


Nicholas Paldino said:
Ole,

Why not use the workaround? You can perform the read, and keep track
of how much time has elapsed. Then, on the next read, you could decrement
the amount of time that you are willing to wait by the next amount of time
left.

So, for example, if your timeout is initially 10 seconds, and you are
reading 100 bytes, then what you need to do is store the time before you
start the read.

If the first read returns 10 bytes, and it takes 2 seconds, then you
issue the second read for 90 bytes, and set the timeout to 8 seconds.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ole said:
I got a problem with serial port read which I use like this:

sp.Read (byteBuffer, 0, 100);

but the problem is that it returns before it has read the 100 bytes - is
there a way to set up the port in a syncronious state so that it wont
return before it has finished? And no - I can't use the work around to
smaple until I got all 100 bytes read because I use the timeout option in
my app.

Thanks
Ole
 
N

Nicholas Paldino [.NET/C# MVP]

Why not try us on the "too complicated part". You might be surprized.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ole said:
Thanks - but it won't work in my application - trust me (it's to
complicated to explain why). If syncronious mode aren't possible can
anybody explain why on earth it is possible to set the sp.ReadTimeOut
parameter and what it is used for????

Thanks
Ole


Nicholas Paldino said:
Ole,

Why not use the workaround? You can perform the read, and keep track
of how much time has elapsed. Then, on the next read, you could
decrement the amount of time that you are willing to wait by the next
amount of time left.

So, for example, if your timeout is initially 10 seconds, and you are
reading 100 bytes, then what you need to do is store the time before you
start the read.

If the first read returns 10 bytes, and it takes 2 seconds, then you
issue the second read for 90 bytes, and set the timeout to 8 seconds.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Ole said:
I got a problem with serial port read which I use like this:

sp.Read (byteBuffer, 0, 100);

but the problem is that it returns before it has read the 100 bytes - is
there a way to set up the port in a syncronious state so that it wont
return before it has finished? And no - I can't use the work around to
smaple until I got all 100 bytes read because I use the timeout option
in my app.

Thanks
Ole
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top