MATLAB Answers

How to communicate with instrument using USB port

조회 수: 217(최근 30일)
BSantos
BSantos 23 Jul 2014
답변: ozgur yildiz 23 Oct 2018
Hello all!
Is there anyone who knows how to establish communication between Matlab and Intrument using USB port? I have the drivers of the instrument installed, but still not able to communicate with it.
Anyone who can help? I have never done this before...
Thank you!

  댓글 수: 2

Michael Haderlein
Michael Haderlein 23 Jul 2014
Did you check the Instrument Control Toolbox? I've personally never worked with it, but it looks as if you'd need to create a VISA-USB object. Then you can read and write messages as shown in the toolbox help. Everything else will strongly depend on your instrument.
BSantos
BSantos 23 Jul 2014
Dear Michael,
I did check it, but no budget to buy it. So, I was asked to do it, without. That Toolbox looked very handy but for now it's not an option...

댓글을 달려면 로그인하십시오.

답변(3개)

Jasmine
Jasmine 23 Jul 2014
First you'll need to open of the port. See fopen(serial) for help with this. You should be able to work out which COM port your instrument is on using device manager (assuming you are working on a windows platform). If for example you found it was on COM3 try fopen(COM3) . You could then use COM3.status to see if the port had opened, or try typing instrfind at the command line. Then how you communicate with it will depend on your instrument and what commands it understands. You may need to use fprintf(serial) to write text to a device or fwrite(serial) to write binary data to a device. See http://www.mathworks.co.uk/help/matlab/ref/serial.fwrite.html it has links to most functions for use with serial devices.

  댓글 수: 3

BSantos
BSantos 23 Jul 2014
Dear Jasmine,
thank you for your answer. I have tried some of these before but still not able to establish a successful communication.
s = serial('COM3');
fopen(s);
set(s,'BaudRate',9600);
fprintf(s,'*IDN?<cr><lf>');
out = fscanf(s);
But then, I get this warning message:
Warning: Unsuccessful read: A timeout occurred before the Terminator was reached.
I think this is an easy problem to solve for those who re used to work in this environment, but for me this is totally new. :)
Joseph Cheng
Joseph Cheng 23 Jul 2014
What instrument are you trying to talk to?
BSantos
BSantos 23 Jul 2014
A Pulse Generator: Quantum Composer 9520 Series.

댓글을 달려면 로그인하십시오.


Jasmine
Jasmine 23 Jul 2014
Sounds like it is a terminator property problem. Try:
set(s,'Terminator',<cr><lf>);
and change your code to:
s = serial('COM3');
fopen(s);
set(s,'BaudRate',9600);
fprintf(s,'*IDN?');
out = fscanf(s);

  댓글 수: 1

BSantos
BSantos 25 Jul 2014
Unfortunately, I can't change the code to your suggestion or what's on the example because that's not the syntax that my instrument uses. I have tried your suggestion About the terminator property but still no success.
Always get the same Warning message!
Anyone out there who might have worked with Quantum Composer 9520 Pulse Generator?
Thanks!

댓글을 달려면 로그인하십시오.


ozgur yildiz
ozgur yildiz 23 Oct 2018
It is not a classic serial connection. Probably the device you want to connect, is identified by your computer since you've already installed the drivers (SDK) of the device. So you cannot see any occupied comport in Device Manager instead you can see the Device ID on one of the USB hub. So First you should indentify 'xxx.dll' files of the device in Matlab environment.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by