Attachment 'GPIB_functions.c'

Download

   1 #include "declarations.h"
   2 
   3 //external variables
   4 extern unsigned long gpib_timeout;
   5 extern char    trmEOI;      // terminate on EOI only, 2011-06-19 RR
   6 
   7 //external functions
   8 void sendTxd1(char data);              
   9 void com_print(char *daten);           
  10 
  11 //auxiliary functions
  12 //delay microseconds
  13 static void delayus (unsigned long micros)
  14 {
  15 	unsigned long i;
  16 	for (i = 0; i < micros; i++)
  17 	{
  18 		asm("nop");
  19 	}
  20 }
  21 
  22 //Set port pins, establish controller in charge, reset connected devices
  23 void Init_Gpib_interface(void)
  24 {
  25 	DATA_OUT;
  26 	SET_TALK_DIR;
  27 	EOI=1;
  28 	DAV=1;
  29 	ATN=1;
  30 	IFC=0;
  31 	REN=0;
  32 	delayus(10000);
  33 	IFC=1;
  34 }
  35 
  36 //Send one byte to gpib bus: MODE= COMMAND:  With ATN asserted, MODE= DATA: release ATN
  37 unsigned int send_gpib_byte(unsigned int mode, unsigned int data)
  38 {
  39 	unsigned long count;
  40 
  41 	DATA_OUT;
  42 	SET_TALK_DIR;
  43 	if (mode == COMMAND)
  44 	{
  45 		 ATN=0;
  46 	}
  47 	count = gpib_timeout;
  48 	while( !NRFD && count)
  49 			{count--;
  50 			 delayus(1);}
  51 	if( count == 0) return DEVICE_NOT_PRESENT_ERROR;
  52 	// changed sequence 2011-06-19 RR
  53 	if (data & 0x80) p3_1=0; else p3_1=1;
  54 	data = data <<1; //shift to p0_1..p0_7, p0_0 is used for TxD
  55 	p0= ~data;
  56 
  57 	delayus(10);
  58 	DAV=0;
  59 	count = gpib_timeout;
  60 	while( !NDAC && count)
  61 			{count--;
  62 			 delayus(1);}
  63 	if( count == 0) return GPIB_TIMEOUT_ERROR;
  64 	DAV=1;
  65 	ATN=1;
  66 	return 0;
  67 }
  68 
  69 //send a string to selected device, assert EOI with last byte
  70 unsigned int send_gpib_string(unsigned char *s)
  71 {
  72 	
  73 	while (*s)
  74 	{
  75 		send_gpib_byte(DATA,*s++);
  76 	}
  77 	EOI=0;
  78 	send_gpib_byte(DATA, LINEFEED);
  79 	EOI=1;
  80 	return 0;
  81 }
  82 
  83 //read a string from selected device until LF received and/or EOI activated
  84 unsigned int read_gpib_string(void)
  85 {
  86 	unsigned long count;
  87 	unsigned int ch;
  88 	
  89 	DATA_IN;		
  90 	SET_LISTEN_DIR;
  91 	
  92 	do
  93 	{
  94 		NDAC=0;
  95 		NRFD=1;
  96 		count = gpib_timeout;
  97 		while ( DAV && count)
  98 			{count--;
  99 			 delayus(1);}
 100 		if( count == 0 ) return GPIB_TIMEOUT_ERROR;
 101 		NRFD=0;
 102 		ch = ~p0 >> 1;
 103 		if (p3_1 == 0) ch= ch | 0x80;
 104 		sendTxd1(ch);
 105 		count = gpib_timeout;
 106 		NDAC=1;
 107 		while ( !DAV && count)
 108 			{count--;
 109 			 delayus(1);}
 110 		if( count == 0 ) return GPIB_TIMEOUT_ERROR;
 111 		// In case of command "E" terminate on EOI only, 2011-06-19 RR
 112 	} while ( ( (ch != LINEFEED) || trmEOI) && EOI);
 113 	NDAC=0;
 114 	NRFD=0;
 115 	trmEOI = 0;
 116 	if (ch != LINEFEED)
 117 		com_print("\r\n");
 118 	return 0;
 119 }
 120 
 121 //address a device as listener, send a query string, then address this device as talker and read answer
 122 unsigned int send_gpib_query(unsigned int addr,unsigned char *sendstring)
 123 {
 124 	unsigned int error;
 125 
 126 	error = send_gpib_byte(COMMAND,UNLISTEN);
 127 	if (error) 
 128 	{
 129 		Init_Gpib_interface();
 130 		return error;
 131 	}
 132 	error = send_gpib_byte(COMMAND,UNTALK);
 133 	if (error) 
 134 	{
 135 		Init_Gpib_interface();
 136 		return error;
 137 	}
 138 	error = send_gpib_byte(COMMAND,LISTEN | addr);
 139 	if (error) 
 140 	{
 141 		Init_Gpib_interface();
 142 		return error;
 143 	}
 144 	error = send_gpib_string(&sendstring[0]);
 145 	if (error) 
 146 	{
 147 		Init_Gpib_interface();
 148 		return error;
 149 	}
 150 	error = send_gpib_byte(COMMAND,UNLISTEN);
 151 	if (error) 
 152 	{
 153 		Init_Gpib_interface();
 154 		return error;
 155 	}
 156 	error = send_gpib_byte(COMMAND,UNTALK);
 157 	if (error) 
 158 	{
 159 		Init_Gpib_interface();
 160 		return error;
 161 	}
 162 	error = send_gpib_byte(COMMAND,TALK | addr);
 163 	if (error) 
 164 	{
 165 		Init_Gpib_interface();
 166 		return error;
 167 	}
 168 	error = read_gpib_string();
 169 	if (error) 
 170 	{
 171 		Init_Gpib_interface();
 172 		return error;
 173 	}
 174 	// append UNL and UNT 2011-06-19 RR
 175 	error = send_gpib_byte(COMMAND,UNLISTEN);
 176 	if (error) 
 177 	{
 178 		Init_Gpib_interface();
 179 		return error;
 180 	}
 181 	error = send_gpib_byte(COMMAND,UNTALK);
 182 	if (error) 
 183 	{
 184 		Init_Gpib_interface();
 185 		return error;
 186 	}
 187 	return 0;
 188 }
 189 
 190 //address a device as listener, then send a string without waiting for answer
 191 unsigned int send_gpib_command(unsigned int addr,unsigned char *sendstring)
 192 {
 193 	unsigned int error;
 194 
 195 	error = send_gpib_byte(COMMAND,UNLISTEN);
 196 	if (error) 
 197 	{
 198 		Init_Gpib_interface();
 199 		return error;
 200 	}
 201 	error = send_gpib_byte(COMMAND,UNTALK);
 202 	if (error) 
 203 	{
 204 		Init_Gpib_interface();
 205 		return error;
 206 	}
 207 	error = send_gpib_byte(COMMAND,LISTEN | addr);
 208 	if (error) 
 209 	{
 210 		Init_Gpib_interface();
 211 		return error;
 212 	}
 213 	error = send_gpib_string(&sendstring[0]);
 214 	if (error) 
 215 	{
 216 		Init_Gpib_interface();
 217 		return error;
 218 	}
 219 	return 0;
 220 }
 221 
 222 //address a device as listener, then send a byte without waiting for answer
 223 // 2011-06-19 RR
 224 unsigned int send_gpib_command_byte(unsigned int addr,unsigned char data)
 225 {
 226 	unsigned int error;
 227 
 228 	error = send_gpib_byte(COMMAND,UNLISTEN);
 229 	if (error) 
 230 	{
 231 		Init_Gpib_interface();
 232 		return error;
 233 	}
 234 	error = send_gpib_byte(COMMAND,UNTALK);
 235 	if (error) 
 236 	{
 237 		Init_Gpib_interface();
 238 		return error;
 239 	}
 240 	error = send_gpib_byte(COMMAND,LISTEN | addr);
 241 	if (error) 
 242 	{
 243 		Init_Gpib_interface();
 244 		return error;
 245 	}
 246 	error = send_gpib_byte(COMMAND, data);
 247 	if (error) 
 248 	{
 249 		Init_Gpib_interface();
 250 		return error;
 251 	}
 252 	return 0;
 253 }
 254 
 255 //address a device as listener
 256 // 2011-06-19 RR
 257 unsigned int send_gpib_listen(unsigned int addr)
 258 {
 259 	unsigned int error;
 260 
 261 	error = send_gpib_byte(COMMAND,UNLISTEN);
 262 	if (error) 
 263 	{
 264 		Init_Gpib_interface();
 265 		return error;
 266 	}
 267 	error = send_gpib_byte(COMMAND,UNTALK);
 268 	if (error) 
 269 	{
 270 		Init_Gpib_interface();
 271 		return error;
 272 	}
 273 	error = send_gpib_byte(COMMAND,LISTEN | addr);
 274 	if (error) 
 275 	{
 276 		Init_Gpib_interface();
 277 		return error;
 278 	}
 279 	return 0;
 280 }
 281 
 282 //send LF+EOI, UNL, UNT
 283 // 2011-06-19 RR
 284 unsigned int send_gpib_unlisten(void)
 285 {
 286 	unsigned int error;
 287 	EOI=0;
 288 	send_gpib_byte(DATA, LINEFEED);
 289 	EOI=1;
 290 	error = send_gpib_byte(COMMAND,UNLISTEN);
 291 	if (error) 
 292 	{
 293 		Init_Gpib_interface();
 294 		return error;
 295 	}
 296 	error = send_gpib_byte(COMMAND,UNTALK);
 297 	if (error) 
 298 	{
 299 		Init_Gpib_interface();
 300 		return error;
 301 	}
 302 	return 0;
 303 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2013-05-08 04:53:00, 10.4 KB) [[attachment:GPIB_USB.c]]
  • [get | view] (2013-05-08 04:53:00, 50.3 KB) [[attachment:GPIB_USB.pdf]]
  • [get | view] (2013-05-08 04:53:00, 212.3 KB) [[attachment:GPIB_USB.png]]
  • [get | view] (2013-05-08 04:53:00, 332.9 KB) [[attachment:GPIB_USB.sch]]
  • [get | view] (2013-05-08 04:53:00, 52.1 KB) [[attachment:GPIB_USB_Kabel1_DSC01698.jpg]]
  • [get | view] (2013-05-08 04:53:00, 53.6 KB) [[attachment:GPIB_USB_Kabel2_DSC01699.jpg]]
  • [get | view] (2013-05-08 04:53:00, 102.5 KB) [[attachment:GPIB_USB_Patine_US_DSC01703.jpg]]
  • [get | view] (2013-05-08 04:53:00, 96.9 KB) [[attachment:GPIB_USB_Platine_OB_DSC01704.jpg]]
  • [get | view] (2013-05-08 04:53:00, 69.8 KB) [[attachment:GPIB_USB_Stecker5V_DSC01701.jpg]]
  • [get | view] (2013-05-08 04:53:00, 5.7 KB) [[attachment:GPIB_functions.c]]
  • [get | view] (2013-05-08 04:53:00, 78.6 KB) [[attachment:Release.zip]]
  • [get | view] (2013-05-08 04:53:00, 9.8 KB) [[attachment:hp1630.py]]
  • [get | view] (2007-04-13 09:25:00, 1.0 KB) [[attachment:hp1630_HC_GPIBf.txt]]
  • [get | view] (2013-05-08 04:53:00, 10.6 KB) [[attachment:txo10MHz_BNC.png]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.