|
"zhang mian" <zhangmian0126@126.com> wrote in message
news:hcof12$gn8$1@fred.mathworks.com...
> Hi,
> I am doing a hardware real time control through rs232 in M-file. The
> problem is when i put fprintf(serobj,'rat 1'),the motor will run at a
> speed 1ml/hr but if the speed is calculated by my program and represented
> by variable 'u1', i put it like fprintf(serobj,'rat u1') the hardware
> will not response to it. Even it shows u1=12.25 or sth else, i put the
> fprintf(serobj,'rat u1'), the motor still run at a default speed 1ml/hr. I
> change it to
> fprintf(serobj,'rat 6'), the speed of the motor will change to 6ml/hr from
> 1ml/hr.
>
> The hardware technician said he was not familiar with Matlab but if the
> program is written in C, the function should be fprintf(serobj,'rat
> %f',u1). But it seems the Matlab doesn't accept this format. It only can
> be fprintf(serobj,format,variable), in this format the whole variable will
> become same format, number or character ect. Now i need the 'rat' in
> character format but the u1 in a float-point format, what can i do?
From the documentation for the serial object's FPRINTF method, the first
syntax you gave in the second paragraph is the correct syntax.
u1 = 12.25;
fprintf(serobj, 'rat %f', u1)
Can your motor accept noninteger values for the 'parameter' of the rat
function? Try:
u1 = 6;
fprintf(serobj, 'rat %f', u1)
Does it expect the parameter after rat to be in a particular format, say an
integer (as per the C %d specifier?)
u1 = 6;
fprintf(serobj, 'rat %d', u1)
Does it have an upper limit on its speed that is lower than 12.25?
u1 = 1.5;
fprintf(serobj, 'rat %f', u1)
Does the motor have the capability to return status/diagnostic information
if you give it something it doesn't expect?
--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
|