Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String object's remove() function is only called once when firstly call of onRecieve() UART Interrupt #10166

Open
1 task done
skyswordx opened this issue Aug 15, 2024 · 1 comment
Assignees

Comments

@skyswordx
Copy link

Board

ESP32wroom

Device Description

Devkit

Hardware Configuration

arduino frame default Serial

Version

latest master (checkout manually)

IDE Name

PlatformIO

Operating System

WSL2

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

115200

Description

In serial communication, within the serial interrupt where the onReceive method is set, the remove() method of the String object inside this interrupt function is only called the first time the interrupt function is triggered (that is, the first time data is received on this serial port).

In this serial communication, the remove method of the String object can only be used once, unless the USB-to-TTL module and the serial port connection are disconnected. However, even after disconnecting and reconnecting, the same issue will occur again.

However, it seems that manually clearing the String object with the clear method after each use may resolve the issue.

Sketch

OnReceiveCb call_back(){
  String receivedData = Serial.readStringUntil('!'); // Read the data until '!' is encountered
  Serial.println(receivedData);// oooo

  receivedData.remove(0,1); // Remove the '#' character from the beginning
  
  Serial.println("removed receivedData first item: #");// oooo
  Serial.println(receivedData);  // oooo
  // receivedData.clear(); // oooo

}

Debug Message

uart messages are below:
------------------------
#P0=500.000
removed receivedData first item: #
#P0=500.000

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.
@skyswordx skyswordx added the Status: Awaiting triage Issue is waiting for triage label Aug 15, 2024
@me-no-dev
Copy link
Member

Here are my results:

void setup() {
  Serial.begin(115200);
  delay(2000);

  String receivedData = "#P0=500.000";
  Serial.println(receivedData);
  receivedData.remove(0,1);
  Serial.println("removed receivedData first item: #");
  Serial.println(receivedData);

}

void loop() {
  // put your main code here, to run repeatedly:
}

Output:

#P0=500.000
removed receivedData first item: #
P0=500.000

I'm guessing that the string starts with invisible char, like \r and that is what you are actually removing, so # stays as second char.

@SuGlider SuGlider added Chip: ESP32-S2 Issue is related to support of ESP32-S2 Chip Peripheral: UART and removed Status: Awaiting triage Issue is waiting for triage labels Aug 15, 2024
@SuGlider SuGlider self-assigned this Aug 15, 2024
@SuGlider SuGlider added this to the 3.0.5 milestone Aug 15, 2024
@SuGlider SuGlider removed the Chip: ESP32-S2 Issue is related to support of ESP32-S2 Chip label Aug 15, 2024
@SuGlider SuGlider removed this from the 3.0.5 milestone Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

3 participants