Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions core/src/drivers/plugin_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ int plugin_driver_init(plugin_driver_t *driver)
// Call the Python init function with proper capsule
PyObject *result =
PyObject_CallFunctionObjArgs(plugin->python_plugin->pFuncInit, args, NULL);

// Store the capsule reference for the lifetime of the plugin
plugin->python_plugin->args_capsule = args;

Expand Down Expand Up @@ -596,10 +596,10 @@ int python_plugin_get_symbols(plugin_instance_t *plugin)
plugin->python_plugin = py_binds;

printf("Python plugin '%s' symbols loaded successfully\n", module_name);
printf(" - init: %s\n", py_binds->pFuncInit ? "" : "");
printf(" - start_loop: %s\n", py_binds->pFuncStart ? "" : "");
printf(" - stop_loop: %s\n", py_binds->pFuncStop ? "" : "");
printf(" - cleanup: %s\n", py_binds->pFuncCleanup ? "" : "");
printf(" - init: %s\n", py_binds->pFuncInit ? "OK" : "Failed");
printf(" - start_loop: %s\n", py_binds->pFuncStart ? "OK" : "Failed");
printf(" - stop_loop: %s\n", py_binds->pFuncStop ? "OK" : "Failed");
printf(" - cleanup: %s\n", py_binds->pFuncCleanup ? "OK" : "Failed");

return 0;
}
Expand Down
20 changes: 10 additions & 10 deletions core/src/drivers/plugins/python/modbus_slave/simple_modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,14 @@ def init(args_capsule):
# This is a PyCapsule from C - use safe extraction
runtime_args, error_msg = safe_extract_runtime_args_from_capsule(args_capsule)
if runtime_args is None:
print(f"[MODBUS] Failed to extract runtime args: {error_msg}")
print(f"[MODBUS] Failed to extract runtime args: {error_msg}")
return False

print(f"[MODBUS] Runtime arguments extracted successfully")
print(f"[MODBUS] Runtime arguments extracted successfully")
else:
# This is a direct object (for testing)
runtime_args = args_capsule
print(f"[MODBUS] Using direct runtime args for testing")
print(f"[MODBUS] Using direct runtime args for testing")

# Try to load configuration from plugin_specific_config_file_path
try:
Expand All @@ -329,21 +329,21 @@ def init(args_capsule):
if network_config and 'host' in network_config and 'port' in network_config:
gIp = str(network_config['host'])
gPort = int(network_config['port'])
print(f"[MODBUS] Configuration loaded - Host: {gIp}, Port: {gPort}")
print(f"[MODBUS] Configuration loaded - Host: {gIp}, Port: {gPort}")
else:
print(f"[MODBUS] Config file loaded but network_configuration section missing or incomplete - using defaults")
print(f"[MODBUS] Config file loaded but network_configuration section missing or incomplete - using defaults")
print(f"[MODBUS] Available config sections: {list(config_map.keys())}")
else:
print(f"[MODBUS] Failed to load configuration file: {status} - using defaults")
print(f"[MODBUS] Failed to load configuration file: {status} - using defaults")
except Exception as config_error:
print(f"[MODBUS] Exception while loading config: {config_error} - using defaults")
print(f"[MODBUS] Exception while loading config: {config_error} - using defaults")
import traceback
traceback.print_exc()

# Safely access buffer size using validation
buffer_size, size_error = runtime_args.safe_access_buffer_size()
if buffer_size == -1:
print(f"[MODBUS] Failed to access buffer size: {size_error}")
print(f"[MODBUS] Failed to access buffer size: {size_error}")
return False

# print(f"[MODBUS] Buffer size: {buffer_size}")
Expand Down Expand Up @@ -371,11 +371,11 @@ def init(args_capsule):
)
server_context = ModbusServerContext(devices={1: device}, single=False)

print(f"[MODBUS] Plugin initialized successfully - Host: {gIp}, Port: {gPort}")
print(f"[MODBUS] Plugin initialized successfully - Host: {gIp}, Port: {gPort}")
return True

except Exception as e:
print(f"[MODBUS] Plugin initialization failed: {e}")
print(f"[MODBUS] Plugin initialization failed: {e}")
import traceback
traceback.print_exc()
return False
Expand Down
22 changes: 11 additions & 11 deletions scripts/setup-tests-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ set -e
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
VENV_DIR="$PROJECT_ROOT/venvs/test-env"

echo "🚀 Setting up test environment for OpenPLC Runtime"
echo "📂 Project root: $PROJECT_ROOT"
echo "🐍 Virtualenv: $VENV_DIR"
echo "Setting up test environment for OpenPLC Runtime"
echo "Project root: $PROJECT_ROOT"
echo "Virtualenv: $VENV_DIR"
echo "=============================="

if [ ! -d "$VENV_DIR" ]; then
echo "📦 Creating virtual environment..."
echo "Creating virtual environment..."
python3 -m venv "$VENV_DIR"
else
echo "Virtual environment already exists."
echo "Virtual environment already exists."
fi

source "$VENV_DIR/bin/activate"

echo "⬆️ Upgrading pip..."
echo "Upgrading pip..."
pip install --upgrade pip

if [ -f "$PROJECT_ROOT/requirements.txt" ]; then
echo "📦 Installing dependencies from requirements.txt..."
echo "Installing dependencies from requirements.txt..."
pip install -r "$PROJECT_ROOT/requirements.txt"
fi

# 4. Install pytest and project in editable mode
echo "🧪 Installing pytest and local package..."
echo "Installing pytest and local package..."
pip install pytest
pip install -e "$PROJECT_ROOT"

if [ ! -f "$PROJECT_ROOT/pytest.ini" ]; then
echo "⚙️ Creating default pytest.ini..."
echo "Creating default pytest.ini..."
cat <<EOF > "$PROJECT_ROOT/pytest.ini"
[pytest]
minversion = 7.0
Expand All @@ -48,7 +48,7 @@ fi

# Existing conftest.py with fixtures is preserved; no need to create or overwrite.

echo "🧪 Running pytest..."
echo "Running pytest..."
pytest -vvv

echo "All done!"
echo "All done!"
8 changes: 4 additions & 4 deletions webserver/DEBUG_WEBSOCKET.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,15 @@ sio = socketio.Client(ssl_verify=False)

@sio.event(namespace='/api/debug')
def connect():
print("Connected to WebSocket!")
print("Connected to WebSocket!")

@sio.event(namespace='/api/debug')
def connected(data):
print(f"Server confirmed: {data}")
print(f"Server confirmed: {data}")

@sio.event(namespace='/api/debug')
def debug_response(data):
print(f"\n✓ Debug response:")
print(f"\nDebug response:")
print(f" Success: {data.get('success')}")
if data.get('success'):
print(f" Data: {data.get('data')}")
Expand All @@ -209,7 +209,7 @@ def debug_response(data):

@sio.event(namespace='/api/debug')
def disconnect():
print("Disconnected")
print("Disconnected")

# Connect with token in auth dict (preferred method)
try:
Expand Down
2 changes: 1 addition & 1 deletion webserver/logger/logger_module_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ for record in buffer.buffer:

---

## 🧪 Development & Testing
## Development & Testing

This section guides developers on how to **test and validate the logging module** during development.

Expand Down
Loading