Communicating with OMEGA HH314A humidity sensor in Matlab *SOLVED*

Hello all, I recently got my hands on an OMEGA HH314A humidity sensor. This communicates with a computer via a RS232 port. It comes with its own proprietary software, however I would like to use matlab to interface with it and receive readings that way. I am able to open up a COM port, however I get a timeout any time I try to read data from the device. My first guess is that perhaps since this device is designed to run off of its own software and driver, that it needs some sort of command before it will send data through the serial port? Trying to figure out what my next steps should be here. I am using version 2007A. Thank you!
- Alex
EDIT: Solved the issue. Played around with a bit of syntax and ended up with this:
s = serial('COM3','BaudRate',9600);
fopen(s);
fwrite(s,'A'); %prompts device to send data
pause(1);
fwrite(s,'c'); %prompts device to stop sending data
for i = 1:7
arr(i,1) = fread(s,1); %put each byte into an array
end
humidity = ((arr(4,1)*255)+ arr(5,1))/10; %convert values
temp = ((arr(6,1)*255)+ arr(7,1))/10; %convert values
fclose(s);

3 Comments

Update: I called the company and got a protocol sheet for the device, but I am still getting timeout errors. Code is as follows:
s=serial('com1');
set(s,'BaudRate',9600,'DataBits', 8, 'Parity', 'none','StopBits', 1, 'FlowControl', 'none','Terminator','CR','Timeout',10);
fopen(s);
fwrite(s, 'E'); % this starts recording data into the device
fscanf(s);
fwrite(s, 'P'); % this returns recorded data
Once I input fscanf(s); it hangs for a bit and then I get a timeout...should I be returning the data before I scan or while its scanning? Or does it go deeper than that...thank you.
I would experiment with
fprintf(s, 'E\n')
and
fprintf(s, 'E\r')
and
fprintf(s, 'E\r\n')

Sign in to comment.

Answers (0)

Categories

Find more on Instrument Control Toolbox in Help Center and File Exchange

Asked:

on 19 Jun 2017

Edited:

on 21 Jun 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!