18 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gavin Trevorrow am 12 Jun. 2024 um 21:51
Kommentiert: Gavin Trevorrow am 13 Jun. 2024 um 15:11
Akzeptierte Antwort: surya venu
I'm attempting to run the example MODBUS RS485 Communication Between Client and Server Using Arduino Board with two Arduino Uno units. These units have only one dedicated serial port on pins 0 and 1. When I go to Monitor and Tune the Client Model, I get an error message for all 6 MODBUS blocks in the model that reads:
Error evaluating 'InitFcn' callback of codertarget.arduinobase.internal.arduino_ModbusRS485MasterRead block (mask) 'arduino_modbus_client/Modbus RS485 Client Read'.
Callback string is 'codertarget.arduinobase.conflictcheck.validateandregisterBlocks(gcbh);'
Caused by:
The SerialPin_1 '1' being used by 'arduino_modbus_client/Modbus RS485 Client Read' is currently in use by 'Monitor and tune over XCP on Serial'. To resolve the conflict, change the value of SerialPin_1 in 'arduino_modbus_client/Modbus RS485 Client Read' to an alternate valid value.
It appears that the only port the Arduino Uno has is in use by the USB interface with my desktop computer. I know that ArduinoIDE has the SoftwareSerial library addon that is supposed to allow you to assign pins to create a separate serial port, but I don't know if a similar operation is possible in Simulink. Or perhaps I can create the new port in ArduinoIDE for use in the Simulink model. Thank you.
0 Kommentare -2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden
-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden
Melden Sie sich an, um zu kommentieren.
Melden Sie sich an, um diese Frage zu beantworten.
Akzeptierte Antwort
surya venu am 13 Jun. 2024 um 5:20
⋮
Hi,
Your issue arises because the Arduino Uno's primary hardware serial port (Serial) is being used for both the USB communication with your computer and for MODBUS RS485 communication in your project. This creates a conflict, especially when you're trying to use the same serial port for monitoring and tuning your Simulink model via the USB connection.
Simulink models for Arduino typically use the hardware serial port for deploying and debugging the model, which is why you're encountering the error. To work around this, you're correct in thinking about "SoftwareSerial", a library that allows you to create a software-based serial port on almost any digital pins of the Arduino.
Unfortunately, Simulink does not directly support "SoftwareSerial" within its block set for Arduino. However, you can integrate custom code, including "SoftwareSerial", into your Simulink model. This involves writing some parts of your model's logic in C++ and ensuring it interacts correctly with the rest of your Simulink model.
Here is how to create to create a custom device driver for Arduino Library: https://www.mathworks.com/help/simulink/supportpkg/arduino_ug/create-custom-blocks-for-arduino-support-package.html
The above link contains information about:
- Create Project and Libraries Folder
- Write Hardware Specific C/C++ Code
- Select System Object Template
- Specify Initialization, Output, and Termination Behavior
- Update Paths for Source and Header Files
- Set Output Port Properties Create
- MATLAB System Block
- Generate Code and Deploy Model to Hardware
Hope it helps.
1 Kommentar -1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Gavin Trevorrow am 13 Jun. 2024 um 15:11
Direkter Link zu diesem Kommentar
https://de.mathworks.com/matlabcentral/answers/2128061-can-i-create-a-new-serial-port-on-the-arduino-uno-to-run-a-simulink-model-in-real-time-that-also-use#comment_3186016
Thank you for your insight! It looks like the page you linked to will be a good starting point for creating the custom code necessary to assign new pins and create the port.
Melden Sie sich an, um zu kommentieren.
Weitere Antworten (0)
Melden Sie sich an, um diese Frage zu beantworten.
Es ist ein Fehler aufgetreten
Da Änderungen an der Seite vorgenommen wurden, kann diese Aktion nicht abgeschlossen werden. Laden Sie die Seite neu, um sie im aktualisierten Zustand anzuzeigen.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asien-Pazifik
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Kontakt zu Ihrer lokalen Niederlassung