Serial interfaces (RS232 and USB) for instrument control

advertisement
Serial interfaces
(RS232 and USB)
for instrument control
Serial interface RS232 for instuments
• Alternative to GPIB (IEEE 488)
• Mainly cheap models without GPIB
• + Advantage: for several decades standard interface
in most PCs – availability
• - Potential problem: reimplementation to instruments
with GPIB (as far as possible keeping parts of old
firmware while introducing RS232)
• - Recently: less widely available – replaced by USB)
Serial interface RS232
• Original standart: EIA-RS232-C (1969)
• Today: more recent version of standart: EIA/TIARS232-F, ANSI/TIA/EIA-574, etc…
• Original connector: 25-pin DB-25
• Original use: interconnection between computer
and modem (DTE and DCE)
• PROBLEM: frequent deviations in
implementation details by individual
manufacturers
RS232
DTE
RS232
DCE
PSTN
DCE
RS232
DTE
DTE, Data Terminal Equipment = computer, PC
DCE, Data Circuit-Termination Equipment
(somatimes: Data Communicatiuon Equipment) = modem
PSTN, Public Switched Telephone Network
RS232
Today variant: usually 9-pin connector DB-9
1 - CD, Carrier Detect
2 - RxD, Received Data
3 – TxD, Transmitted Data
4 – DTR, Data Terminal Equipment Ready
5 – SG, Signal Ground
6 – DSR, DCE Ready (Data Set Ready)
7 – RTS (*), Request to Send
8 – CTS, Clear to Send, modem signals readiness
9 – RI, Ring Indicator, incoming call
(*) signal 7 today usually redefined as RFR (see below)
Fig.: http://www.camiresearch.com/Data_Com_Basics/RS232_standard.html
RS232 cable interconnection
a) connection DTE-DCE: cable „1:1“, „connector extender“
Use:
usually: connection PC - modem
rarely: PC - instrument (not typical, rare solution)
RS232 cable interconnection
b) connection DTE-DTE: today much more typical
SG
TxD
TxD
RxD
RxD
Interconnection by crossover cable („null modem“):
Minimally: TxD -> RxD and vice versa (at least SW handshake)
Usually also: CTS -> RTS (RFR) and vice versa (HW handshake)
Use: PC - instrument
SW Handshake (DTE-DTE)
Software hanshake: exchange of special characters Xon, Xoff
- text transmission only
- not for binary data (random occurrence of Xon or Xoff in data)
SG
TxD
TxD
RxD
RxD
Minimal implementation: 3 wires
HW Handshake (DTE-DTE)
Hardware hanshake: exchange of enabling signals RTS-CTS
Originally (DTE-DCE interface): request for transmission, clearance for
transmission, i.e. single-sided data flow control. DTE cannot stop receiving.
Today (DTE-DTE interface) redefinition of RTS signal: RFR – Ready for
receiving. Enables mutual data flow control. Sometimes DSR and DTR signals also
used.
SG
TxD
TxD
RxD
RxD
CTS
CTS
RTS
RTS
Minimal implementation: 5 wires
Signal levels RS232
U
WARNING: inverse logic
+15V
SPACE, Log. 0
+3V (receiver), +5V (transmitter)
Forbidden zone
t
-3V (receiver), -5V (transmitter)
MARK, Log. 1
-15V
1
0
1
Conversion from microprocessor logic levels (TTL 0-5V): e.g. MAX232 chip, etc…
Transmission in frames
Quiet state -> Start bit -> N bits data -> (Parity if used) -> Stop bit(s) = Quiet state
(Logic:)
1
0
Quiet
Start LSB
1
MSB Par
Stop Quiet
Resynchronization of receiver clock
(Voltage:)
+
Start LSB
-
MSB Par
1
Stop
Frame composition
• Every frame starts with 1 Start bitem (transition from quiet state
to log. 0 for resynchronization of receiver clock)
• Follows N bits of data (typically 7 or 8, rarely other count), first
the least significant bit (LSB), last the most significant bit (MSB)
• Follows one bit of parity (if enabled)
– Choice: None, Even, Odd, Mark (always 1), Space (always 0)
• Follows 1 (or more) Stop bits (transition back to quiet state)
• MUST agree frame format setting of transmitter and receiver,
including data rate (Baud rate)
• Otherwise -> framing error reported by receiver (unexpected
values measured at key control bit intervals)
Baud rate
• Baud rate = Symbol rate (rate of encoding impulses at
physical layer)
• Not the same as effective data bit rate
– Generally (not for RS232) 1 symbol may encode multiple
bits (QAM-type modulation etc…)
– for RS232 1 pulse = 1 bit, BUT: additional start bit, parity,
stop bit(s), inter-frame delay, …
• Standart baudartes: 75, 110, 300, 1200, 2400, 4800, 9600,
19200, 38400, 57600, 115200
Waveform examples
9600Bd i.e. 1 bit (symbol) = 104 us, 8 bit, No Parity
Character = 0x0F = 0000 1111bin = 15dec
S
SPACE, Log. 0
MARK, Log. 1
1
1 1
1 0
0
0
0 Stop
Waveform examples
9600Bd i.e. 1 bit (symbol) = 104 us, 8 bit, No Parity
Character = 0xAA = 1010 1010bin = 170dec
S
SPACE, Log. 0
MARK, Log. 1
0
1 0
1 0
1
0
1 Stop
Waveform examples
2400Bd i.e. 1 bit (symbol) = 417 us, 8 bit, EVEN Parity
Character = 0xFF = 1111 1111bin = 255dec
S 1 1 1 1 1 1 1 1 P=0 Stop
SPACE, Log. 0
MARK, Log. 1
Waveform examples
2400Bd i.e 1 bit (symbol) = 417 us, 8 bit, EVEN Parity
Character = 0x01 = 0000 0001bin = 01dec
S 1 0 0 0 0 0 0 0 P=1 Stop
SPACE, Log. 0
MARK, Log. 1
Efforts of standartization in
measurement systems
• IEEE 1174 – standart 2000, revision 2009
• BUT: Minimal real use among manufacturers
• Defines:
– HW interface: 9-pin RS232 (EIA-574)
– Emulation of special messages IEEE 488.1 over RS232
– Implementation of IEEE 488.2 (message protocols,
common commands, etc.) over RS232
• Purpose: maximal protection of existing
firmware in instruments using 488.2 (i.e. minimal
changes enforced by migration to RS232)
IEEE 1174
IEEE 488.1 message emulation – e.g.:
&SRQ CRLF = Service Request
&POL = Serial Poll
&GET = Group Execute Trigger
&DCL CRLF = Device Clear
(Minimal real support of manufactureres)
IEEE 488.2 support:
Fig.: Standard IEEE 1174
Mainly defined solution od nonstandard
situations (messgae congestion,
deadlock, …)
Programming RS232 communication
• LabView and LabWindows/CVI:
Using RS232 library
Using VISA library - recommended
• Similarly in MATLAB Instrument Control
Toolbox
• Eventually: directly in Win32 API
Example program in CVI - RS232
Serial port setting
(COM1, 9600Bd, …)
Example program in CVI - VISA
VISA resource:
ASRL1 = COM1
Attribute settings
Baudrate, N bits, Parity
USB measuring instruments
• Wide availability of USB in computers
=> Motivation for USB support in instruments
• Possible replacement of GPIB (IEEE 488)
• Faster data rate than RS232 and GPIB
• More devices on USB bus (127 via hubs)
• PROBLEM: retaining maximum of firmware in
instruments (from IEEE 488.2 support)
=> standartization USB class „Test and Measurement“
USB
•
+ Data rate
1.
2.
3.
USB 1.1 (1998): 12 Mbit/s
USB 2 (2000): 280 MBit/s (35 MByte/s)
USB 3 (2008): 4 Gbit/s
First osciloscopes: USB host for USB flash discs (screenshot
and data storage, replacement of floppy discs)
Later: also communication and control from PC (as
replacement or supplement of GPIB)
Definition of USB class
„Test and Measurement Device“
• USB standart defines device classes:
Audio class, Battery charging, Imaging class, IrDA,
Printer Class, …, Test & Measurement Class, … ,
Video Class
• Purpose: retaining maximum of instrument
firmware from 488.2, replacement of lower levels
(488.1 -> USB)
See:
http://www.usb.org/developers/devclass_docs#approved
USB Discovery in PC
Here:
osciloscope
Agilent
DSO1012A
Like all USB: automatic detection and driver load
VISA and USB
Problem:
Unlike e.g. GPIB, VISA resource descriptor for USB is higly sensitive to
completeness (serial number, etc.)
Thus, full specification of target device is necessary: even more than for
GPIB it is good practice to make the program flexible, i.e. import the
VISA resource string from GUI or a .cfg file
+ VISA resource can be Copy & Paste-ed from MAX
+ can be looked up using VISA function viFindRsrc ( ,"?*INSTR", , , );
Supported in VISA and integrated SW tools
(NI MAX, Agilent IO Control)
Detection in NI MAX
VISA resource can be
Copy & Paste-ed
Tools in MAX:
Basic communication USB in MAX
Identification query Response
Record in NI I/O Trace
Example program in CVI - VISA
Example program in LabView
Download