Interfacing with Matlab

R

Thread Starter

reynold

i want to use matlab to talk to one sensor, before using matlab, i already use hyper terminal program to get the data from sensor to Pc, the requested protocol is to send instruction"00 02 3B AA", however i can not get the response of the sensor. can somebody help me?the matlab code is listed below,

g = serial('COM3');
%set(s,'BaudRate',19200);
%s = serial('COM3','BAUD',19200);
!mode com3:19200,n,8,1
fopen(g);
as=['00','02','3B','AA'];
fwrite(g,as,'uint8');
mydata=fread(g,7,'uint8');
fclose(g)
delete(g)
clear g
 
J
Be sure that you are writing Hexadecimal characters to the serial ports. Check the matlab sintax of this instruction as=['00','02','3B','AA']. Look that you are writing ascii characters instead hexadecimal.
 
Have you checked whether the serial() call and the fopen() calls are succeeding? fopen() is most likely failing and the code is not catching that.

What kind of COM port connection are you using? is it usb to com port? Check the communication settings (flow control, parity stop bit, etc.).

I have sometimes found numerous issues with third-party usb to comport adapters. They are only as good as the drivers they write....
 
Top