serial communication problem is not working in .mat file
Afficher commentaires plus anciens
hi i want send 1 and 0 to arduino from matlab with usb and blink the led when 1 receveing and 0 receceing it is not blink my code be like
s = serialport("COM10",9600);
writeline(s,'1');
clear s
when i am sending from matlab command prompt is sending and bliking the led and when i am send it from .mat file script it is not working any can help the slove the problem
1 commentaire
Mustafa Codur
le 31 Déc 2020
Hello,
the following link includes solution of your problem.
Réponses (2)
Ameer Hamza
le 11 Mar 2020
You should not clear the serial object without closing and deleting it first. It is probably happening that you opened the serial object and then deleted the variable. Now it is open in the background, and you cannot connect to it again with s = serialport("COM10",9600). You should first delete all the serial objects.
delete(instrfind)
Then run the script, and always remember to close the serial object after use
s = serialport("COM10",9600);
fopen(s)
writeline(s,'1');
fclose(s)
9 commentaires
gugu bubu
le 11 Mar 2020
Ameer Hamza
le 11 Mar 2020
Have you defined s by running
s = serialport("COM10",9600);
gugu bubu
le 12 Mar 2020
Ameer Hamza
le 12 Mar 2020
Try running following lines together
delete(instrfind)
s = serialport("COM10",9600);
fopen(s)
writeline(s,'1');
fclose(s)
If you don't get any error than MATLAB is working fine. You need to check the programming of your arduino.
gugu bubu
le 14 Mar 2020
Ameer Hamza
le 14 Mar 2020
Then arduino might not be connected properly to your PC. Or it is connected to some other port. Try finding the correct port number "COMxx".
Walter Roberson
le 1 Jan 2021
serialport() objects cannot be fopen() or fclose() -- those apply to serial() objects, not to serialport() objects.
Catarina Campos
le 3 Juin 2021
Modifié(e) : Catarina Campos
le 3 Juin 2021
@Walter Roberson im sorry to bother, but how do you open and close a serialport object then?
Walter Roberson
le 3 Juin 2021
serialport objects are automatically opened and cannot be closed, and must instead be deleted to close them.
You can tell that whoever designed the interface never did any serious dial-up work, and that whoever approved the interface was not concerned about Mathworks losing users to other more serious device control products.
Mustafa Codur
le 31 Déc 2020
0 votes
Hello,
the following link includes solution of your problem.
Catégories
En savoir plus sur Serial and USB Communication dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!