### AT Command Example (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Provides an example of interacting with devices like modems or WiFi modules using AT commands. It shows sending a command and reading the device's version information. ```gdscript serial.writeline("AT+VERSION?") var version = serial.readline() print("Module version: ", version) ``` -------------------------------- ### Common Use Cases Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Examples demonstrating how to use GdSerial for common tasks like Arduino communication, AT commands, and binary data transfer. ```APIDOC ## Common Use Cases ### Arduino Communication **Synchronous (Simple API):** ```gdscript # Assuming 'serial' is an instance of GdSerial serial.writeline("GET_SENSOR") var reading = serial.readline() print("Sensor value: ", reading) ``` **Asynchronous (Manager API with Line Buffering):** ```gdscript # Assuming 'manager' is an instance of GdSerialManager manager.open("COM3", 9600, 1000, 1) # Mode 1: wait for newline ``` ### AT Commands (Modems, WiFi Modules) **Synchronous (Simple API):** ```gdscript # Assuming 'serial' is an instance of GdSerial serial.writeline("AT+VERSION?") var version = serial.readline() print("Module version: ", version) ``` ### Binary Data Transfer **Synchronous (Simple API):** ```gdscript # Assuming 'serial' is an instance of GdSerial var data = PackedByteArray([0x01, 0x02, 0x03, 0x04]) serial.write(data) var response = serial.read(10) ``` **Asynchronous (Manager API with Raw or Custom Delimiter):** ```gdscript # Assuming 'manager' is an instance of GdSerialManager # Mode 0: Emit all chunks immediately manager.open("COM3", 9600, 1000, 0) # Mode 2: Wait for a custom delimiter byte manager.open("COM3", 9600, 1000, 2) manager.set_delimiter("COM3", 0xFF) # Set 0xFF as the delimiter ``` ``` -------------------------------- ### Arduino Communication Example (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Shows a common use case for serial communication with an Arduino. It demonstrates sending a command and reading a response synchronously, and also how to configure the manager for line-buffered asynchronous communication. ```gdscript # Synchronous (simple, blocking) serial.writeline("GET_SENSOR") var reading = serial.readline() print("Sensor value: ", reading) ``` ```gdscript manager.open("COM3", 9600, 1000, 1) # Mode 1: wait for newline ``` -------------------------------- ### Async Manager Setup and Communication (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Demonstrates setting up the GdSerialManager for non-blocking serial communication. It connects to a specified port, handles data reception, and manages disconnections. This is recommended for maintaining a responsive UI. ```gdscript extends Node var manager: GdSerialManager func _ready(): manager = GdSerialManager.new() manager.data_received.connect(_on_data) manager.port_disconnected.connect(_on_disconnect) # Mode 0: RAW (emit all chunks), 1: LINE_BUFFERED (wait for \n), 2: CUSTOM_DELIMITER if manager.open("COM3", 9600, 1000, 0): print("Connected to COM3") func _process(_delta): # This triggers the signals above manager.poll_events() func _on_data(port: String, data: PackedByteArray): print("Data from ", port, ": ", data.get_string_from_utf8()) func _on_disconnect(port: String): print("Lost connection to ", port) ``` -------------------------------- ### Binary Data Transfer Examples (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Illustrates how to send and receive raw binary data over serial ports. It covers both synchronous `write`/`read` operations and asynchronous communication using `GdSerialManager` with raw or custom delimiter modes. ```gdscript # Synchronous approach var data = PackedByteArray([0x01, 0x02, 0x03, 0x04]) serial.write(data) var response = serial.read(10) ``` ```gdscript manager.open("COM3", 9600, 1000, 0) # Mode 0: emit all chunks immediately ``` ```gdscript # or manager.open("COM3", 9600, 1000, 2) # Mode 2: wait for delimiter byte manager.set_delimiter("COM3", 0xFF) # Set custom end marker ``` -------------------------------- ### Basic Serial Communication in GDScript Source: https://github.com/sujithchristopher/gdserial/blob/main/RELEASE_NOTES.md Demonstrates the fundamental usage of GdSerial for opening a serial port, sending data, receiving a response, and closing the connection. Requires GdSerial to be installed and configured in the Godot project. ```gdscript var serial = GdSerial.new() serial.set_port("COM3") serial.set_baud_rate(9600) if serial.open(): serial.writeline("Hello Arduino!") var response = serial.readline() print("Response: ", response) serial.close() ``` -------------------------------- ### Temporarily Disable Gatekeeper on macOS (Bash) Source: https://github.com/sujithchristopher/gdserial/blob/main/MACOS_SECURITY.md This command temporarily disables macOS Gatekeeper, a security feature that blocks unsigned applications and libraries. While it can resolve installation issues, it is not recommended for general use due to security risks. Remember to re-enable Gatekeeper after testing. ```bash # Temporarily disable Gatekeeper (NOT recommended for security) sudo spctl --master-disable # Re-enable after testing sudo spctl --master-enable ``` -------------------------------- ### Basic Serial Communication in GdSerial (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/addons/gdserial/README.md Demonstrates the basic usage of GdSerial for opening a serial port, writing data, and closing the connection. This requires an instance of GdSerial and setting the port and baud rate before opening. ```gdscript extends Node var serial: GdSerial func _ready(): serial = GdSerial.new() serial.set_port("COM3") serial.set_baud_rate(9600) if serial.open(): serial.writeline("Hello!") serial.close() ``` -------------------------------- ### AT Commands for Modems/WiFi Modules with GdSerial Source: https://context7.com/sujithchristopher/gdserial/llms.txt Shows how to communicate with AT command-based devices like ESP8266 modules. Includes sending AT commands, checking responses, and configuring settings. Uses a longer timeout suitable for AT command interactions. ```gdscript extends Node var serial: GdSerial func _ready() -> void: serial = GdSerial.new() serial.set_port("/dev/ttyUSB0") serial.set_baud_rate(115200) serial.set_timeout(2000) # AT commands may need longer timeout if serial.open(): # Check module is responsive serial.writeline("AT") await get_tree().create_timer(0.1).timeout var response = serial.readline() print("AT Response: ", response) # Output: "OK" # Query firmware version serial.writeline("AT+GMR") await get_tree().create_timer(0.1).timeout print("Version: ", serial.readline()) # Configure WiFi mode serial.writeline("AT+CWMODE=1") # Station mode await get_tree().create_timer(0.1).timeout print("Mode set: ", serial.readline()) serial.close() ``` -------------------------------- ### Error Handling and Troubleshooting Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Guidance on common errors, their causes, and troubleshooting steps, including permission issues and build problems. ```APIDOC ## Error Handling and Troubleshooting ### Common Errors - **Port not found or inaccessible:** Verify device connection, check OS device manager (`dmesg` on Linux), try different ports/cables. - **Permission denied (Linux):** Ensure user is in the `dialout` group. Run `sudo usermod -a -G dialout $USER` and log out/in. - **Device disconnected:** Check physical connection. - **Timeout during read:** Increase timeout value or check device responsiveness. ### Build Issues - **Update Rust:** Run `rustup update`. - **Clear Cache:** Execute `cargo clean`. - **Check Dependencies:** Ensure all required libraries are available. **Note:** Detailed error messages are logged through Godot's console. ``` -------------------------------- ### Multi-Port Async Communication with GdSerialManager Source: https://context7.com/sujithchristopher/gdserial/llms.txt Illustrates managing multiple serial devices concurrently using GdSerialManager. Demonstrates opening ports, connecting to data received and disconnection signals, and polling for events. ```gdscript extends Node var manager: GdSerialManager var arduino_port = "COM3" var gps_port = "COM5" func _ready() -> void: manager = GdSerialManager.new() manager.data_received.connect(_on_data) manager.port_disconnected.connect(_on_disconnect) # Open Arduino in line-buffered mode manager.open(arduino_port, 9600, 1000, 1) # Open GPS module in line-buffered mode (NMEA sentences end with newline) manager.open(gps_port, 9600, 1000, 1) print("Monitoring both ports...") func _process(_delta: float) -> void: manager.poll_events() func _on_data(port: String, data: PackedByteArray) -> void: var text = data.get_string_from_utf8().strip_edges() match port: arduino_port: print("Arduino: ", text) # Handle Arduino sensor data gps_port: if text.begins_with("$GPGGA"): print("GPS Fix: ", text) # Parse NMEA GPGGA sentence for position data func _on_disconnect(port: String) -> void: print("Lost connection to: ", port) # Attempt reconnection after delay await get_tree().create_timer(2.0).timeout manager.open(port, 9600, 1000, 1) ``` -------------------------------- ### GdSerial Basic API - Port Management (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Demonstrates basic port management functions for the GdSerial library in GDScript. This includes listing ports, setting port configurations like baud rate and parity, opening/closing the port, and checking its status. ```gdscript var serial = GdSerial.new() # List available ports var ports = serial.list_ports() print(ports) # Set port and baud rate serial.set_port("/dev/ttyUSB0") serial.set_baud_rate(9600) # Open the port if serial.open(): print("Serial port opened successfully.") # ... perform read/write operations ... serial.close() else: print("Failed to open serial port.") # Check if port is open print("Is port open? ", serial.is_open()) ``` -------------------------------- ### Platform-Specific Notes Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Information regarding serial port naming conventions and necessary permissions on Windows, Linux, and macOS. ```APIDOC ## Platform-Specific Notes ### Windows - **Port Names:** Typically `COM1`, `COM2`, etc. - **Permissions:** Administrator privileges might be required for certain devices. ### Linux - **Port Names:** Typically `/dev/ttyUSB0`, `/dev/ttyACM0`, etc. - **Permissions:** The user must be part of the `dialout` group to access serial ports. ```bash sudo usermod -a -G dialout $USER # Log out and log back in for changes to take effect ``` ### macOS - **Port Names:** Typically `/dev/tty.usbserial-*` or `/dev/tty.usbmodem*`. ``` -------------------------------- ### Read Serial Data: Binary, String, and Line Source: https://context7.com/sujithchristopher/gdserial/llms.txt Demonstrates how to read data from a serial port using `read()`, `read_string()`, and `readline()`. These methods respect the configured timeout. `read()` fetches raw bytes, `read_string()` interprets bytes as UTF-8, and `readline()` reads until a newline character is encountered. Ensure the serial port is opened and configured before use. ```gdscript var serial = GdSerial.new() serial.set_port("/dev/ttyUSB0") serial.set_baud_rate(9600) serial.set_timeout(2000) # 2 second timeout if serial.open(): # Send command to Arduino serial.writeline("GET_TEMPERATURE") # Wait for device to respond await get_tree().create_timer(0.1).timeout # Check if data is available var available = serial.bytes_available() print("Bytes available: ", available) # Output: 12 if available > 0: # Read raw bytes var raw_data: PackedByteArray = serial.read(10) print("Raw bytes: ", raw_data) # Output: [50, 53, 46, 52, 67, 10] # Read as UTF-8 string var text: String = serial.read_string(100) print("Text: ", text) # Output: "25.4C" # Read until newline (most common for Arduino) var line: String = serial.readline() print("Line: ", line) # Output: "Temperature: 25.4C" serial.close() ``` -------------------------------- ### Build GdSerial Library Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Builds the GdSerial library for release. This command compiles the Rust code into a usable plugin for Godot 4. The script varies between Linux/macOS and Windows. ```bash # Linux/Mac ./build_release.sh ``` ```bash # Windows build_release.bat ``` -------------------------------- ### Read Data from Serial Port Source: https://context7.com/sujithchristopher/gdserial/llms.txt Demonstrates how to read binary data, strings, or line-terminated text from a serial port using read(), read_string(), and readline(). Operations respect the configured timeout. ```APIDOC ## read(), read_string(), and readline() ### Description Receive binary data, strings, or line-terminated text from the serial port. Operations respect the configured timeout. ### Method Various (read, read_string, readline) ### Endpoint N/A (Direct method calls on GdSerial instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```gdscript var serial = GdSerial.new() serial.set_port("/dev/ttyUSB0") serial.set_baud_rate(9600) serial.set_timeout(2000) # 2 second timeout if serial.open(): # Send command to Arduino serial.writeline("GET_TEMPERATURE") # Wait for device to respond await get_tree().create_timer(0.1).timeout # Check if data is available var available = serial.bytes_available() print("Bytes available: ", available) if available > 0: # Read raw bytes var raw_data: PackedByteArray = serial.read(10) print("Raw bytes: ", raw_data) # Read as UTF-8 string var text: String = serial.read_string(100) print("Text: ", text) # Read until newline (most common for Arduino) var line: String = serial.readline() print("Line: ", line) serial.close() ``` ### Response #### Success Response (Data Read) - **raw_data** (PackedByteArray) - Raw bytes read from the serial port. - **text** (String) - Data read as a UTF-8 string. - **line** (String) - Data read until a newline character. #### Response Example ```json { "raw_data": "[50, 53, 46, 52, 67, 10]", "text": "25.4C", "line": "Temperature: 25.4C" } ``` ``` -------------------------------- ### Reconfigure Open Serial Port Settings with GdSerialManager Source: https://context7.com/sujithchristopher/gdserial/llms.txt Shows how to dynamically change serial port settings of an already open port using `GdSerialManager.reconfigure_port()`. This avoids the need to close and reopen the port, allowing for runtime adjustments to baud rate, data bits, parity, stop bits, flow control, and timeout. ```gdscript var manager = GdSerialManager.new() manager.open("COM3", 9600, 1000, 0) # Later, change settings without closing the port var success = manager.reconfigure_port( "COM3", # port_name 115200, # baud_rate (upgrade speed) 8, # data_bits 0, # parity (0: None, 1: Odd, 2: Even) 1, # stop_bits 0, # flow_control (0: None, 1: Software, 2: Hardware) 500 # timeout_ms (reduce timeout) ) if success: print("Port reconfigured successfully") else: print("Failed to reconfigure port") ``` -------------------------------- ### Arduino Bidirectional Communication with GdSerial Source: https://context7.com/sujithchristopher/gdserial/llms.txt Demonstrates sending a command to an Arduino and receiving sensor data. Requires the GdSerial library and a compatible Arduino sketch. Handles opening, reading, and closing the serial port. ```gdscript extends Node var serial: GdSerial func _ready() -> void: serial = GdSerial.new() serial.set_port("COM3") serial.set_baud_rate(9600) if serial.open(): # Request sensor reading serial.writeline("GET_SENSOR") # Wait for Arduino to process and respond await get_tree().create_timer(0.1).timeout if serial.bytes_available() > 0: var reading = serial.readline() print("Sensor value: ", reading) # Output: "Sensor value: 512" serial.close() # Arduino sketch (for reference): # void setup() { # Serial.begin(9600); # } # void loop() { # if (Serial.available()) { # String cmd = Serial.readStringUntil('\n'); # if (cmd == "GET_SENSOR") { # int value = analogRead(A0); # Serial.println(value); # } # } # } ``` -------------------------------- ### Clone GdSerial Repository Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Clones the GdSerial repository from GitHub and navigates into the project directory. This is the first step for building the library from source. ```bash git clone https://github.com/SujithChristopher/gdserial.git cd gdserial ``` -------------------------------- ### GdSerialManager.open() - Buffering Modes Source: https://context7.com/sujithchristopher/gdserial/llms.txt Configure the GdSerialManager.open() method with different buffering modes (RAW, LINE_BUFFERED, CUSTOM_DELIMITER) to suit various data protocols. ```APIDOC ## open() with Buffering Modes ### Description The `GdSerialManager.open()` method supports three buffering modes for different data protocols: RAW (mode 0), LINE_BUFFERED (mode 1), and CUSTOM_DELIMITER (mode 2). ### Method `GdSerialManager.open(port_name: String, baud_rate: int, timeout_ms: int, mode: int = 0)` ### Endpoint N/A (Direct method calls on GdSerialManager instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```gdscript var manager = GdSerialManager.new() manager.data_received.connect(_on_data) # Mode 0: RAW - emits all data chunks immediately (best for binary protocols) manager.open("COM3", 9600, 1000, 0) # Mode 1: LINE_BUFFERED - waits for newline character before emitting # Ideal for Arduino Serial.println() output manager.open("COM4", 115200, 1000, 1) # Mode 2: CUSTOM_DELIMITER - waits for custom byte before emitting manager.open("COM5", 9600, 1000, 2) manager.set_delimiter("COM5", 0xFF) # Custom end marker byte func _on_data(port: String, data: PackedByteArray) -> void: match port: "COM3": # Handle raw binary data print("Raw bytes: ", data) "COM4": # Handle line-buffered text print("Line: ", data.get_string_from_utf8()) "COM5": # Handle custom-delimited packets print("Packet: ", data) ``` ### Response #### Success Response (Port Opened) - **Port Status** (Boolean) - True if the port was opened successfully, false otherwise. #### Response Example (No direct response body, success indicated by return value and subsequent data reception signals) ```json { "port_status": true } ``` ``` -------------------------------- ### GdSerial Class - Basic Synchronous API for Serial Communication in Godot 4 Source: https://context7.com/sujithchristopher/gdserial/llms.txt Demonstrates the basic synchronous API of the `GdSerial` class for controlling a single serial port in Godot 4. It covers port configuration, opening/closing the port, writing string and line data, and reading responses. This class is suitable for straightforward communication scenarios where blocking operations are acceptable. ```gdscript extends Node # Configuration constants const PARITY_NONE = 0 const PARITY_ODD = 1 const PARITY_EVEN = 2 const STOP_BITS_ONE = 1 const STOP_BITS_TWO = 2 const FLOW_CONTROL_NONE = 0 const FLOW_CONTROL_SOFTWARE = 1 const FLOW_CONTROL_HARDWARE = 2 var serial: GdSerial func _ready() -> void: serial = GdSerial.new() # List all available COM ports with detailed info print("Available COM ports:") var ports: Dictionary = serial.list_ports() for i: int in ports: var port_info: Dictionary = ports[i] print("Port: ", port_info["port_name"], " (", port_info["device_name"], ") - Type: ", port_info["port_type"]) # Output: Port: COM3 (Arduino Uno) - Type: USB - VID: 2341, PID: 0043 # Configure serial port settings serial.set_port("COM3") # Windows: COM3, Linux: /dev/ttyUSB0, macOS: /dev/tty.usbserial-* serial.set_baud_rate(9600) serial.set_data_bits(8) serial.set_parity(PARITY_NONE) serial.set_stop_bits(STOP_BITS_ONE) serial.set_flow_control(FLOW_CONTROL_NONE) serial.set_timeout(1000) # 1 second timeout # Open the port if serial.open(): print("Serial port opened successfully!") # Write string data serial.write_string("Hello Arduino!") # Write line with newline character appended serial.writeline("AT+VERSION?") # Wait for response await get_tree().create_timer(0.2).timeout if serial.bytes_available() > 0: var response := serial.read_string(100) print("Received: ", response) # Close the port when done serial.close() else: print("Failed to open serial port") ``` -------------------------------- ### GdSerialManager: Open Port with Buffering Modes Source: https://context7.com/sujithchristopher/gdserial/llms.txt Illustrates opening serial ports with different buffering modes using `GdSerialManager.open()`. Mode 0 (RAW) emits data immediately. Mode 1 (LINE_BUFFERED) waits for a newline character. Mode 2 (CUSTOM_DELIMITER) waits for a specified byte sequence. The `set_delimiter()` method is used for custom delimiter mode. ```gdscript var manager = GdSerialManager.new() manager.data_received.connect(_on_data) # Mode 0: RAW - emits all data chunks immediately (best for binary protocols) manager.open("COM3", 9600, 1000, 0) # Mode 1: LINE_BUFFERED - waits for newline character before emitting # Ideal for Arduino Serial.println() output manager.open("COM4", 115200, 1000, 1) # Mode 2: CUSTOM_DELIMITER - waits for custom byte before emitting manager.open("COM5", 9600, 1000, 2) manager.set_delimiter("COM5", 0xFF) # Custom end marker byte func _on_data(port: String, data: PackedByteArray) -> void: match port: "COM3": # Handle raw binary data print("Raw bytes: ", data) "COM4": # Handle line-buffered text print("Line: ", data.get_string_from_utf8()) "COM5": # Handle custom-delimited packets print("Packet: ", data) ``` -------------------------------- ### GdSerial - Send Binary and Text Data to Serial Port Source: https://context7.com/sujithchristopher/gdserial/llms.txt Demonstrates how to send raw bytes using `write()` and string data using `write_string()` to a serial port with `GdSerial`. Both methods return a boolean indicating success. `writeline()` is also shown, which appends a newline character to the string before sending. ```gdscript var serial = GdSerial.new() serial.set_port("COM3") serial.set_baud_rate(115200) if serial.open(): # Write binary data (PackedByteArray) var binary_data = PackedByteArray([0x01, 0x02, 0x03, 0x04, 0xFF]) var success = serial.write(binary_data) print("Binary write success: ", success) # Output: true # Write string data (converted to UTF-8) serial.write_string("Hello Arduino!") # Write line with automatic newline appended serial.writeline("GET_SENSOR") # Sends "GET_SENSOR\n" serial.close() ``` -------------------------------- ### Simple Blocking API Usage (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Illustrates the basic usage of the GdSerial class for synchronous serial communication. It includes listing available ports, setting port configurations, opening the port, writing data, reading responses, and closing the port. This API is simpler but can block the main thread. ```gdscript extends Node var serial: GdSerial func _ready(): serial = GdSerial.new() # List available ports var ports: Dictionary = serial.list_ports() for i in ports: var info = ports[i] print("- ", info["port_name"], " (", info["device_name"], ")") serial.set_port("COM3") serial.set_baud_rate(115200) if serial.open(): serial.writeline("Hello!") await get_tree().create_timer(0.1).timeout if serial.bytes_available() > 0: print("Response: ", serial.readline()) serial.close() ``` -------------------------------- ### GdSerial - Enumerate Available Serial Ports Source: https://context7.com/sujithchristopher/gdserial/llms.txt The `list_ports()` method of the `GdSerial` class returns a dictionary containing information about all available serial ports on the system. This includes the port name, type (e.g., USB), device name, and USB device identification (VID/PID). This information is crucial for selecting the correct port for communication. ```gdscript var serial = GdSerial.new() var ports: Dictionary = serial.list_ports() # Example output dictionary: # { # 0: { # "port_name": "COM3", # "port_type": "USB - VID: 2341, PID: 0043", # "device_name": "Arduino Uno" # }, # 1: { # "port_name": "COM5", # "port_type": "USB - VID: 10C4, PID: EA60", # "device_name": "CP2102 USB to UART Bridge" # } # } for i in ports: var info = ports[i] print("- ", info["port_name"], " (", info["device_name"], ")") ``` -------------------------------- ### Async Serial Communication with GdSerialManager (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/addons/gdserial/README.md Shows how to use GdSerialManager for asynchronous serial data reception. It involves creating a manager, connecting to the 'data_received' signal, and then opening a port. The manager needs to be polled regularly to process events. ```gdscript extends Node var manager: GdSerialManager func _ready(): manager = GdSerialManager.new() manager.data_received.connect(func(port, data): print("Data: ", data.get_string_from_utf8()) ) manager.open_port("COM3", 9600, 1000) func _process(_delta): manager.poll_events() ``` -------------------------------- ### GdSerialManager.reconfigure_port() Source: https://context7.com/sujithchristopher/gdserial/llms.txt Dynamically update serial port settings (baud rate, data bits, parity, stop bits, flow control, timeout) on an already open port without needing to close and reopen it. ```APIDOC ## reconfigure_port() - Update Settings on Open Port ### Description Dynamically update serial port settings while the port is open without closing and reopening. ### Method `GdSerialManager.reconfigure_port(port_name: String, baud_rate: int, data_bits: int, parity: int, stop_bits: int, flow_control: int, timeout_ms: int)` ### Endpoint N/A (Direct method calls on GdSerialManager instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```gdscript var manager = GdSerialManager.new() manager.open("COM3", 9600, 1000, 0) # Later, change settings without closing the port var success = manager.reconfigure_port( "COM3", # port_name 115200, # baud_rate (upgrade speed) 8, # data_bits 0, # parity (0: None, 1: Odd, 2: Even) 1, # stop_bits 0, # flow_control (0: None, 1: Software, 2: Hardware) 500 # timeout_ms (reduce timeout) ) if success: print("Port reconfigured successfully") else: print("Failed to reconfigure port") ``` ### Response #### Success Response (Reconfiguration) - **success** (Boolean) - True if the port settings were reconfigured successfully, false otherwise. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### GdSerial Basic API - Utilities (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Shows utility functions provided by the GdSerial library in GDScript. These include checking the number of available bytes in the buffer and clearing the input/output buffers. ```gdscript var serial = GdSerial.new() serial.set_port("COM3") if serial.open(): # Check bytes available to read var available_bytes = serial.bytes_available() print("Bytes available: ", available_bytes) # Clear buffers if serial.clear_buffer(): print("Buffers cleared successfully.") else: print("Failed to clear buffers.") serial.close() else: print("Failed to open serial port.") ``` -------------------------------- ### GdSerial - Core API Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md The GdSerial class offers a basic, synchronous API for controlling a single serial port, similar to PySerial. ```APIDOC ## GdSerial - Core API ### Description Provides a simple, PySerial-like API for direct, synchronous control of a single serial port. ### Methods #### Port Management - `list_ports() -> Dictionary`: Get all available serial ports. - `set_port(port_name: String)`: Set the serial port to use (e.g., "COM3", "/dev/ttyUSB0"). - `set_baud_rate(rate: int)`: Set the baud rate (default: 9600). - `set_data_bits(bits: int)`: Set data bits (6, 7, or 8). - `set_parity(type: int)`: Set parity (0: None, 1: Odd, 2: Even). - `set_stop_bits(bits: int)`: Set stop bits (1 or 2). - `set_flow_control(type: int)`: Set flow control (0: None, 1: Software, 2: Hardware). - `set_timeout(timeout_ms: int)`: Set read timeout in milliseconds (default: 1000). - `open() -> bool`: Open the serial port. - `close()`: Close the serial port. - `is_open() -> bool`: Check if the port is currently open. #### Data Operations - `write(data: PackedByteArray) -> bool`: Write raw bytes to the serial port. - `write_string(data: String) -> bool`: Write string data to the serial port. - `writeline(data: String) -> bool`: Write string data followed by a newline character. - `read(size: int) -> PackedByteArray`: Read a specified number of raw bytes from the serial port. - `read_string(size: int) -> String`: Read a specified number of bytes and convert them to a string. - `readline() -> String`: Read data until a newline character is encountered. #### Utilities - `bytes_available() -> int`: Get the number of bytes currently available in the input buffer. - `clear_buffer() -> bool`: Clear both the input and output buffers. ``` -------------------------------- ### GdSerial Basic API - Data Operations (GDScript) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Illustrates data handling operations using the GdSerial library in GDScript. This covers writing raw bytes or strings, reading data in bytes or as strings, and reading a line until a newline character. ```gdscript var serial = GdSerial.new() serial.set_port("COM3") serial.set_baud_rate(115200) if serial.open(): # Write string data serial.write_string("Hello Arduino!") serial.writeline("This is a new line.") # Write raw bytes var byte_data = PackedByteArray([0x01, 0x02, 0x03]) serial.write(byte_data) # Read raw bytes var read_bytes = serial.read(10) print("Read bytes: ", read_bytes) # Read as string var read_str = serial.read_string(20) print("Read string: ", read_str) # Read a line var read_line = serial.readline() print("Read line: ", read_line) serial.close() else: print("Failed to open serial port.") ``` -------------------------------- ### GdSerial - Simple Blocking API Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md The GdSerial class offers a straightforward, blocking API for serial communication. Suitable for simpler use cases or when blocking operations are acceptable. ```APIDOC ## GdSerial API ### Description Provides a simple, blocking interface for serial communication. Use this for straightforward tasks where blocking is not an issue. ### Methods - `list_ports() -> Dictionary`: Returns a dictionary of available serial ports. - `set_port(name: String)`: Sets the serial port to be used. - `set_baud_rate(baud: int)`: Sets the baud rate for the serial connection. - `open() -> bool`: Opens the configured serial port. Returns true on success. - `close()`: Closes the currently open serial port. - `writeline(data: String) -> bool`: Writes a string followed by a newline character to the port. - `write(data: PackedByteArray) -> bool`: Writes raw bytes to the port. - `readline() -> String`: Reads a line from the serial port (waits for newline). - `read(length: int) -> PackedByteArray`: Reads a specified number of bytes from the port. - `bytes_available() -> int`: Returns the number of bytes currently available in the receive buffer. ### Request Example (GDScript) ```gdscript extends Node var serial: GdSerial func _ready(): serial = GdSerial.new() # List available ports var ports: Dictionary = serial.list_ports() for port_id in ports: var info = ports[port_id] print("- ", info["port_name"], " (", info["device_name"], ")") serial.set_port("COM3") serial.set_baud_rate(115200) if serial.open(): serial.writeline("Hello!") await get_tree().create_timer(0.1).timeout # Wait briefly if serial.bytes_available() > 0: print("Response: ", serial.readline()) serial.close() ``` ### Response Example (Console Output) ``` - COM3 (USB Serial Device) Response: OK ``` ``` -------------------------------- ### Linux User Group Modification (Bash) Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md Provides the bash command to add a user to the 'dialout' group on Linux systems. This is necessary to grant the user permission to access serial ports. ```bash sudo usermod -a -G dialout $USER # Log out and back in for changes to take effect ``` -------------------------------- ### GdSerialManager - Asynchronous Multi-Port API Source: https://context7.com/sujithchristopher/gdserial/llms.txt Utilize the GdSerialManager for non-blocking, multi-port serial communication. It employs background reader threads and event signals for efficient handling of multiple devices and UI operations. ```APIDOC ## GdSerialManager Class - Asynchronous Multi-Port API ### Description Provides non-blocking, multi-port serial communication through background reader threads and event signals. Ideal for applications requiring simultaneous communication with multiple devices or non-blocking UI operations. ### Method Various (open, write, poll_events, etc.) ### Endpoint N/A (Direct method calls on GdSerialManager instance) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```gdscript extends Node var manager: GdSerialManager func _ready() -> void: manager = GdSerialManager.new() # Connect signals for async events manager.data_received.connect(_on_serial_data) manager.port_disconnected.connect(_on_serial_disconnect) # Open port in RAW mode (mode 0) - emits all data chunks immediately if manager.open("COM3", 9600, 1000): print("Port COM3 opened using Manager") # Write data to a specific port var data = "Hello from Manager\n".to_utf8_buffer() manager.write("COM3", data) else: print("Failed to open COM3 with Manager") # CRITICAL: Must call poll_events() in _process to trigger signals func _process(_delta: float) -> void: if manager: # poll_events() returns an Array of Dictionaries AND emits signals var events: Array = manager.poll_events() for event: Dictionary in events: if event.has("disconnected"): print("Event Polling: Port ", event["port"], " disconnected!") # Signal callback for new data func _on_serial_data(port: String, data: PackedByteArray) -> void: var text := data.get_string_from_utf8() print("Async Data from ", port, ": ", text) # Signal callback for disconnection func _on_serial_disconnect(port: String) -> void: print("Critical: Port ", port, " was disconnected!") ``` ### Response #### Success Response (Events/Data) - **events** (Array) - An array of dictionaries representing events (e.g., disconnection). - **data_received signal** - Emitted when data is received on a port. - **port_disconnected signal** - Emitted when a port is disconnected. #### Response Example ```json { "events": [ {"disconnected": true, "port": "COM3"} ], "data_received": {"port": "COM3", "data": "[72, 101, 108, 108, 111]"} } ``` ``` -------------------------------- ### GdSerialManager - Advanced API Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md The GdSerialManager class provides an advanced, asynchronous API for managing multiple serial ports using background threads and signals, suitable for complex applications. ```APIDOC ## GdSerialManager - Advanced API ### Description Offers a multi-port, asynchronous manager that utilizes background threads and signals. This class is ideal for complex applications requiring concurrent serial communication. ### Methods *(Specific methods for GdSerialManager are not detailed in the provided text, but it is described as an advanced, multi-port, asynchronous manager.)* ``` -------------------------------- ### Asynchronous Multi-Port Communication with GdSerialManager Source: https://context7.com/sujithchristopher/gdserial/llms.txt Utilizes the `GdSerialManager` for non-blocking serial communication across multiple ports. It employs background threads and event signals (`data_received`, `port_disconnected`) for asynchronous operations. The `poll_events()` method must be called regularly (e.g., in `_process`) to process incoming data and events. ```gdscript extends Node var manager: GdSerialManager func _ready() -> void: manager = GdSerialManager.new() # Connect signals for async events manager.data_received.connect(_on_serial_data) manager.port_disconnected.connect(_on_serial_disconnect) # Open port in RAW mode (mode 0) - emits all data chunks immediately if manager.open("COM3", 9600, 1000): print("Port COM3 opened using Manager") # Write data to a specific port var data = "Hello from Manager\n".to_utf8_buffer() manager.write("COM3", data) else: print("Failed to open COM3 with Manager") # CRITICAL: Must call poll_events() in _process to trigger signals func _process(_delta: float) -> void: if manager: # poll_events() returns an Array of Dictionaries AND emits signals var events: Array = manager.poll_events() for event: Dictionary in events: if event.has("disconnected"): print("Event Polling: Port ", event["port"], " disconnected!") # Signal callback for new data func _on_serial_data(port: String, data: PackedByteArray) -> void: var text := data.get_string_from_utf8() print("Async Data from ", port, ": ", text) # Signal callback for disconnection func _on_serial_disconnect(port: String) -> void: print("Critical: Port ", port, " was disconnected!") ``` -------------------------------- ### GdSerialManager - Asynchronous Operations Source: https://github.com/sujithchristopher/gdserial/blob/main/README.md The GdSerialManager class provides an asynchronous, non-blocking interface for managing serial ports. It's recommended for applications requiring a responsive UI. ```APIDOC ## GdSerialManager API ### Description Manages serial ports asynchronously, emitting signals for data reception and disconnections. Ideal for non-blocking UI operations. ### Methods - `list_ports() -> Dictionary`: Lists available serial ports. - `open(name: String, baud: int, timeout: int, mode: int) -> bool`: Opens a serial port with specified baud rate, timeout, and buffering mode. - `mode`: 0 (raw), 1 (line-buffered), 2 (custom delimiter). - `close(name: String)`: Closes the specified serial port. - `is_open(name: String) -> bool`: Checks if a port is currently open. - `write(name: String, data: PackedByteArray) -> bool`: Writes raw bytes to the port. - `reconfigure_port(...) -> bool`: Updates settings on an open port. - `set_delimiter(name: String, delimiter: int) -> bool`: Sets a custom delimiter byte for mode 2. - `poll_events() -> Array`: **Crucial**: Must be called in `_process` to handle signals and events. ### Signals - `data_received(port: String, data: PackedByteArray)`: Emitted when new data arrives on a port. - `port_disconnected(port: String)`: Emitted when a port is disconnected. ### Request Example (GDScript) ```gdscript extends Node var manager: GdSerialManager func _ready(): manager = GdSerialManager.new() manager.data_received.connect(_on_data) manager.port_disconnected.connect(_on_disconnect) # Open COM3 in line-buffered mode if manager.open("COM3", 9600, 1000, 1): print("Connected to COM3") func _process(_delta): manager.poll_events() # Essential for signal emission func _on_data(port: String, data: PackedByteArray): print("Data from ", port, ": ", data.get_string_from_utf8()) func _on_disconnect(port: String): print("Lost connection to ", port) ``` ### Response Example (Signals) ``` Data from COM3: Hello World! Lost connection to COM3 ``` ``` -------------------------------- ### Remove Quarantine Flag from macOS Libraries (Bash) Source: https://github.com/sujithchristopher/gdserial/blob/main/MACOS_SECURITY.md This command removes the quarantine flag from downloaded macOS libraries, which is often the cause of 'malware' warnings or library loading errors. It targets specific library files or entire directories. Ensure you replace the placeholder path with the actual location of your gdserial addon. ```bash # Remove quarantine flag from the downloaded library cd /path/to/your/godot/project/addons/gdserial/bin/macos-arm64/ xattr -d com.apple.quarantine libgdserial.dylib # Or remove from entire addon folder xattr -rd com.apple.quarantine /path/to/addons/gdserial/ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.