4
123
Chapter 4 - Remote Interface Reference
Calculating FCS
Calculating FCS
•
FCS (Frame Check Sum) is used to assure that the RS-232 transmission
was not corrupted.
•
The following BASIC routine calculates the FCS for a
Command
or
Response Packet
.
BASIC Routine for
calculating FCS
Visual C++
Routine for
calculating FCS
1110
‘Copy either Command$ or Response$ into Packet$
1120
‘Run FCS Generator routine: FCSGEN
1130
‘For Command Packets, the routine generates the proper FCS
1140
‘For Response Packets, the routine compares the FCS received to
1150
‘a calculated FCS and returns the FCSVALID fl ag
1160 FCSGEN:
1170
FCS = 0
1180 FCSVALID
=
“TRUE”
1190 Input
Packet$
1200 STARTCHAR$=MID$(Packet$,1,1)
1210
IF STARTCHAR$ = “!” THEN FCSLEN = LEN(Packet$)
1220
IF STARTCHAR$ = “@” THEN FCSLEN = LEN(Packet$) - 4
1230
IF STARTCHAR$ <> “!” OR STARTCHAR$ <> “@” THEN FCSVALID = “FALSE”
1240
For IFCS=1 to FCSLEN
1250
FCS=FCS XOR ASC(MID$(Packet$, IFCS, 1))
1260 Next
1270 FCS$=RIGHT$(“0”,HEX$(FCS),2)
1280
IF STARTCHAR$ = “@” and FCS$ <> MID$(Packet$,18,2) THEN FCSVALID = “FALSE”
•
The following Visual C++ routine calculates the FCS for a
Command
or
Response Packet
.
static BYTE ComputeFCS ( const CString& srPreFcsCmd )
{
BYTE ucFCS = 0; // zero FCS byte
// For debugging: Validate CString object reference is to the fi rst part of a Command or
//
Response Packet
ASSERT( srPreFcsCmd.GetAt(0) = = ‘!’ || srPreFcsCmd.GetAt(0) = = ‘@’ );
ASSERT( srPreFcsCmd.GetLength() = = 15 || srPreFcsCmd.GetLength() = = 17 );
//
Loop through each character of the string and ‘Exclusive OR’ result
// with next character. Byte returned should match transmitted FCS.
for( BYTE ucCharIdx = 0; ucCharIdx < srPreFcsCmd.GetLength(); uc+ )
ucFCS ^= (BYTE) srPreFcsCmd.GetAt( ucCharIdx ) ;
return ucFCS;
}
srPreFcsCmd
contains the
Command Packet
up to the FCS characters.
•
The instrument always checks the
Command Packet’s
FCS against the
calculated FCS. The host computer program can use the
Response
Packet’s
FCS to verify proper communication from the instrument but
it is not necessary.
Summary of Contents for LFI-3751
Page 10: ...10 This page intentionally left blank ...
Page 13: ...1 Chapter 1 Quick Start 13 1 ...
Page 20: ...20 This page intentionally left blank ...
Page 21: ...2 Chapter 2 Front Panel Operation 21 2 ...
Page 34: ...34 This page intentionally left blank ...
Page 54: ...54 This page intentionally left blank ...
Page 68: ...68 This page intentionally left blank ...
Page 69: ...3 Chapter 3 Rear Panel Operation 69 3 ...
Page 75: ...3 4 Chapter 4 Remote Interface Reference 75 4 ...
Page 88: ...88 This page intentionally left blank ...
Page 127: ...5 Chapter 5 Specifications 127 5 ...
Page 131: ...Appendix CAT 220 Cable Accessory Diagram 131 ...