フィルターのクリア

Error message not connected

5 ビュー (過去 30 日間)
Fiboehh
Fiboehh 2011 年 5 月 13 日
Hellow, im working with two motors for a project and they are connected via the Control instrument toolbox. Now i have used it in my gui, so the motor connect before the figure is shown. So in the function density_CreateFcn. But know, there must be a fault message when the gui starts and the motors arent connected properly. Anyone who has experience with this? Thx in advance

採用された回答

Matt Fig
Matt Fig 2011 年 5 月 13 日
t = serial(...) % Try to open the connections.
u = serial(...)
try
fopen(...)
catch
errordlg('First Motor not connected properly.', 'Connect Error');
end
try
fopen(...)
catch
errordlg('Second Motor not connected properly.', 'Connect Error');
end
Now you should put a pushbutton on the GUI which has the same above code in the callback. Perhaps one pushbutton for each motor.
  2 件のコメント
Walter Roberson
Walter Roberson 2011 年 5 月 13 日
The serial port version of fopen() has no outputs: if there is a problem it throws an error.
Matt Fig
Matt Fig 2011 年 5 月 13 日
Oh yeah, oops... Long day...

サインインしてコメントする。

その他の回答 (3 件)

Sean de Wolski
Sean de Wolski 2011 年 5 月 13 日
If the motor isn't connected it will error when it tries to connect to it because it won't be able to.
Post the full error message text for a more pinpointed response.

Walter Roberson
Walter Roberson 2011 年 5 月 13 日
I suspect that the answer you are looking for is that you should use a "try/catch" block around the fopen() for each of the motors. Though depending how you are finding the device information for the motors, you might be able to partly detect the condition earlier (e.g., if you only detect one COM port then you know that you don't have two motors connected.)

Fiboehh
Fiboehh 2011 年 5 月 13 日
The motors are connected like this:
t = serial('COM1','BaudRate',57600,'DataBits',8,'Stopbits',1,'ErrorFcn','Fout opgetreden!','Parity','none','FlowControl','none'); % rotations- motor
u = serial('COM3','BaudRate',112500,'DataBits',8,'Stopbits',1,'ErrorFcn','Fout opgetreden!','Parity','none','FlowControl','none'); % microcontroller
fopen(t)
fopen(u)
Now i want a message box that gives a error : 'Serial connection not established, please check connections and try again.' And a button to try if the new connection works. Maybe a try/catch is good, but i dont now how to make the error box for the gui.
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 5 月 13 日
The specific error for serial() failing to create the internal java object is MATLAB:serial:serial:cannotCreate
The specific error for serial fopen failing to open the internal java object is MATLAB:serial:fopen:opfailed
You can create an error dialog with
ed = errordlg({'Serial connection not established.', 'Please check connections and try again'});
uiwait(ed);

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by