Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MM Serial port buffer size
Author | Message | ||||
AndrewB Newbie Joined: 04/12/2011 Location: AustraliaPosts: 15 |
Hi, Quick question - when setting up MM serial ports 1 or 2, the buffer size can be set to a number whose limits I've not really tried, but have set to 4096 with no error message. However, on reading, it seems possible to read only up to 255 characters at a time, so if more characters are in the buffer, you have to do repeat reads until the buffer is empty. Is this correct, or am I missing something? Example Code 1: open "com1:4800, 4096" as #1 print input$(255, #1) In this case, screen output is first 255 characters in the com1 input buffer Example Code 2: open "com1:4800, 4096" as #1 print input$(256, #1) In this case, screen output is 'error: number out of bounds' |
||||
Olimex Senior Member Joined: 02/10/2011 Location: BulgariaPosts: 226 |
COM port buffers are 128 bytes long last time I check the sources INPUT$ returns string, strings in MM-BASIC are 0..255 bytes long this is why you get error when you want to read bigger string you can use LOC(#1) function which returns how many bytes are read in the buffer before you use INPUT$ |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6097 |
From the Help file, The default buffer size is 256 bytes for Tx and Rx One example has a buffer of 1024 bytes. I don't remember seeing the maximum size anywhere. As already stated, the string size limit of 255 bytes was causing your error. Using a big com port buffer size is likely to use up ram which might be needed elsewhere in your program. Jim VK7JH MMedit MMBasic Help |
||||
AndrewB Newbie Joined: 04/12/2011 Location: AustraliaPosts: 15 |
Thanks guys. It's a long time since I've programmed in Basic, and I had read many times 'Implementation Characteristics' paragraph in the MMBasic User Manual, but each time the maximum string length of 255 failed to sink in. Yes, a long buffer length would be wasteful and in most cases be unnecessary, but I was just checking since I hadn't actually found a limit. Thanks again. |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
TassyJim is correct. The default buffer size is 256 bytes for both Tx and Rx. And, yes, if it is bigger than 255 bytes you will have to read it in a number of hunks. A bigger buffer is handy if your program occasionally becomes busy (writing to a LCD for example) and cannot regularly check the serial port for data, The only limit to the buffer size is the amount of free memory in the string and array section (where the buffer is allocated). For example, if you used: open "com1:4800, 4096" as #1 The memory command will report that an extra 8K of array and string memory was used. Incidentally, this part of memory will be renamed to "General Memory" in the next version because it is increasingly being used for more than just arrays and strings. Geoff Geoff Graham - http://geoffg.net |
||||
swoodgate Newbie Joined: 24/11/2011 Location: AustraliaPosts: 14 |
Hey Geoff "... bigger than 255 bytes you will have to read it in a number of hunks." That's some good looking data you've got there! Also wanted to say thanks for the Maximite, haven't had this much fun for ages, teaching programming concepts to my kids is so easy when you can show examples instantly on the screen. Best regards Steve |
||||
Print this page |