|
"MIKE AUTHERTON" <satautherton@rediff.com> wrote in message
news:ijbmjk$flo$1@fred.mathworks.com...
> "Trent Jarvi" wrote in message <ij3ioa$it9$1@fred.mathworks.com>...
>>
>>
>> "MIKE AUTHERTON" <satautherton@rediff.com> wrote in message
>> news:<ij1l1k$cm4$1@fred.mathworks.com>...
>>
>> > New to matlab and programming. Trying to interface a range sensor
>> > through serial port using matlab. The intention is to send the
>> > commands(about four binary strings with each receiving a response)
>> > through the port and read the output from the sensor continously.
>>
>> >
>>
>> > My code for single command after reading matlab help
>>
>> >
>>
>> > S=serial('COM1','Baudrate',9600);
>>
>> > fopen(S);
>>
>> > fwrite(S,'1.............10');
>>
>> > fprintf(S,'*IDN?');
>>
>> > out=fscanf(S);
>>
>> > fclose(S);
>>
>> > delete(S);
>>
>> > clear S;
>>
>> >
>>
>> > but i did get the values from the sensor a few times, sometimes only 30
>> > bits are received but mostly no data is being read. messages
>>
>> >
>>
>> > A timeout occurred before the terminator was reached
>>
>> > and\\The specified amount of data was not returned in the time period
>>
>> >
>>
>> > how to go about this????
>>
>>
>>
>> Hi Mike,
>>
>>
>>
>> FSCANF is used to read terminated strings. Newline is usually the
>> termination character (ASCII 10). '*IDN?' is a SCPI command used to
>> communicate with instruments like Digital Multimeters and Oscilloscopes.
>> The instruments usually return the model and firmware information as a
>> terminated string. If a terminating character is not received, FSCANF
>> will continue trying to find one until a timeout occurs (10 seconds by
>> default).
>>
>>
>>
>> Sensors are usually fairly simple. They usually won't have a SCPI
>> interpreter but may respond to specific values to trigger a reading.
>> Sometimes they just transmit the data at regular intervals. The manual
>> will describe those details.
>>
>>
>>
>> To help you get started, You will want to use FREAD to obtain the data
>> currently available and then try to convert that into the form you
>> require.
>>
>>
>>
>> while( S.BytesAvailable == 0 )
>>
>> pause(0.1);
>>
>> end
>>
>> out = fread(S, S.BytesAvailable);
>>
>>
>>
>> After reading your sensor manual, you may decide to send some values
>> first and then wait for a specific number of bytes.
>>
>
> Hi Trent,
> Thanks for your inputs, I did read the data
> out from my sensor, but once I power the sensor off and then ON, The
> program no longer works, Is there any way tho increase the buffer bytes
> more than 512?.I have to read a lot of data more than 712 bytes in a
> cycle.
Nice Mike,
It usually takes a while to get a robust solution to handle all conditions
such as power cycling the sensor.
To increase the buffer, just set the InputBufferSize while the serial port
is closed.
fclose(S); % just needed if the port is open. You will probably set the
value prior to opening.
set(S, 'InputBufferSize', 712);
The buffer can be set considerably higher (Mb's).
As you learn more about the serial object, you may find that the following
are handy commands.
set(S) % display all the properties with options and defaults
inspect(S) % graphical visualization of the properties.
|