Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 6, 2006


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Helpful Hints for Using the GPIB-232CT-A

5 ratings | 4.00 out of 5
Read in | Print

Overview

The GPIB-232CT-A is a serial-to-GPIB interface that transforms any computer with an RS-232 port into a GPIB Talker/Listener/Controller; it can also function as a serial-to-GPIB converter so that serial devices can interface directly with GPIB. The GPIB-232CT-A has the same functionality as a standard GPIB plug-in interface board, yet also provides users with the option to use a notebook computer to develop portable light-weight test and measurement GPIB applications.

This document describes various issues that may assist you in successfully configuring and operating the GPIB-232CT-A on different platforms using different operating modes.

Introduction

When using the GPIB-232CT-A as the System Controller, you configure the GPIB-232CT-A to operate in S mode. In this case, you use the NI-488.2 driver software and related GPIB functions and routines to develop software applications to interface with GPIB instruments and peripherals. Alternatively, you have the freedom to bypass the NI-488.2 driver and develop applications that use low-level commands sent directly to the GPIB-232CT-A. This minimizes the software overhead associated with the language interface library and the NI-488.2 driver software, so users can develop faster and smaller GPIB executable programs. This approach also gives users the freedom to develop applications to control remote testing sites using modem technology and existing telecommunications links. A list of these low-level functions, known as S-Mode functions, can be found in the GPIB-232CT-A User Manual. It is important to note that regardless of whether the NI-488.2 driver or the S-Mode functions are used, you are still operating the GPIB-232CT-A in S-Mode, linked to your computer over the serial port.

Besides being able to operate as a Talker/Listener/Controller, the GPIB-232CT-A can also function as an interface between the GPIB and serial-ready peripherals and instruments. In the operational mode known as G-Mode, the GPIB-232CT-A receives information from the GPIB and transmits it to an instrument or peripheral with a serial interface. Just as in S-Mode, there is also a set of G-Mode functions for configuring the operational characteristics of your GPIB-232CT-A. For example, to disable the SRQ feature of the GPIB-232CT-A, send the srqen 0 command to the GPIB-232CT-A primary address. See the GPIB-232/485CT-A User Manual for detailed information.

For applications that must span distances greater than 50 feet, you can use our GPIB-485CT-A to achieve GPIB control through an RS-485 port. The GPIB-485CT-A has the same functionality as the GPIB-232CT-A but over a span of 1.2 km (4000 ft). Unlike RS-232, RS-485 is a multidrop, differential wiring scheme where each transmission line is referenced to a separate ground. Differential transmission makes RS-485 less susceptible to noise and voltage degradation due to transmission line effects. If these factors are important to your application, contact National Instruments to receive additional information on using the GPIB-485CT-A.
See Also:
GPIB-232/485CT-A User Manual

Configuring Your GPIB-232CT-A for Operation in DOS or Windows


This section provides information that will help you configure your GPIB-232CT-A to work with an RS-232 port in your computer while operating the GPIB-232CT-A in S-Mode..

Installing in DOS
After installation of the NI-488.2 driver software for DOS, edit the driver configuration using ibconf.exe located in the GPIB distribution directory. Specify the COM port you will be using and verify that the base I/O address and interrupt channel matches with those set up on your computer. One possible way of doing this is to invoke a Microsoft utility known as Microsoft Diagnostics (MSD). This utility can be invoked from the DOS prompt by typing msd. The section that reports COM port information will tell you the base I/O address and interrupt channel that each available COM port is currently using. In general, COM1 is used to interface a mouse and so you would want to use a COM port other than COM1 to interface with your GPIB-232CT-A. Table 1 contains a list of standard base addresses and IRQ settings for COM1 through COM4. Unless you have changed your PC COM port configurations, you should have no problems in accepting the default settings that ibconf.exe fills in for base I/O and interrupt level.

Table 1. Standard COM Port Settings
Com Ports
Base Address
IRQ Settings
COM1
0x3F8
4
COM2
0x2F8
3
COM3
0x3F8
4
COM4
0x2F8
3

IRQ settings can be modified, based on how your system allocates IRQ resources. Be sure you understand how modifying IRQ settings will affect your system and your COM port prior to doing any modifications.

In addition to base I/O address and IRQ configuration, it is also important verify that the baud rate, number of data bits, number of stop bits and parity selections made for the GPIB-232CT-A concur with those for the COM port. Any DOS reference will contain information on how to modify your COM port settings. It is recommended that you place the appropriate call inside autoexec.bat so that every time your computer loads DOS, your COM ports are configured for you automatically. For example, for version 5.0 of MS-DOS, the command mode com2: 96,n,8,1,n can be added to the batch file to configure COM2 for 9600 baud, no parity, 8 data bits, 1 stop bit, and no retry. If at any time you need to modify the configuration, just edit this line in autoexec.bat.

Installing in Windows
After installing the NI-488.2 driver software for Windows, specify the COM port you will be using via Wibconf.exe. Double-click on the wibconf icon in the GPIB program group or access the file in the GPIB distribution directory using File Manager. If you try to access COM3 or COM4, be sure that your comm.drv provides support for these additional ports. In some programming environments, such as LabWindows/CVI, you can open and configure a COM port via some defined function. In other cases, a COM port may be opened as is; it would be important to verify that the current configuration concurs with your GPIB-232CT-A configuration. You can view and edit your current COM port settings by entering Control Panel from the Main Program Group inside Program Manager. Selecting Ports from here will popup a window displaying all the available COM ports. Select the COM port that you would like to configure and click on the settings button. In the settings popup window, you can configure Baud Rate, Data Bits, Parity, Stop Bits, and Flow Control. By clicking on the advanced button, you can view and modify the base I/O address and interrupt level for that particular COM port. Do not modify these settings unless you clearly understand COM port interfacing with the PC.

Choosing the Mode of Operation


S-Mode
In the S-Mode configuration, the GPIB-232CT-A can act as a system controller, accomplishing tasks such as addressing talkers and listeners on the bus, managing information transfer across the bus, and managing requests for service by various devices on the GPIB.

You can use the GPIB-232CT-A with or without the NI-488.2 driver. Using it with the driver, you can operate the GPIB-232CT-A as if it were a standard plug-in GPIB interface board. NI-488.2 translates NI-488 functions and NI-488.2 routines into calls that are made to the GPIB controller through the serial port. To use this method, install our NI-488.2 driver and then either link our language interface to the GPIB application or use one of our development environments, such as LabWindows CVI, which incorporates GPIB libraries directly into the environment.

In addition to using the NI-488.2 driver software, you also have the option to access the GPIB-232CT-A using the GPIB-232CT-A specific, S-Mode programming functions. These low-level functions, which are summarized in Appendix A, can minimize the overhead associated with the NI-488.2 driver, decrease execution time, and result in a smaller compiled program. However, realize that the NI-488.2 driver provides a high-level, easy-to-use API that is compatible with other National Instruments GPIB interfaces. You should consider these factors carefully when developing your GPIB application program. Also note that because the S-Mode commands are written directly to the GPIB-232CT-A, it is critical to adhere to the termination requirements specified for each command when sending these commands to the controller through the serial port. For additional information regarding S-Mode and a detailed listing of the S-Mode functions, see the GPIB-232/485CT-A User Manual.

In addition to the S-Mode functions list appearing in Appendix A, Appendix B contains two S-Mode Programming examples written in LabWindows CVI. As you read through the examples, it is clear that a programming language that expedites access to the COM ports of your computer decreases your development time.

G-Mode
G-Mode is used to interface a serial device to the GPIB. In this scenario, another GPIB controller manages the GPIB and communicates with a serial device through the GPIB-232CT-A. In essence the GPIB-232CT-A acts as a high performance GPIB-to-serial converter. It is important to note how addressing is done when configuring the GPIB-232CT-A for G-Mode. The GPIB address that you assign via the DIP switches is known as the GPIB Primary address and is actually the GPIB address of the configuration register of the GPIB-232CT-A. There are G-Mode functions you can use to modify the operating parameters of the GPIB-232CT-A (See the GPIB-232/485CT-A User Manual for G-Mode function details.). The address at which you can access your serial device will be the Primary Address plus one. Thus, you are actually using two GPIB addresses when operating the GPIB-232CT-A in G-Mode. For example, if the GPIB Primary Address is six, the GPIB address at which the serial device is accessed is seven.
See Also:
GPIB-232/485CT-A User Manual

Cabling Requirements


There are two cable configurations used with the GPIB-232CT-A. One is DTE-to-DCE interfacing and the other is DTE-to-DTE interfacing, which is also known as the Null Modem cable configuration. DTE implies Data Terminal Equipment and DCE implies Data Communications Equipment. These types of cabling come in a 9-to-9 or a 9-to-25 pin configuration. An illustration of these cables as well as a description of the minimum requirements for RS-232 appear in Appendix D of the GPIB-232/485CT-A User Manual. When setting up your GPIB-232CT-A, it is critical that you choose the correct cabling. The following sections explain differences between DTE to DCE and DTE to DTE and why there is a need for two interfacing methods.

DTE to DCE
This RS-232 configuration was originally created to interface Data Terminal Equipment (DTE) to Data Communications Equipment (DCE) such as modems. The acronyms DTE and DCE imply the arrangement of control and data signals for a serial communications interface. In the DTE configuration, pin 2 is used to transmit data and pin 3 is used to receive data. In the DCE configuration pin 2 is used to receive data and pin 3 is used to transmit data. The cabling of a DTE interface to a DCE interface is known as a straight-through connection where pin 2 of DTE connects to pin 2 of DCE and pin 3, to pin 3.

DTE to DTE
Notice that when connecting together two DTE interfaces, a straight-through connection no longer applies because pin 2 is used to transmit and pin 3 is used to receive on both sides of the serial communication link. Rather than implementing a straight through connection, the wiring is exchanged in the cable so that pin 2 of one end of the link connects with pin 3 of the other. Because we are no longer connecting a terminal or computer to a serial communications device (modem), the term null modem cable is used to describe the cabling required to exchange the appropriate signals in the cable. The term full null modem cable implies that the cable provides not only the minimum requirements for RS-232, but also the control lines required to implement hardware handshaking of data across the serial link.

The minimum cable configuration required for serial communication are the RXC (Receive) line, the TXD (Transmit) line and GND (Ground). The other signals that make up RS-232 are not used if hardware handshaking is not needed. An illustration of how this can be done appears in Appendix D of the GPIB-232/485CT-A User Manual.
See Also:
GPIB-232/485CT-A User Manual

General Operating Notes


In general, the GPIB-232CT-A connects to a computer serial (COM) port. Be sure that you are not using a port that has been configured or allocated for use by some other device. It is important to verify that your COM ports are set up correctly by checking your BIOS prior to booting DOS. The BIOS contains information regarding which external interface ports are currently enabled or disabled. Once this has been accomplished, use the software utilities of your operating system to correctly configure the parameters for that COM port. In addition, be sure to select the correct switch settings for your desired application. These would include mode of operation (S-mode or G-mode), baud rate, number of data bits, number of stop bits, and parity checking mode. If operation through the serial port becomes unreliable, you might want to use the CTS (Clear To Send) and RTS (Request To Send) hardware handshaking lines to manage RS-232 data transfers. To enable hardware handshaking, your devices must be compatible with the CTS and RTS signals and you must be using a full null modem cable that connects all these signals between the devices and the GPIB-232CT-A. Reducing the baud rate may also stabilize serial transfer of information. If you are operating at 9600 baud or greater, it is important to use hardware handshaking to avoid losing bytes on transfers. A brief excerpt from the GPIB-232/485CT-A User Manual appears in Appendix A of this document. It goes into details regarding how the Controller implements data buffering and hardware handshaking. This information is critical in understanding the concept of Hardware Handshaking.

Troubleshooting
For troubleshooting purposes, you can also operate the GPIB-232CT-A by terminal emulation. In this situation, the GPIB-232CT-A is set up in S-mode and a dumb terminal or terminal emulation software program from your PC is interfaced to the GPIB-232CT-A via the serial port. Thus, you can interactively interface with the controller using S-mode commands. This method is useful when getting acquainted with how S-Mode functions return information after commands are sent to the controller. You can also verify that the GPIB-232CT-A is operating correctly using terminal emulation.

A convenient way of accomplishing terminal emulation is to use the Windows Terminal application that appears in the Accessories Program Group inside Program Manager. Use the Terminal Emulation, Terminal Preferences and the Communications selections under the Settings pull down menu to configure your terminal session. Then connect the serial port to the GPIB-232CT-A via a null modem cable and use commands such as onl, sic and id to verify communications with your controller. To verify the integrity of your cable, disconnect it from the GPIB controller and connect pin 2 to pin 3 with a short wire (paper-clips work well), and disable the local echo under the Terminal Preferences. Change Flow Control to none under Communications and begin typing on your terminal or PC keyboard. Everything that is typed should echo back to the screen. This will assure that information is flowing through the cable as expected. A continuity tester can be used to verify continuity of the other signal through the cable.

A sample terminal session appears below:

Terminal: onl 1 <return>  Place the GPIB-232CT-A Controller on-line. Returns nothing.

Terminal: sic <return>   Send Interface Clear to the Controller. The ATN LED turns on. Nothing returned.

Terminal: id <return>   Returns the product identification, firmware revision, and RAM size.

   Sample Response: GPIB-232CT-A Rev B.2
(c) 1992 National Instruments
256K bytes RAM

In addition to the items mentioned above, if operating in DOS, you can also use the msd utility to verify the current COM port settings, interrupt allocation, and verify that the GPIB Terminate and Stay Resident Program (TSR) was loaded into memory. Note if you did not see a blue National Instruments driver banner appear during the booting process of your computer, the gpib.com driver never got loaded. Verify that the call device=<boot drive>\<path>\gpib.com appears in your config.sys file. An example call would be device=C:\gpib-ct\gpib.com where C:\ corresponds to the boot drive and gpib-ct corresponds to the directory containing all the GPIB distribution files including gpib.com

Power-On Self Test
The GPIB-232CT-A has a power-on self test that executes when the unit is powered up. Upon powering up the GPIB-232CT-A, the POWER LED comes on. After about eight seconds, the READY LED should also come on. If this does not occur the GPIB-232CT-A has failed its power-on self test and you should contact National Instruments technical support for further assistance.

Programming Examples (See Appendix B)
Example 1: S-Mode Programming PC to PC
This code illustrates how to use the GPIB-232CT-A as a slave. The code emulates the functionality of the Fluke 45. This application is useful in creating a software simulation of some device you might be developing.

Example 2: S-Mode Programming in a Remote GPIB Application
This code illustrates how you can access a GPIB-232CT-A and collect data from GPIB devices through a modem. For more detailed information, see Remote GPIB Control Using a GPIB-232CT-A.
See Also:
Remote GPIB Control Using the GPIB-232CT-A

Appendix A -- S-Mode Functions Summary


I/O Functions
rd count, address
wrt count, address list data

Read Data
Write Data
High-Level Bus Management Functions
clr address list
loc address list
trg address list

Clear Specificed Device(s)
Go to Local
Trigger Selected Device(s)
GPIB Initialization Functions
caddr address
eos modes, eoschar
eot on/off
onl on/off
rsc on/off
tmo values

Change GPIB address of GPIB-232CT-A
Change or disable termination mode
Enable/Disable EOS on Writes
Place GPIB-232CT-A online/offline
Request System Control
Change or disable time-outs
Serial Poll Functions
rsp address list
rsv status byte

Conduct a Serial Poll
Request Service and/or set Serial Poll Byte
Low-Level Bus Management
cac mode
cmd count commands
gts mode
lines
In address list
pct address
sic time
sre on/off

Become Active Controller
Send IEE 488 Commands
Go from Activer Controller to Standby
Determine State of GPIB Lines
Check for Listening Devices
Pass Control
Send Interface Clear for Specified Duration
Set Remote Enable
Parallel Poll Functions
ist set/clear
ppc values
ppu address list
rpp

Respond to Parallel Poll: Set ist bit
Parallel Poll Configure
Parallel Poll Unconfigure
Conduct a Parallel Poll
Serial Port Functions
echo on/off
spign on/off
xon modes

Echo Chars Received from Serial Port
Ignore Serial Port Errors
Change Serial Port XON/XOFF Proctocol
General Use Functions
conf option value
id
stat modes
wait mask

Read/Change Controller Configuration
Identify System
Return GPIB-232CT-A Status
Wait for Selected Event(s)

Data Buffering and Handshaking Schemes


Two protection mechanisms are used to ensure that the GPIB-232CT-A does not lose incoming serial data -- data buffering and handshaking.

Buffering
The GPIB-232CT-A has an internal RAM buffer that stores incoming serial data until it can output the data to the GPIB port. The size of this RAM buffer determines how much serial data the GPIB-232CT-A can accept before the buffer is completely full.

When its RAM buffer is nearly full, the GPIB-232CT-A can handshake with the serial host to stop data transmission. When the buffer is almost empty, the GPIB-232CT-A is capable of using both the XON/XOFF software handshaking and the hardware handshaking protocols.

Handshaking
The hardware handshake function is always active during RS-232 transfers and uses the Request to Send (RTS) and Clear to Send (CTS) signal lines. When the GPIB-232CT-A is ready to accept serial data, it asserts the RTS line. This signal remains asserted until the GPIB-232CT-A data buffer is almost full. At this point, the GPIB-232CT-A unasserts the RTS line, signaling to the serial host that the GPIB-232CT-A is no longer ready to accept data. The serial host should monitor the RTS line and suspend data transmission whenever the RTS line becomes unasserted. The GPIB-232CT-A asserts RTS when it is again ready to receive serial data.

The GPIB-232CT-A is also able to suspend transmission when the serial host is no longer ready to accept data. The GPIB-232CT-A is configured to stop transmission of serial data immediately when CTS becomes unasserted. The GPIB-232CT-A resumes transmission as soon as CTS is reasserted.

Because most serial devices use the same form of hardware handshaking as the GPIB-232CT-A, you can achieve bidirectional flow control by using a serial cable that connects the GPIB-232CT-A RTS signal to the serial device CTS signal. In addition, the serial device RTS signal should be connected to the GPIB-232CT-A CTS signal. With this setup, each device monitors the RTS signal of the other device and suspends transmission when necessary to prevent data loss. See Appendix D of the GPIB-232/485CT-A User Manual for more information on wiring schemes.
See Also:
GPIB-232/485CT-A User Manual

Appendix B -- Programming Examples


/**********************************************************/
/* This is an S-mode programming example in which the  */
/* 232CT-A controller is set up as a Slave with GPIB      */
/* Primary Address of 4. The program simulates responses of */
/* the Fluke 45 Multimeter when sent various command */
/* strings. This code responds to Device Level Comm by the Master.*/
/**********************************************************/
/* I recommend using this code running at 4800 baud.       */
/* You may get erratic behavior when running at 9600 baud. */
/* If you have a UART that has a fairly large FIFO buffer   */
/* to buffer incoming serial data, then try using 9600     */
/* otherwise choose a lower baud rate.                     */
/**********************************************************/
/* I use the Delay() function to smooth out timing problems */
/* when interacting with the serial port of my PC.         */
/* Similar experimentation may be required to smooth out   */
/* timing issues related to interacting with your PC */
/* serial port. */
/**********************************************************/
/* I wait for a single event in the "wait" mask. If you   */
/* want to wait for multiple events, then you must check   */
/* status and use IF statements to Mask out the desired   */
/* event. */
/**********************************************************/
/* Author: Amar D. Patel */
/* Revision: 1.2 */
/* Date: 01/06/95 */
/**********************************************************/

/**********************INCLUDES****************************/
#include <userint.h>
#include <rs232.h>
#include <ansi_c.h>
#include <formatio.h>
#include <utility.h>

/**********************DEFINES******************************/
#define   SIZE      50
#define   ID "*IDN?"
#define   MEAS1 "VAL1?"
#define   MEAS2  "*SRE 1; VAL1?"
#define   STOP_EXECUTION  "quit"
#define   TRUE    1
#define   FALSE   0
#define SRQ 4096
/****************USER DEFINED FUNCTION PROTOTYPES************/
void CheckGPIBError (char *); /**Currently UnUsed!**/
void CheckCOMportError (int);
void StringInit(void);
void ReadAllStatus(void);
void CTAInit(void);

/****************GLOBAL VARIABLES****************************/
int   ComError; /*COM port error*/
int   BytesWritten; /*Bytes Written on COM Writes*/
int   BytesRead; /*Bytes Read on COM Reads*/
int   inQlen; /*COM port input Q length*/
int   exit_prgm = FALSE;
int   strLength; /*Command String Length*/
int   stat;

charCommand[SIZE];
charStatus[10]; /*GPIB Status*/
charGPIBerr[5]; /*GPIB Error number*/
charSPerr[5]; /*Serial Port Error number*/
charcount[5]; /*Byte count or reads or writes*/
charMeas_data[10];   /*Random Voltage*/

double randmNum; /*Random Number for generating random voltage*/

/***************MAIN PROGRAM**********************************/
main(){

        ComError = OpenComConfig (2, "COM2", 4800, 0, 8, 1, 512, 512);
        CheckCOMportError(ComError);
        ComError = SetCTSMode (2, 1);
        CheckCOMportError(ComError);

        CTAInit(); /** Initialize 232 CT-A **/

        while (exit_prgm == FALSE) {
Delay(2);
FlushInQ (2);
inQlen = 0;

    BytesWritten = ComWrt (2, "wait 4\r\n", 8);/** Wait to be addressed as Listener **/
while (inQlen < 4 ) { /** Check input Q for data **/
inQlen = GetInQLen (2);
}
StringInit(); /** Reset Data strings with null **/
ReadAllStatus();
BytesWritten = ComWrt (2, "rd #50\r\n", 8);/** Direct CT-A to read data on GPIB **/
FillBytes (Command, 0, 50, 0);
BytesRead = ComRdTerm (2, Command, 50, 13);/** Read Data out from Serial Input Buffer **/

/**********IF-ELSE STATEMENTS USED TO MASK FOR INPUT STRING*********/

if ( CompareStrings (STOP_EXECUTION, 0, Command, 0, 0) == 0) {
MessagePopup ("232 CT-A Status", "Quitting Application");
exit_prgm = TRUE;
}
else if ( CompareStrings (ID, 0, Command, 0, 0) == 0) {
Delay(2);
FlushInQ (2);        /**Flush Serial Input Q and Resest inQlength**/
inQlen =0;
BytesWritten = ComWrt (2, "wait 8\r\n", 8);/**Wait to be addressed as a Talker**/
while (inQlen < 4 ) {
inQlen = GetInQLen (2);   /**Wait for status to be returned**/
}
StringInit();
ReadAllStatus();
BytesWritten = ComWrt (2, "wrt #30\nFLUKE, 45, 5000163, 1.6 D1.0\r\n", 38);
}
else if ( CompareStrings (MEAS1, 0, Command, 0, 0) == 0) {
Delay(2);
FlushInQ (2);
inQlen = 0;
randmNum = (double) rand() / 32767 * 2.1;
Scan (&randmNum, "%f>%s", Meas_data);
strLength = StringLength (Meas_data);
BytesWritten = ComWrt (2, "wait 8\r\n", 8);
while (inQlen < 4 ) {
inQlen = GetInQLen (2);
}
StringInit();
ReadAllStatus();
BytesWritten = ComWrt (2, "wrt\n", 4);
BytesWritten = ComWrt (2, Meas_data, strLength);
BytesWritten = ComWrt (2, "\r\n", 2);
}
else if ( CompareStrings (MEAS2, 0, Command, 0, 0) == 0) {
Delay(2);
FlushInQ (2);
randmNum = (double) rand() / 32767 * 2.1;
Scan (&randmNum, "%f>%s", Meas_data);
strLength = StringLength (Meas_data);
Delay(5);
BytesWritten = ComWrt (2, "rsv 70\r", 7);     /* Set SRQ:Processing done*/
Delay(2);
FlushInQ (2);
inQlen = 0;
BytesWritten = ComWrt (2, "wait 8\r\n", 8);
while (inQlen < 4 ) {
inQlen = GetInQLen (2);
}
StringInit();
ReadAllStatus();
BytesWritten = ComWrt (2, "wrt\n", 4);
BytesWritten = ComWrt (2, Meas_data, strLength);
BytesWritten = ComWrt (2, "\r\n", 2);
}
else {      Delay(2);
FlushInQ (2);
inQlen = 0;
BytesWritten = ComWrt (2, "wait 8\r\n", 8);
while (inQlen < 4 ) {
inQlen = GetInQLen (2);
}
StringInit();
ReadAllStatus();
BytesWritten = ComWrt (2, "wrt #40\nINVALID COMMAND: Awaiting Next Command\r\n", 48);
}
}/* end while*/

Delay(5);
ComError = CloseCom (2);
CheckCOMportError(ComError);
}

/***************************************************/
/* Function: CheckCOMportError  */
/* Parameters: int error value returned  */
/* Return Value:   NONE  */
/* Description: This function checks the COM port      */
/* error code and returns the appropriate message.      */
/* Error codes are referenced in LWCVI user manual.          */
/***************************************************/
void CheckCOMportError (int err_value) {
if (err_value < 0) {
MessagePopup ("Communications Error", "Com Port Error: Program Aborted.");
exit (0);
}
}
/**********************************************************/
/* Function: CTAInit        */
/* Parameters: NONE        */
/* Return Value: NONE */
/* Description: This function Initializes the GPIB           */
/* 232 CT-A for EOI, Primary Address 4 and   */
/* Non-Controller. */
/*********************************************************/
void CTAInit(void) {
BytesWritten = ComWrt (2, "onl 1\r", 6);
BytesWritten = ComWrt (2, "eot 1\r", 6);
BytesWritten = ComWrt (2, "caddr 4\r", 8);
BytesWritten = ComWrt (2, "rsc 0\r", 6);
}
/***********************************************************/
/* Function: StringInit          */
/* Parameters: NONE           */
/* Return Value: NONE   */
/* Description: This function initializes the status     */
/* information returned by the "wait" command.*/
/***********************************************************/
void StringInit(void) {
FillBytes (Status, 0, 10, 0);
FillBytes (GPIBerr, 0, 5, 0);
FillBytes (SPerr, 0, 5, 0);
FillBytes (count, 0, 5, 0);
}

/****************************************************/
/* Function: ReadAllStatus  */
/* Parameters: NONE  */
/* Return Value: NONE  */
/* Description: This function reads all status       */
/* information returned by "wait".  */
/***************************************************/
void ReadAllStatus(void) {
BytesRead = ComRdTerm (2, Status, 10, 13);
BytesRead = ComRdTerm (2, GPIBerr, 5, 13);
BytesRead = ComRdTerm (2, SPerr, 5, 13);
BytesRead = ComRdTerm (2, count, 5, 13);
}
/*************************************************************/
/* Remote GPIB Using the GPIB-232CT-A Source Code                        */
/*************************************************************/
/**************************INCLUDES**************************/
#include <formatio.h>
#include <gpib.h>
#include <userint.h>
#include <ansi_c.h>
#include <utility.h>
#include <rs232.h>

/***************************FUNCTION PROTOTYPES******************/
void CheckCOMportError (int);
void ReadAllStatus(void);
void CheckGPIBError(void);

/**************************GLOBALS*******************************/
static intComError;
static intBytesWritten;
static intBytesRead;
static int Flag;
static inthandle;
static inthexStat;
static int InQLen;

charStatus[10];
charGPIBerr[5];
charSPerr[5];
charcount[5];
chardatabuf[100];
charDCbuf[100];
charTimeout[5];
charspoll[5];

/*****************************MAIN*****************************/
main(){

/*************OPEN & CONFIGURE COM2: HW HANDSHAKE**********/
ComError = OpenComConfig (2, "COM2", 2400, 0, 8, 1, 512, 512);
CheckCOMportError(ComError);

ComError = SetCTSMode (2, 1);
CheckCOMportError(ComError);


/*************CONNECT TO REMOTE MODEM*******************/
BytesWritten = ComWrt (2, "ATQ0V1E1S0=0\r\n", 14);
Delay (2);
BytesWritten =ComWrt (2, "ATDT97945775\r\n", 14);
Delay(2);
FlushInQ (2);
InQLen = 0;
while (InQLen < 14) {
InQLen = GetInQLen (2);
}

BytesRead = ComRd (2, databuf, 80);
if (strncmp(databuf, "\r\nCONNECT 2400", 14) == 0)
printf("Connection Succesful!\n");

else {      printf("No Carrier:  Connect Unsuccessful!\n");
exit (0);
}

/**********************GPIB 232CT-A INTERFACING****************/
/* Command: *IDN? returns instrument ID from 488.2 Instrument.   */
/* Command: *SRE 16 enables the Service Request Enable register */
/*              of a 488.2 instrument.  Instrument will assert SRQ   */
/*              when data ready. */
/* Command: VAL1? instructs our device to return DC voltage.     */
/****************************************************************/

Delay (2);
FlushInQ (2);

BytesWritten = ComWrt (2, "onl 1\r", 6);
CheckGPIBError();

BytesWritten = ComWrt (2, "sic\r", 4);
CheckGPIBError();

BytesWritten = ComWrt (2, "wrt 8\n*IDN?\r\n", 13);
CheckGPIBError();

BytesWritten = ComWrt (2, "rd #70 8\r\n", 10);
BytesRead = ComRdTerm (2, databuf, 100, 13);
CheckGPIBError();
printf("%s\n", databuf);

BytesWritten = ComWrt (2, "wrt 8\n*SRE 16\r\n", 15);
CheckGPIBError();

BytesWritten = ComWrt (2, "wrt 8\nVAL1?\r\n", 13);
CheckGPIBError();

Delay (2);
FlushInQ (2);
InQLen = 0;

BytesWritten = ComWrt (2, "wait 4096\r", 10);
while (InQLen < 4) {
InQLen = GetInQLen (2);
}
ReadAllStatus();
Scan (Status, "%s>%d", &hexStat);

if(hexStat & 0x1000) {
BytesWritten = ComWrt (2, "rsp 8\r", 6);
BytesRead = ComRdTerm (2, spoll, 5, 13);
BytesWritten = ComWrt (2, "rd #70 8\r\n", 10);
BytesRead = ComRdTerm (2, DCbuf, 100, 13);
}
 
/********************DISCONNCT FROM REMOTE MODEM**************/
BytesWritten = ComWrt (2, "onl 0\r", 6);
CheckGPIBError();

FlushOutQ (2);
    BytesWritten = ComWrt (2, "+++", 3);
    Delay(2);
    BytesWritten = ComWrt (2, "ATH\r\n", 5);
Delay(3);

/*******************CLOSE COM2**************************/
ComError = CloseCom (2);
CheckCOMportError(ComError);

}/***END MAIN***/

/*******************FUNCTION DECLARATIONS**************************/
/***************************************************************/
/* Function: CheckCOMportError           */
/* Parameters: int error value returned                   */
/* Return Value: NONE           */
/* Description: This function checks the COM port                      */
/* error code and returns the appropriate message.      */
/* Error codes are referenced in LWCVI user manual.*/
/***************************************************************/

void CheckCOMportError (int err_value) {
if (err_value < 0) {
MessagePopup ("Communications Error", "Com Port Error: Program Aborted.");
exit (0);
}
}

/******************************************************/
/* Function: ReadAllStatus       */
/* Parameters: NONE       */
/* Return Value: NONE       */
/* Description: This function reads all status            */
/* information returned by "wait".       */
/******************************************************/

void ReadAllStatus(void) {
BytesRead = ComRdTerm (2, Status, 10, 13);
BytesRead = ComRdTerm (2, GPIBerr, 5, 13);
BytesRead = ComRdTerm (2, SPerr, 5, 13);
BytesRead = ComRdTerm (2, count, 5, 13);
}

/*************************************************************/
/* Function: CheckGPIBError         */
/* Parameters: NONE         */
/* Return Value: NONE         */
/* Description: This function reads all status        */
/* information returned by "stat".  If an error             */
/* condition exists, display error code and exit prgm.*/
/**************************************************************/

void CheckGPIBError (void) {
int GPIBErrCode;
int hexStat;
int InQlen;

Delay (2);
FlushInQ (2);

BytesWritten = ComWrt (2, "stat n\r", 7);
while (InQLen < 4) {
InQLen = GetInQLen (2);
}
ReadAllStatus();
Scan (Status, "%s>%d", &hexStat);
Scan (GPIBerr, "%s>%d", &GPIBErrCode);
if (hexStat < 0) {
printf("GPIB Error: GPIB error code = %d\n", GPIBErrCode);
exit (0);
}
}
Related Links:
GPIB-232/485CT-A User Manual
5 ratings | 4.00 out of 5
Read in | Print

Reader Comments | Submit a comment »

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).