0
votes

I'm using TSI flowmeter 4040, which use an RS232 serial COM port (38400 baud rate, 8 data bits, 1 stop bit, none polarity, none flow control). Flowmeter data format is ASCII.

According to the datasheet, in PuTTY, I need to type the command DAFxx1000 to get 1000 data readings from the flowmeter. Now, I tried to do the same way in MATLAB. The connection is successful. However, I cannot get sensor data reading (see image). Anyone knows why, please?

Thanks!

MATLAB screenshot

1
Could it be the terminator? See this for details. - wwweagle
Did you try just waiting? You're sending the readline command as soon as you send the writeline one, so maybe the instrument does not yet have 1000 data readings available to return? - Matteo V
I agree with pausing the function a bit between sending your requesting and reading the response. Also, you may need to set the other properties of the serialport - data bits, stop bits etc because the default values in MATLAB may not match the instrument specifications. Lastly, read the manual for what the terminating character is if any. - falopsy

1 Answers

0
votes

Problem solved. TSI 4040 flowmeter is a bit special. It returns: OK (change line) data1,data2,data3 (change line) So I need to use the following MATLAB command:

% Show all available COM serial ports on the PC
serialportlist

% Set COM serial port, baud rate
%{ 
Default setting: 
Baud rate: 38400
Data bits: 8 bits
Stop bit: 1 bit
Parity: None
Flow control: None
Timeout: 10 seconds
%}
s = serialport("COM1",38400);


% Set terminator for ASCII string communication
% CR = Carriage Return
% LF = Line Feed
configureTerminator(s,"CR/LF");


% Display the terminator 
s.Terminator


%% We MUST manually stop the while loop when it's finished
%{
Steps: 
1. Send command to TSI flowmeter 
2. Read and save data to the string array: OK (change line)
3. Read and save data to the string array: flowmeter return data
%}
i = 1;
while 1
    writeline(s,"DAFTP0100");

    OK(i) = readline(s);
    data(i) = readline(s);
    i = i + 1;
end