Effacer les filtres
Effacer les filtres

warning in serial properties

4 vues (au cours des 30 derniers jours)
Rangga
Rangga le 12 Juin 2024
Commenté : Ayush Aniket le 12 Juin 2024
I created a code like this
and I have a problem that the serial function is not supported in matlab 2024, if I want to change to the matlab 2024 version how will the code be?
function [sphandle] = Dataserialport(comPortNum, bufferSize)
availablePorts = serialportlist;
if ~isempty(availablePorts)
disp('Serial port(s) already open. Re-initializing...');
end
comPortString = ['COM' num2str(comPortNum)];
sphandle = serial(comPortString,'BaudRate',921600);
set(sphandle,'Terminator', 'LF');
set(sphandle,'InputBufferSize', bufferSize);
set(sphandle,'Timeout',10);
set(sphandle,'ErrorFcn',@dispError);
fopen(sphandle);
end
function [sphandle] = Controlserialport(comPortNum,~)
comPortString = ['COM' num2str(comPortNum)];
sphandle = serial(comPortString,'BaudRate',115200);
set(sphandle,'Parity','none') ;
set(sphandle,'Terminator','LF');
fopen(sphandle);
end
  1 commentaire
Ayush Aniket
Ayush Aniket le 12 Juin 2024
Hi Rangga,
Instead of serial function, you can try the serialport function. Refer to the documentation link: https://www.mathworks.com/help/matlab/ref/serialport.html

Connectez-vous pour commenter.

Réponses (1)

Image Analyst
Image Analyst le 12 Juin 2024
If you look in the help, it will tell you. Use serialport instead. I figure you can figure out how to change your code as well as, or better than, I can now that you know the new function to use.
help serial
SERIAL Construct serial port object. SERIAL will be removed in a future release. Use serialport instead. S = SERIAL('PORT') constructs a serial port object associated with port, PORT. If PORT does not exist or is in use you will not be able to connect the serial port object to the device. In order to communicate with the device, the object must be connected to the serial port with the FOPEN function. When the serial port object is constructed, the object's Status property is closed. Once the object is connected to the serial port with the FOPEN function, the Status property is configured to open. Only one serial port object may be connected to a serial port at a time. S = SERIAL('PORT','P1',V1,'P2',V2,...) constructs a serial port object associated with port, PORT, and with the specified property values. If an invalid property name or property value is specified the object will not be created. Note that the property value pairs can be in any format supported by the SET function, i.e., param-value string pairs, structures, and param-value cell array pairs. SERIAL Functions SERIAL object construction. serial - Construct serial port object. Getting and setting parameters. get - Get value of serial port object property. set - Set value of serial port object property. State change. fopen - Connect object to device. fclose - Disconnect object from device. record - Record data from serial port session. Read and write functions. fprintf - Write text to device. fgetl - Read one line of text from device, discard terminator. fgets - Read one line of text from device, keep terminator. fread - Read binary data from device. fscanf - Read data from device and format as text. fwrite - Write binary data to device. readasync - Read data asynchronously from device. SERIAL port functions. serialbreak - Send break to device. General. delete - Remove serial port object from memory. inspect - Open inspector and inspect instrument object properties. instrcallback - Display event information for the event. instrfind - Find serial port objects with specified property values. instrfindall - Find all instrument objects regardless of ObjectVisibility. isvalid - True for serial port objects that can be connected to device. stopasync - Stop asynchronous read and write operation. SERIAL Properties BaudRate - Specify rate at which data bits are transmitted. BreakInterruptFcn - Callback function executed when break interrupt occurs. ByteOrder - Byte order of the device. BytesAvailable - Specifies number of bytes available to be read. BytesAvailableFcn - Callback function executed when specified number of bytes are available. BytesAvailableFcnCount - Number of bytes to be available before executing BytesAvailableFcn. BytesAvailableFcnMode - Specifies whether the BytesAvailableFcn is based on the number of bytes or terminator being reached. BytesToOutput - Number of bytes currently waiting to be sent. DataBits - Number of data bits that are transmitted. DataTerminalReady - State of the DataTerminalReady pin. ErrorFcn - Callback function executed when an error occurs. FlowControl - Specify the data flow control method to use. InputBufferSize - Total size of the input buffer. Name - Descriptive name of the serial port object. ObjectVisibility - Control access to an object by command-line users and GUIs. OutputBufferSize - Total size of the output buffer. OutputEmptyFcn - Callback function executed when output buffer is empty. Parity - Error detection mechanism. PinStatus - State of hardware pins. PinStatusFcn - Callback function executed when pin in the PinStatus structure changes value. Port - Description of a hardware port. ReadAsyncMode - Specify whether an asynchronous read operation is continuous or manual. RecordDetail - Amount of information recorded to disk. RecordMode - Specify whether data is saved to one disk file or to multiple disk files. RecordName - Name of disk file to which data sent and received is recorded. RecordStatus - Indicates if data is being written to disk. RequestToSend - State of the RequestToSend pin. Status - Indicates if the serial port object is connected to serial port. StopBits - Number of bits transmitted to indicate the end of data transmission. Tag - Label for object. Terminator - Character used to terminate commands sent to serial port. Timeout - Seconds to wait to receive data. TimerFcn - Callback function executed when a timer event occurs. TimerPeriod - Time in seconds between timer events. TransferStatus - Indicate the asynchronous read or write operations that are in progress. Type - Object type. UserData - User data for object. ValuesReceived - Number of values read from the device. ValuesSent - Number of values written to device. Example: % To construct a serial port object: s1 = serial('COM1'); s2 = serial('COM2', 'BaudRate', 1200); % To connect the serial port object to the serial port: fopen(s1) fopen(s2) % To query the device. fprintf(s1, '*IDN?'); idn = fscanf(s1); % To disconnect the serial port object from the serial port. fclose(s1); fclose(s2); See also SERIAL/FOPEN. Documentation for serial doc matlab/serial Folders named serial matlab/serial

Produits


Version

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by