first commit
commit
8da96e4062
@ -0,0 +1,4 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
@ -0,0 +1,2 @@
|
||||
# Normalize EOL for all files that Git considers text files.
|
||||
* text=auto eol=lf
|
||||
@ -0,0 +1,3 @@
|
||||
# Godot 4+ specific ignores
|
||||
.godot/
|
||||
/android/
|
||||
@ -0,0 +1,51 @@
|
||||
# GdSerial - Serial Communication for Godot
|
||||
|
||||
<img src="icon.png" alt="GdSerial Icon" width="64" height="64" align="left" style="margin-right: 20px;">
|
||||
|
||||
A Rust-based serial communication library for Godot 4 that provides PySerial-like functionality.
|
||||
|
||||
<br clear="left">
|
||||
|
||||
## Installation
|
||||
|
||||
1. Download this addon from the Godot Asset Library or GitHub
|
||||
2. Copy the `addons/gdserial` folder to your project's `addons/` directory
|
||||
3. Enable the plugin in Project Settings > Plugins
|
||||
|
||||
## Quick Start
|
||||
|
||||
```gdscript
|
||||
extends Node
|
||||
|
||||
var serial: GdSerial
|
||||
|
||||
func _ready():
|
||||
serial = GdSerial.new()
|
||||
|
||||
# List available ports
|
||||
var ports = serial.list_ports()
|
||||
print("Available ports: ", ports)
|
||||
|
||||
# Configure and connect
|
||||
serial.set_port("COM3") # Adjust for your system
|
||||
serial.set_baud_rate(9600)
|
||||
|
||||
if serial.open():
|
||||
serial.writeline("Hello Arduino!")
|
||||
var response = serial.readline()
|
||||
print("Response: ", response)
|
||||
serial.close()
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
See the main repository README for complete API documentation.
|
||||
|
||||
## Requirements
|
||||
|
||||
- Godot 4.2+
|
||||
- Appropriate permissions for serial port access (see platform-specific notes in main README)
|
||||
|
||||
## License
|
||||
|
||||
MIT License - see LICENSE file for details.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,223 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="GdSerial" inherits="RefCounted" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
|
||||
<brief_description>
|
||||
A PySerial-like serial communication library for Godot 4.
|
||||
</brief_description>
|
||||
<description>
|
||||
GdSerial provides cross-platform serial communication functionality for Godot 4, enabling direct communication with serial devices such as Arduino, sensors, modems, and other hardware. The API is designed to be similar to Python's PySerial library, making it familiar and easy to use.
|
||||
|
||||
The library supports automatic disconnection detection, robust error handling, and cross-platform port enumeration with device identification.
|
||||
|
||||
Key features:
|
||||
- PySerial-like API for familiar usage patterns
|
||||
- Automatic device disconnection detection and cleanup
|
||||
- Cross-platform support (Windows, Linux, macOS)
|
||||
- USB device identification (VID/PID, manufacturer, product)
|
||||
- Configurable baud rates, timeouts, and port settings
|
||||
- Both binary and text-based communication
|
||||
- Line-based reading with proper newline handling
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
<methods>
|
||||
<method name="bytes_available">
|
||||
<return type="int" />
|
||||
<description>
|
||||
Returns the number of bytes available to read from the serial port buffer.
|
||||
|
||||
This method automatically tests the connection state and will mark the port as disconnected if the device is no longer available. If the port is not open or has been disconnected, returns 0.
|
||||
|
||||
This is useful for checking if data is available before calling [method read] or [method read_string] to avoid blocking operations.
|
||||
</description>
|
||||
</method>
|
||||
<method name="clear_buffer">
|
||||
<return type="bool" />
|
||||
<description>
|
||||
Clears all data from both the input and output serial port buffers.
|
||||
|
||||
Returns [code]true[/code] if the buffers were successfully cleared, [code]false[/code] otherwise. This method automatically tests the connection state and will handle disconnection if the device is no longer available.
|
||||
|
||||
Useful for ensuring a clean slate when starting communication or after an error condition.
|
||||
</description>
|
||||
</method>
|
||||
<method name="close">
|
||||
<return type="void" />
|
||||
<description>
|
||||
Closes the serial port connection and releases any associated resources.
|
||||
|
||||
After calling this method, [method is_open] will return [code]false[/code] and all read/write operations will fail until [method open] is called again.
|
||||
|
||||
It is safe to call this method multiple times or when the port is already closed.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_open">
|
||||
<return type="bool" />
|
||||
<description>
|
||||
Checks if the serial port is currently open and the device is still connected.
|
||||
|
||||
This method actively tests the connection by attempting a non-destructive operation on the port. If the device has been disconnected (e.g., USB device unplugged), this method will automatically close the port and return [code]false[/code].
|
||||
|
||||
Returns [code]true[/code] if the port is open and the device is still available, [code]false[/code] otherwise.
|
||||
</description>
|
||||
</method>
|
||||
<method name="list_ports">
|
||||
<return type="Dictionary" />
|
||||
<description>
|
||||
Returns a dictionary containing information about all available serial ports on the system.
|
||||
|
||||
Each entry in the dictionary has an integer key (port index) and a Dictionary value containing:
|
||||
- [code]port_name[/code] (String): The system port name (e.g., "COM3", "/dev/ttyUSB0")
|
||||
- [code]port_type[/code] (String): Type information including USB VID/PID for USB devices
|
||||
- [code]device_name[/code] (String): Human-readable device name from USB descriptors
|
||||
|
||||
Example return value:
|
||||
[codeblock]
|
||||
{
|
||||
0: {
|
||||
"port_name": "COM3",
|
||||
"port_type": "USB - VID: 2341, PID: 0043",
|
||||
"device_name": "Arduino Uno"
|
||||
}
|
||||
}
|
||||
[/codeblock]
|
||||
|
||||
This method is useful for presenting available ports to users and for automatic device discovery.
|
||||
</description>
|
||||
</method>
|
||||
<method name="open">
|
||||
<return type="bool" />
|
||||
<description>
|
||||
Opens a connection to the serial port with the current configuration.
|
||||
|
||||
Returns [code]true[/code] if the port was successfully opened, [code]false[/code] otherwise. The port configuration uses:
|
||||
- 8 data bits
|
||||
- No parity
|
||||
- 1 stop bit
|
||||
- No flow control
|
||||
- Baud rate set by [method set_baud_rate] (default: 9600)
|
||||
- Timeout set by [method set_timeout] (default: 1000ms)
|
||||
|
||||
You must call [method set_port] with a valid port name before calling this method.
|
||||
</description>
|
||||
</method>
|
||||
<method name="read">
|
||||
<return type="PackedByteArray" />
|
||||
<param index="0" name="size" type="int" />
|
||||
<description>
|
||||
Reads up to [param size] bytes from the serial port and returns them as a [PackedByteArray].
|
||||
|
||||
This method uses non-blocking reads and will return immediately with available data, even if less than [param size] bytes are available. If no data is available or an error occurs, returns an empty [PackedByteArray].
|
||||
|
||||
The method automatically handles disconnection detection - if the device is disconnected during the read operation, the port will be automatically closed.
|
||||
|
||||
Timeout behavior is controlled by [method set_timeout]. Read operations that exceed the timeout will return an empty array.
|
||||
</description>
|
||||
</method>
|
||||
<method name="read_string">
|
||||
<return type="String" />
|
||||
<param index="0" name="size" type="int" />
|
||||
<description>
|
||||
Reads up to [param size] bytes from the serial port and converts them to a UTF-8 string.
|
||||
|
||||
This is a convenience method that calls [method read] and converts the result to a string. If the received bytes cannot be converted to valid UTF-8, an error is logged and an empty string is returned.
|
||||
|
||||
Returns an empty string if no data is available, an error occurs, or the conversion fails.
|
||||
</description>
|
||||
</method>
|
||||
<method name="readline">
|
||||
<return type="String" />
|
||||
<description>
|
||||
Reads a line of text from the serial port, stopping at the first newline character ('\n').
|
||||
|
||||
This method reads data byte-by-byte until a newline is encountered, the timeout is reached, or an error occurs. Carriage return characters ('\r') are automatically filtered out.
|
||||
|
||||
The newline character itself is not included in the returned string. If the timeout is reached before a complete line is received, the partial line data is returned.
|
||||
|
||||
Returns an empty string if no data is available, the port is not open, or an error occurs.
|
||||
|
||||
This method is particularly useful for line-based protocols and communicating with devices that send data terminated by newlines.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_baud_rate">
|
||||
<return type="void" />
|
||||
<param index="0" name="baud_rate" type="int" />
|
||||
<description>
|
||||
Sets the baud rate (communication speed) for the serial port.
|
||||
|
||||
The baud rate determines how fast data is transmitted over the serial connection. Common values include 9600, 19200, 38400, 57600, 115200, etc.
|
||||
|
||||
This setting takes effect the next time [method open] is called. Changing the baud rate while the port is open will not affect the current connection.
|
||||
|
||||
Default value: 9600
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_port">
|
||||
<return type="void" />
|
||||
<param index="0" name="port_name" type="String" />
|
||||
<description>
|
||||
Sets the name of the serial port to connect to.
|
||||
|
||||
The port name format depends on the operating system:
|
||||
- Windows: "COM1", "COM2", etc.
|
||||
- Linux: "/dev/ttyUSB0", "/dev/ttyACM0", etc.
|
||||
- macOS: "/dev/tty.usbserial-*", "/dev/tty.usbmodem*", etc.
|
||||
|
||||
Use [method list_ports] to discover available ports on the system.
|
||||
|
||||
This setting takes effect the next time [method open] is called.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_timeout">
|
||||
<return type="void" />
|
||||
<param index="0" name="timeout_ms" type="int" />
|
||||
<description>
|
||||
Sets the timeout for read operations in milliseconds.
|
||||
|
||||
This timeout applies to all read operations ([method read], [method read_string], [method readline]). If a read operation cannot complete within this time, it will return with whatever data was available.
|
||||
|
||||
Setting a longer timeout allows more time for slow devices to respond, while shorter timeouts make operations more responsive but may truncate data from slow devices.
|
||||
|
||||
This setting takes effect the next time [method open] is called.
|
||||
|
||||
Default value: 1000 (1 second)
|
||||
</description>
|
||||
</method>
|
||||
<method name="write">
|
||||
<return type="bool" />
|
||||
<param index="0" name="data" type="PackedByteArray" />
|
||||
<description>
|
||||
Writes binary data to the serial port.
|
||||
|
||||
Returns [code]true[/code] if all data was successfully written and flushed to the device, [code]false[/code] otherwise.
|
||||
|
||||
The method automatically tests the connection state before writing and handles disconnection detection. If the device is disconnected during the write operation, the port will be automatically closed.
|
||||
|
||||
All data is immediately flushed to ensure it's transmitted to the device.
|
||||
</description>
|
||||
</method>
|
||||
<method name="write_string">
|
||||
<return type="bool" />
|
||||
<param index="0" name="data" type="String" />
|
||||
<description>
|
||||
Writes a string to the serial port.
|
||||
|
||||
This is a convenience method that converts the string to UTF-8 bytes and calls [method write].
|
||||
|
||||
Returns [code]true[/code] if the string was successfully written and flushed to the device, [code]false[/code] otherwise.
|
||||
</description>
|
||||
</method>
|
||||
<method name="writeline">
|
||||
<return type="bool" />
|
||||
<param index="0" name="data" type="String" />
|
||||
<description>
|
||||
Writes a string followed by a newline character ('\n') to the serial port.
|
||||
|
||||
This is a convenience method for line-based protocols. It appends a newline character to the provided string and sends it to the device.
|
||||
|
||||
Returns [code]true[/code] if the string and newline were successfully written and flushed to the device, [code]false[/code] otherwise.
|
||||
|
||||
This method is useful for communicating with devices that expect line-terminated commands.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
</class>
|
||||
Binary file not shown.
@ -0,0 +1,42 @@
|
||||
[remap]
|
||||
|
||||
importer="scene"
|
||||
importer_version=1
|
||||
type="PackedScene"
|
||||
uid="uid://whb60vrhxy42"
|
||||
path="res://.godot/imported/threadfin-butterflyfish.glb-4cfc2b56864daefe766dc25b4402f86a.scn"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/gdserial/doc/en/threadfin-butterflyfish.glb"
|
||||
dest_files=["res://.godot/imported/threadfin-butterflyfish.glb-4cfc2b56864daefe766dc25b4402f86a.scn"]
|
||||
|
||||
[params]
|
||||
|
||||
nodes/root_type=""
|
||||
nodes/root_name=""
|
||||
nodes/root_script=null
|
||||
nodes/apply_root_scale=true
|
||||
nodes/root_scale=1.0
|
||||
nodes/import_as_skeleton_bones=false
|
||||
nodes/use_name_suffixes=true
|
||||
nodes/use_node_type_suffixes=true
|
||||
meshes/ensure_tangents=true
|
||||
meshes/generate_lods=true
|
||||
meshes/create_shadow_meshes=true
|
||||
meshes/light_baking=1
|
||||
meshes/lightmap_texel_size=0.2
|
||||
meshes/force_disable_compression=false
|
||||
skins/use_named_skins=true
|
||||
animation/import=true
|
||||
animation/fps=30
|
||||
animation/trimming=false
|
||||
animation/remove_immutable_tracks=true
|
||||
animation/import_rest_as_RESET=false
|
||||
import_script/path=""
|
||||
materials/extract=0
|
||||
materials/extract_format=0
|
||||
materials/extract_path=""
|
||||
_subresources={}
|
||||
gltf/naming_version=2
|
||||
gltf/embedded_image_handling=1
|
||||
@ -0,0 +1,22 @@
|
||||
[configuration]
|
||||
|
||||
entry_symbol = "gdext_rust_init"
|
||||
compatibility_minimum = 4.2
|
||||
|
||||
[libraries]
|
||||
|
||||
linux.debug.x86_64 = "res://addons/gdserial/bin/linux-x86_64/libgdserial.so"
|
||||
linux.release.x86_64 = "res://addons/gdserial/bin/linux-x86_64/libgdserial.so"
|
||||
linux.debug.arm64 = "res://addons/gdserial/bin/linux-arm64/libgdserial.so"
|
||||
linux.release.arm64 = "res://addons/gdserial/bin/linux-arm64/libgdserial.so"
|
||||
windows.debug.x86_64 = "res://addons/gdserial/bin/windows-x86_64/gdserial.dll"
|
||||
windows.release.x86_64 = "res://addons/gdserial/bin/windows-x86_64/gdserial.dll"
|
||||
windows.debug.arm64 = "res://addons/gdserial/bin/windows-arm64/gdserial.dll"
|
||||
windows.release.arm64 = "res://addons/gdserial/bin/windows-arm64/gdserial.dll"
|
||||
macos.debug.x86_64 = "res://addons/gdserial/bin/macos-x86_64/libgdserial.dylib"
|
||||
macos.release.x86_64 = "res://addons/gdserial/bin/macos-x86_64/libgdserial.dylib"
|
||||
macos.debug.arm64 = "res://addons/gdserial/bin/macos-arm64/libgdserial.dylib"
|
||||
macos.release.arm64 = "res://addons/gdserial/bin/macos-arm64/libgdserial.dylib"
|
||||
|
||||
[documentation]
|
||||
en = "res://addons/gdserial/doc/en/"
|
||||
@ -0,0 +1 @@
|
||||
uid://cvccd8e4fsuj8
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 9.9 KiB |
@ -0,0 +1,40 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ynyfpebskqam"
|
||||
path="res://.godot/imported/icon.png-53ffae8ebbf3205c8850638b64c27a1c.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/gdserial/icon.png"
|
||||
dest_files=["res://.godot/imported/icon.png-53ffae8ebbf3205c8850638b64c27a1c.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
@ -0,0 +1,7 @@
|
||||
[plugin]
|
||||
|
||||
name="GdSerial - Serial Communication Library"
|
||||
description="A Rust-based serial communication library for Godot 4 that provides PySerial-like functionality. Enables communication with Arduino, sensors, and other serial devices."
|
||||
author="Sujith Christopher"
|
||||
version="0.2.7"
|
||||
script="plugin.gd"
|
||||
@ -0,0 +1,8 @@
|
||||
@tool
|
||||
extends EditorPlugin
|
||||
|
||||
func _enter_tree():
|
||||
print("GdSerial plugin activated")
|
||||
|
||||
func _exit_tree():
|
||||
print("GdSerial plugin deactivated")
|
||||
@ -0,0 +1 @@
|
||||
uid://bh3dth437th11
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 5.5 MiB |
@ -0,0 +1,44 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ng2pd43kxgs7"
|
||||
path.s3tc="res://.godot/imported/threadfin-butterflyfish_kupu-kupu-sirip-benang.png-0b31866de17ef3afa8dbca15702dadbc.s3tc.ctex"
|
||||
metadata={
|
||||
"imported_formats": ["s3tc_bptc"],
|
||||
"vram_texture": true
|
||||
}
|
||||
generator_parameters={
|
||||
"md5": "bc2098bfa3f85de8c85c1b9ab8436298"
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/threadfin-butterflyfish_kupu-kupu-sirip-benang.png"
|
||||
dest_files=["res://.godot/imported/threadfin-butterflyfish_kupu-kupu-sirip-benang.png-0b31866de17ef3afa8dbca15702dadbc.s3tc.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=2
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=true
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=0
|
||||
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="128" height="128"><rect width="124" height="124" x="2" y="2" fill="#363d52" stroke="#212532" stroke-width="4" rx="14"/><g fill="#fff" transform="translate(12.322 12.322)scale(.101)"><path d="M105 673v33q407 354 814 0v-33z"/><path fill="#478cbf" d="m105 673 152 14q12 1 15 14l4 67 132 10 8-61q2-11 15-15h162q13 4 15 15l8 61 132-10 4-67q3-13 15-14l152-14V427q30-39 56-81-35-59-83-108-43 20-82 47-40-37-88-64 7-51 8-102-59-28-123-42-26 43-46 89-49-7-98 0-20-46-46-89-64 14-123 42 1 51 8 102-48 27-88 64-39-27-82-47-48 49-83 108 26 42 56 81zm0 33v39c0 276 813 276 814 0v-39l-134 12-5 69q-2 10-14 13l-162 11q-12 0-16-11l-10-65H446l-10 65q-4 11-16 11l-162-11q-12-3-14-13l-5-69z"/><path d="M483 600c0 34 58 34 58 0v-86c0-34-58-34-58 0z"/><circle cx="725" cy="526" r="90"/><circle cx="299" cy="526" r="90"/></g><g fill="#414042" transform="translate(12.322 12.322)scale(.101)"><circle cx="307" cy="532" r="60"/><circle cx="717" cy="532" r="60"/></g></svg>
|
||||
|
After Width: | Height: | Size: 995 B |
@ -0,0 +1,43 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dlib5lxp4dldp"
|
||||
path="res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://icon.svg"
|
||||
dest_files=["res://.godot/imported/icon.svg-218a8f2b3041327d8a5756f3a245f83b.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/uastc_level=0
|
||||
compress/rdo_quality_loss=0.0
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/channel_remap/red=0
|
||||
process/channel_remap/green=1
|
||||
process/channel_remap/blue=2
|
||||
process/channel_remap/alpha=3
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
svg/scale=1.0
|
||||
editor/scale_with_editor_scale=false
|
||||
editor/convert_colors_with_editor_theme=false
|
||||
@ -0,0 +1 @@
|
||||
extends Node
|
||||
@ -0,0 +1 @@
|
||||
uid://dsv777rckdai
|
||||
@ -0,0 +1,48 @@
|
||||
extends Node
|
||||
|
||||
var serial: GdSerial
|
||||
|
||||
var latestData
|
||||
|
||||
func _ready():
|
||||
# Create serial instance
|
||||
serial = GdSerial.new()
|
||||
|
||||
# List available ports
|
||||
print("Available ports:")
|
||||
var ports = serial.list_ports()
|
||||
for i in range(ports.size()):
|
||||
var port_info = ports[i]
|
||||
print("- ", port_info["port_name"], " (", port_info["port_type"], ")")
|
||||
|
||||
# Configure and open port
|
||||
serial.set_port("/dev/cu.usbmodem101") # Adjust for your system
|
||||
serial.set_baud_rate(9600)
|
||||
serial.set_timeout(1000)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func _process(delta):
|
||||
serial.readline();
|
||||
if serial.open():
|
||||
print("Port opened successfully!")
|
||||
# Send command
|
||||
serial.writeline("Hello Arduino!")
|
||||
|
||||
|
||||
# Wait and read response
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
if serial.bytes_available() > 0:
|
||||
var response = serial.readline()
|
||||
print("Response: ", response)
|
||||
latestData = response
|
||||
|
||||
serial.close()
|
||||
#else:
|
||||
#print("Failed to open port")
|
||||
#print(latestData)
|
||||
|
||||
|
||||
@ -0,0 +1 @@
|
||||
uid://dyuq6c82ei7fc
|
||||
@ -0,0 +1,8 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://mh2ey6ut8rgf"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dyuq6c82ei7fc" path="res://node_3d.gd" id="1_a202f"]
|
||||
|
||||
[node name="Node3D" type="Node3D"]
|
||||
script = ExtResource("1_a202f")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
@ -0,0 +1,16 @@
|
||||
; Engine configuration file.
|
||||
; It's best edited using the editor UI and not directly,
|
||||
; since the parameters that go here are not all obvious.
|
||||
;
|
||||
; Format:
|
||||
; [section] ; section goes between []
|
||||
; param=value ; assign values to parameters
|
||||
|
||||
config_version=5
|
||||
|
||||
[application]
|
||||
|
||||
config/name="fish"
|
||||
run/main_scene="res://node_3d.tscn"
|
||||
config/features=PackedStringArray("4.5", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
@ -0,0 +1 @@
|
||||
uid://bd7o0xwr2n8s3
|
||||
Loading…
Reference in New Issue