<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264806</link>
    <title>MATLAB Central Newsreader - Rs232 hardware communication,  fprintf</title>
    <description>Feed for thread: Rs232 hardware communication,  fprintf</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 03 Nov 2009 05:28:03 -0500</pubDate>
      <title>Rs232 hardware communication,  fprintf</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264806#691640</link>
      <author>zhang mian</author>
      <description>Hi,&lt;br&gt;
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 &lt;br&gt;
fprintf(serobj,'rat 6'), the speed of the motor will change to 6ml/hr from 1ml/hr. &lt;br&gt;
&lt;br&gt;
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?</description>
    </item>
    <item>
      <pubDate>Tue, 03 Nov 2009 14:41:38 -0500</pubDate>
      <title>Re: Rs232 hardware communication,  fprintf</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/264806#691727</link>
      <author>Steven Lord</author>
      <description>&lt;br&gt;
&quot;zhang mian&quot; &amp;lt;zhangmian0126@126.com&amp;gt; wrote in message &lt;br&gt;
news:hcof12$gn8$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; I am doing a hardware real time control through rs232 in M-file. The &lt;br&gt;
&amp;gt; problem is when i put fprintf(serobj,'rat 1'),the motor will run at a &lt;br&gt;
&amp;gt; speed 1ml/hr but if the speed is calculated by my program and represented &lt;br&gt;
&amp;gt; by variable 'u1', i put it like fprintf(serobj,'rat u1')  the hardware &lt;br&gt;
&amp;gt; will not response to it. Even it shows u1=12.25 or sth else, i put the &lt;br&gt;
&amp;gt; fprintf(serobj,'rat u1'), the motor still run at a default speed 1ml/hr. I &lt;br&gt;
&amp;gt; change it to&lt;br&gt;
&amp;gt; fprintf(serobj,'rat 6'), the speed of the motor will change to 6ml/hr from &lt;br&gt;
&amp;gt; 1ml/hr.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; The hardware technician said he was not familiar with Matlab but if the &lt;br&gt;
&amp;gt; program is written in C, the function should be fprintf(serobj,'rat &lt;br&gt;
&amp;gt; %f',u1). But it seems the Matlab doesn't accept this format. It only can &lt;br&gt;
&amp;gt; be fprintf(serobj,format,variable), in this format the whole variable will &lt;br&gt;
&amp;gt; become same format, number or character ect. Now i need the 'rat' in &lt;br&gt;
&amp;gt; character format but the u1 in a float-point format, what can i do?&lt;br&gt;
&lt;br&gt;
From the documentation for the serial object's FPRINTF method, the first &lt;br&gt;
syntax you gave in the second paragraph is the correct syntax.&lt;br&gt;
&lt;br&gt;
u1 = 12.25;&lt;br&gt;
fprintf(serobj, 'rat %f', u1)&lt;br&gt;
&lt;br&gt;
Can your motor accept noninteger values for the 'parameter' of the rat &lt;br&gt;
function?  Try:&lt;br&gt;
&lt;br&gt;
u1 = 6;&lt;br&gt;
fprintf(serobj, 'rat %f', u1)&lt;br&gt;
&lt;br&gt;
Does it expect the parameter after rat to be in a particular format, say an &lt;br&gt;
integer (as per the C %d specifier?)&lt;br&gt;
&lt;br&gt;
u1 = 6;&lt;br&gt;
fprintf(serobj, 'rat %d', u1)&lt;br&gt;
&lt;br&gt;
Does it have an upper limit on its speed that is lower than 12.25?&lt;br&gt;
&lt;br&gt;
u1 = 1.5;&lt;br&gt;
fprintf(serobj, 'rat %f', u1)&lt;br&gt;
&lt;br&gt;
Does the motor have the capability to return status/diagnostic information &lt;br&gt;
if you give it something it doesn't expect?&lt;br&gt;
&lt;br&gt;
-- &lt;br&gt;
Steve Lord&lt;br&gt;
slord@mathworks.com&lt;br&gt;
comp.soft-sys.matlab (CSSM) FAQ: &lt;a href=&quot;http://matlabwiki.mathworks.com/MATLAB_FAQ&quot;&gt;http://matlabwiki.mathworks.com/MATLAB_FAQ&lt;/a&gt; </description>
    </item>
  </channel>
</rss>

