BBC BASIC for Windows
« Serial port buffer »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:13pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Serial port buffer  (Read 1105 times)
manxman
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 21
xx Serial port buffer
« Thread started on: Dec 11th, 2012, 12:30pm »

Is it possible to increase the size of the Windows serial port buffer? I have a program that receives and plots data arriving at 20Hz from the port. The reason I ask is that my program sometimes leaves the graphics task to carry out another time-consuming operation that might result in the buffer overflowing. Since there is no handshaking with the external instrument, this can result in data being lost. Extending the buffer would solve this problem.

Regards,

Manxman undecided
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Serial port buffer
« Reply #1 on: Dec 11th, 2012, 4:09pm »

on Dec 11th, 2012, 12:30pm, manxman wrote:
my program sometimes leaves the graphics task to carry out another time-consuming operation that might result in the buffer overflowing.

Have you actually observed such an overflow, or is it a theoretical concern? The default buffer size is quite large (4 Kbytes I think) so you would have to leave the input 'unserviced' for quite a long time for it to overflow.

If it really does overflow, the solution is surely to service the serial port more frequently (perhaps in a timer interrupt) rather than to try to increase the buffer size.

Richard.
User IP Logged

manxman
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 21
xx Re: Serial port buffer
« Reply #2 on: Dec 12th, 2012, 09:15am »

Yes, I do sometimes observe an overflow when the program is made to depart for several minutes from servicing the serial buffer. I would have to restructure my program so that serial data processing (and associated graphics and filing) is put inside the other task - something I am not keen to do. For me the ideal thing would be to enlarge the buffer, if this is possible. Any hints are most welcome!

Regards,

Manxman
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Serial port buffer
« Reply #3 on: Dec 12th, 2012, 2:54pm »

on Dec 12th, 2012, 09:15am, manxman wrote:
Yes, I do sometimes observe an overflow when the program is made to depart for several minutes from servicing the serial buffer.

Several minutes?! You really need to consider restructuring your code - why can't you carry out the serial-port servicing in a timer interrupt? That ought to allow you to avoid overflows without making any changes to the time-consuming 'graphics and filing' code.

Quote:
For me the ideal thing would be to enlarge the buffer, if this is possible.

The trouble is, you can't guarantee to be able to increase the buffer size. All Windows allows you to specify is a recommended buffer size: the OS may, or it may not, increase its size to the value you have requested.

The relevant phrase in MSDN is "The device driver receives the recommended buffer sizes, but is free to use any input and output (I/O) buffering scheme, as long as it provides reasonable performance and data is not lost due to overrun (except under extreme circumstances)". Not servicing the serial port for several minutes is without doubt an 'extreme circumstance', so all bets are off:

http://msdn.microsoft.com/en-us/library/windows/desktop/aa363439.aspx

If your program only ever needs to run on a specific machine or machines, and you can establish that on those machines - with their particular software and hardware configurations - you can increase the buffer size enough to solve your problem, then go ahead and do it that way. But I would urge you to consider making your program less dependent on such factors.

Richard.
User IP Logged

manxman
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 21
xx Re: Serial port buffer
« Reply #4 on: Dec 12th, 2012, 8:31pm »

Hmmm.

My program will only ever be running on a specific machine which is acting mainly as a data logger. I had never considered the use of a timer interrupt (and have no experience of such). From the link you give I could presumably increase the buffer size by including the statement:

_In_ A% dwInQueue

in my code, where A% is the desired size of the input buffer.

Regards,

Manxman
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: Serial port buffer
« Reply #5 on: Dec 12th, 2012, 9:34pm »

on Dec 12th, 2012, 8:31pm, manxman wrote:
From the link you give I could presumably increase the buffer size

Yes, the SetupComm API function is the way to try to increase it. The MSDN description doesn't make clear whether a 'success' return from the function (i.e. a non-zero value) means that the requested buffer size was accepted, but if in doubt you can always call the GetCommProperties API which returns the current buffer size in the dwCurrentRxQueue member. If I try to double the buffer size from the default 4096 bytes to 8192 bytes, here it succeeds:

Code:
      SYS "SetupComm", @hfile%(channel%), 8192, 0 

Richard.
User IP Logged

manxman
Developer

member is offline

Avatar




PM

Gender: Male
Posts: 21
xx Re: Serial port buffer
« Reply #6 on: Dec 13th, 2012, 4:43pm »

laugh Wunderbar.

I will include that call in my program and hopefully that will provide my solution.

Thanks again for your professional support.

Manxman
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls