Hi
Tried doing something.
after taking a brush up from The serial port session in ' help' section of matlab i tried modifying your above code accordingly
%Create a serial port object — Create a serial port object for a specific serial port using the serial creation function.
%Configure properties during object creation if necessary. In particular, you might want to configure properties associated with serial port communications such as the baud rate, the number of data bits, and so on.
%Connect to the device — Connect the serial port object to the device using the fopen function.
%After the object is connected, alter the necessary device settings by configuring property values, read data, and write data.
%Configure properties — To establish the desired serial port object behavior, assign values to properties using the set function or dot notation.
%In practice, you can configure many of the properties at any time including during, or just after, object creation. Conversely, depending on your device settings and the requirements of your serial port application, you might be able to accept the default property values and skip this step.
%Write and read data — Write data to the device using the fprintf or fwrite function, and read data from the device using the fgetl, fgets, fread, fscanf, or readasync function.
%The serial port object behaves according to the previously configured or default property values.
%Disconnect and clean up — When you no longer need the serial port object, disconnect it from the device using the fclose function, remove it from memory using the delete function, and remove it from the MATLAB® workspace using the clear command.
disp('Start');
s = serial('COM3'); %port creation
set(s,'BaudRate',9600,'DataBits',8,'Parity','none' ,'StopBits',1,'FlowControl','none','InputBufferSize',102400) % serial port properties
fopen(s); % connecting to a device using fopen
s.ReadAsynMode='Continuous'; % mode of reading
readasync(s1);
l=[hex2dec('AB1F'); % input data
l=char(l);
fwrite(s,l); %sending data to micro controller
w=fread(s,1,'unchar') %reading from the port a value at a atime
stopasync(s)
fclose(s)
delete(s)
clear s
disp('end');
it was executed but with error "??? Error using ==> serial.fopen at 71
Port: COM3 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device."
Will look more and try to come up with something more working!! 😀 meanwhile if you have nay updates do post on!!!
Are you sure? This action cannot be undone.