Professional Documents
Culture Documents
陳彥穆
July 19, 2007
Outline
Computer-based Measurement Automation
{ Design Flow
{ A Comprehensive Overview & some history
Labview
{ Introduction
{ Control Examples –
Matlab
{ Introduction
{ Control Examples – Graphic User Interface Design
Comparison
{ Merits and Defects
{ Hybrid
Instrument Control !?
The abilities to
Write
Write some bits or bytes to the instruments as commands
Read
Read information or measured data from the instruments
Instrument Control !?
In order to do that, we require
Interface
Physical connections between computers and instruments
Interface driver
It tells computers how to interpret the data on the interface
( Protocols )
Instrument Control !?
and we still need
Command book
The language of “the” instrument.
We call a complete and well-capsulated command set as
“Instrument Driver.”
Control Program
combinations of commands to finish our job
Why?
Instruments • Resolution?
Dynamic Range?
Field of View?
• Instrument Interface
Programming Language /
Programming • VB, C/C++, VC.Net, BCB…
Environment • Matlab
• Labview
Instrument Command
Interface Drivers • Serial port driver
• GPIB driver
• USB driver
User Interface
• Instrument Command
Testing
Problem Define: The control flow chart
A sample control flow chart
Problem Define: Nature of signal
Type
{ Electro-
voltage/current
impedance
{ Photon
wavelength
Magnitude
Duration
Problem Define: Instruments
Resolution
{ Intensity
{ Time response of instrument
Dynamic Range
{ Intensity
{ Frequency
Field of View
Instrument Interface
{ Crate Instrument: CAMAC / VXI / PXI
{ GPIB / RS-232 / USB / IEEE1394
{ PCI / ISA
A real example:
measure laser contrast automatically
A real example-
measure laser contrast automatically
Control Flow Chart
A real example-
measure laser contrast automatically
The Instruments
A real example-
measure laser contrast automatically
The Instruments
text-based languages
{ C/C++, VC.Net, BCB
{ Visual Basic
{ Matlab (Scientific environment)
Interface Drivers
{ Serial port driver
{ GPIB driver
{ USB driver …
{ VISA (Virtual Instrument Software Architecture)
Instrument Command
{ SCPI (Standard Commands for Programmable Instrumentation)
{ VXI Plug&Play
{ IVI (Interchangeable Virtual Instrument )
{ Instrument specific command
Part-II: History
A Comprehensive Overview of Measurement
Automation
Register-based command
H
fo P d
ri e
ns sig
tru ns
m H
1965
en P
ta -IB
ti o
n
sy
H st
Automation
s t P- I em
an B s
1975
da be
rd co
m
es
IE
EE
IE -4
88
1987
EE
.1
48
8.
2
Text-based command
ad
op
te
For monolithic instruments
SC d
1990
fo P
rI IS
EE p
E e ci
48 fic
8 ati
in on
st
ru int
1993 IE m ro
en du
EE
ts ce
48 d
8.
2
St
GPIB (General Purpose Interface Bus / IEEE-488)
an
da
rd
re
A Comprehensive Overview of Measurement
vi
se
d
A Comprehensive Overview of Measurement
Automation
Text-based / Register-
based command
擷取自
Matlab Instrument Control Toolbox Help documents
A Comprehensive Overview of Measurement
Automation
Serial Port
RS-232 COM1
very common on personal computers
Parallel Port
printer port LPT
Difficulties in developing a measurement
automation system
Non-Interchangeable
Time inefficient
A Comprehensive Overview of Measurement
Automation
{ Same I/O function for open, send, read, query, close…, but
not same command.
Utilizing VISA to achieve interface I/O (other interface drivers are also available)
IVI defines several Instruments class to achieve same “command”
( just like SCPI)
{ DC power supply
{ Digital multimeter (DMM)
{ Function generator & Arb
{ Oscilloscope
{ Power meter
{ RF signal generator
{ Spectrum analyzer
{ Switch
The IVI Config server – for instrument interchangeability
{ Two instruments with different vendors, different interfaces (e.g.
GPIB and USB) can be interchanged just in a few minutes.
The Structure
Software
Application
Hardware
Instrument Hardware
Part-III: LabVIEW
What is LabVIEW?
VI : Virtual Instrument
The block diagram can include functions and structures from the built-in
LabVIEW VI libraries. It also can include terminals that are associated with
controls and indicators created on the front panel.
Front panel demo: a virtual instrument
…\examples\apps\demos.llb\Two Channel Oscilloscope.vi
Controls and indicators
Palettes
Functions Palette Controls Palette
LabVIEW palettes give
you the options you need
to create and edit your
front panel and block
diagram. Tools Palette
z = sqrt(abs(x)) + y;
D = A AND (B OR C)
diagram panel
Comparison and CASE structure
if a > b then
todo list 1……
else
todo list 2……
end
FOR loop
a=1;
for (i=0, i<6, i++){
a=a+a*i;
}
Output = 720
Sequence and While loop
1. Port number:
port number = 0 for COM1, 1 for COM2
2. Baud rate (or bits per sec, bps)
3. Data bits: number of bits in the incoming data
4. Number of stop bits
5. Parity bit? (None, Odd, Even)
6. Command characters used by the device
Marking level
Spacing level
Time
8 data bits
Parity bit
VISA Open
Open the VISA channel according
the VISA resource name
VISA Close
Close the VISA channel according
the VISA resource name
Serial Port VIs (Cont.)
VISA Read
VISA Write
>>help gpib
GPIB Construct GPIB object.
OBJ = GPIB('VENDOR',BOARDINDEX,PRIMARYADDRESS) constructs a
GPIB object, OBJ, associated with board index, BOARDINDEX, and
instrument primary address, PRIMARYADDRESS. The primary address
can range between 0 and 30. The GPIB hardware is supplied by
VENDOR. Supported vendors include:
'agilent' - Agilent Technologies hardware.
'cec' - Capital Equipment Corporation hardware.
'contec' - CONTEC hardware.
'ics' - ICS Electronics hardware.
'iotech' - IOTech hardware.
'keithley' - Keithley hardware.
'mcc' - Measurement Computing Corporation (ComputerBoards) hardware.
'ni' - National Instruments hardware.
.
.
.
H
fo P d
ri e
ns sig
tru ns
m H
1965
en P
ta -IB
ti o
n
sy
H st
s t P- I em
an B s
1975
da be
rd co
m
es
IE
EE
IE -4
88
1987
EE
.1
48
8.
2
Text-based command
ad
op
te
For monolithic instruments
SC d
1990
fo P
rI IS
EE p
E e ci
48 fic
GPIB (IEEE-488) bus history
8 ati
in on
st
ru int
1993 IE m ro
en du
EE
ts ce
48 d
8.
2
St
GPIB (General Purpose Interface Bus / IEEE-488)
an
da
rd
re
vi
se
d
Pin assignment of GPIB
Listeners can only receive data and commands from the bus.
Attention
Talker
Data Valid
Talker
Listener
Not Ready For Data
Listener
Not Data Accepted
ATN: Attention
Asserted by controller to indicate that the data bus holds a
command rather than data.
%Suppose we have a serial port ‘com1’, and we want to set its BaudRate to
%1200
>>s1 = serial('COM1', 'BaudRate', 1200)
>>fopen(s1)
% To query the instrument.
>>fprintf(g, '*IDN?'); %Identify yourself or else…
>>idn = fscanf(s1);
% To disconnect the serial port object from the instrument.
>>fclose(s1);
Matlab vs. Labview
fopen(s1)
fprintf(g, '*IDN?');
fscanf(s1);
fclose(s1);
How to use VISA interface
•MATLAB has it own GPIB and serial port driver, but
you can still use the version in VISA library (vmtool)
>>inspect(s) %GUI tool for checking all the properties of this object
Basic building blocks of GUI
and Event-driven programming in Matlab
圖擷取從 MATLAB程式設計與應用-張智星
Basic building blocks of GUI
and Event-driven programming in Matlab
Callback functions
figure
h = uicontrol(gcf,'Style','Push','position',[50 20 80 30],'string',‘Push');
cmd = 'fprintf(''Somebody pushed me!\n'');';
set(h, 'Callback', cmd);
擷取從 MATLAB程式設計與應用-張智星
Some useful commands
findobj
Locate graphics objects with specific properties
gcf
Get current figure handle
gca
Get current axes handle
gcbo
Return handle of object whose callback is executing
set / get
set / get properties of object
Measurement Automation in Matlab
High Voltage Main Frame
Retard.m
Serial Port
LPT
Pin2 and pin7 PC
FireBox
MATLAB
Pressure
Watcher
GPIB
Laser Intensity
monitor
Oscilloscope
Laser System
MCP
grid
Part-V: Comparison
Labview > Matlab
Labview
{ G-Language (Graphic)
{ great GUI
{ fast response
{ Multi-threading-embedded
Matlab
{ M file (Text)
{ Limited GUI
{ Interpreter (Slow)
{ Single threading (M file)
readasync
Matlab
{ M file (Text), handle string well
{ Unlimited algorithms and it’s easy to add your own
{ It’s easy to modified your subroutine
{ Comment and Documentation
Labview
{ lots of algorithms but it takes a while to locate it.
“draw” another one?
{ Connector adding Show dataprocess.vi
{ It is messy to write documentation
Matlab == Labview
Matlab
{ Instrument Control ability
Serial port, GPIB interface, VISA driver
Instrument Driver, tmtool
{ Instrument driver editor – write your own or load it from IVI driver
Labview
{ Instrument Control ability
Serial port, GPIB interface, VISA driver
Instrument Driver, IVI, MAX
MATLAB Instrument Driver
>>midedit
Labview
{ DLL Invoke node
{ ActiveX Invoke node
{ Matlab Script node
{ CIN Code Interface Node – to call C code
DLL Invoke node