Communicating with a device

19 views (last 30 days)
Hello everybody!
I am completely new to this problem. I have a digital weighing scale(a load cell hooked to a digital monitor) and I would like for MatLab to recognize it and communicate. Load cell is connected to the digital monitor and the monitor to my laptop. The connection is RS232, but I have a converter to USB, since my laptop does not support RS232.
So if someone could just stir me in the right direction, because I have no idea where to begin.
I'm guessing Instrument Control Toolbox? I have all the necessary info on the scale and it's outputs.
Anyone?

Accepted Answer

Walter Roberson
Walter Roberson on 27 Nov 2011
Please see my Answer to this question to see the general procedures for working with serial ports. That particular question is focused on communication with a robot, but the outline I gave there applies to your case.
You will not need the Instrument Control Toolbox.
You will need to have your digital scale connected up before your start your MATLAB session, and you will need to take in to account that the device name of a USB device is not constant. See instrfind() to retrieve the list of serial devices.
  2 Comments
Slobodan Djordjevi?
Slobodan Djordjevi? on 2 Dec 2011
Walter thank you for this!
But I still have several questions...
I don't think my code below recognizes the scale. The scale is connected via (RS232 - USB) to COM6(looked up in Device manager).
The scale monitor now is showing 0.00kg. How do I get this information to .txt file.
The Code :
clc;
clear all;
s1 = serial('COM6'); % define serial port
s1.BaudRate=9600; % define baud rate
set(s1, 'terminator', 'LF'); % define the terminator for println
fopen(s1);
data = fgetl(s1, '%s');
fid = fopen('tehtnica.txt', 'wt');
fprintf(fid, '%s', data);
fclose(fid);
fclose(s1);
Help me on this one, please!
Walter Roberson
Walter Roberson on 2 Dec 2011
fgetl() does not accept a format: it always returns a string.
You might want to change your output format to
fprintf(fid, '%s\n', data);
I do not know how your scale operates; it would be common for you to need to send a command to the scale to provoke it to send the current reading back.

Sign in to comment.

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!