Berry 'serial.read()' read only 'n' bytes (#22835)

This commit is contained in:
s-hadinger 2025-01-17 22:26:46 +01:00 committed by GitHub
parent a49e924b53
commit a7ee6054b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View File

@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- Command `FileLog 10..14` to enable logging to filesystem using up to 16 log files of 100kB (`#define FILE_LOG_SIZE 100`)
- I2S Opus stream and file support for opus/aac (#22795)
- I2S command I2sLoop (#22807)
- Berry `serial.read()` read only `n` bytes
### Breaking Changed

View File

@ -143,10 +143,18 @@ extern "C" {
int32_t b_serial_read(struct bvm *vm) {
be_getmember(vm, 1, ".p");
TasmotaSerial * ser = (TasmotaSerial *) be_tocomptr(vm, -1);
int32_t max_lex = -1; // -1 means unlimited
int32_t argc = be_top(vm); // Get the number of arguments
if (argc >= 2 && be_isint(vm, 2)) {
max_lex = be_toint(vm, 2);
}
if (ser) {
int32_t len = ser->available();
if (len < 0) { len = 0; }
if (len > 0) {
if (max_lex >= 0 && len > max_lex) {
len = max_lex;
}
// read bytes on stack
char * rx_buf = new char[len];
len = ser->read(rx_buf, len);