Clear Filters
Clear Filters

The command "serial" creates an error when used in a function and works fine as a script file.

1 view (last 30 days)
I'm connecting a GMC-300E+ Geiger-Counter to the pc via Matlab and the instrumentation-control toolbox. The script file (attached in the PDF) works fine. When I'm using the script as a function (just removing the % see in the PDF) there will be an error "Unable to connect to the serialport device at port 'COM11' ". Adding the % again, changing from function to script, every thing works fine again. Versions:
MATLAB Version: (R2021b) Update 3
MATLAB License Number: 41082938
Operating System: Microsoft Windows 7 Professional Version 6.1 (Build 7601: Service Pack 1)
Java Version: Java 1.8.0_202-b08 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode
MATLAB Version 9.11 (R2021b)
Instrument Control Toolbox Version 4.5 (R2021b)
Signal Processing Toolbox Version 8.7 (R2021b)
Thank for any help or explanation. Alex
Alexander on 2 Jun 2022
I used the function serial(). When using serialport() instead it works fine, as script and function.
Walter Roberson
Walter Roberson on 2 Jun 2022
Why are you opening the device serial() and serialport()?
You serial() and fclose() but not fopen()
You appear to be using a script to assign variables. In functions, matlab is permitted to ignore the assignments in some circumstances. The workaround is to assign something (anything) to the variable before calling the script so that matlab knows it should be treated as a variable.

Sign in to comment.

Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!