Mailing List Archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[tlug] measureI_Vplus.c: release early, release often (was Re: just a quick note... more to come later :))



On Thu, 27 Jul 2006 10:19:40 +0200 Michal Hajek <hajek1@example.com> wrote:

> measureI_Vplus()

measureI_Vplus.c

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <getopt.h>
#include <gpib/ib.h>
#include <sys/timeb.h>
#include "lojza.h"

#define MAX_KEITHLEY_REPLY_LEN (16) /* ^^^ this probably belongs in keithley.h *
/

/* ibwrtstr is a wrapper for ibwrt to avoid need counting chars in strings
*  (and the inevitable bugs therefrom) */
/* ^^^ this should likely go in keithley.c */

int ibwrtstr(int ud,const void *data)
{
   return ibwrt(ud,data,(long)strlen((char *)data);
}

void measureI_Vplus(double *current_plus, double *voltage_plus)
{
   double voltage_as_measured_on_normal; /* ^^^ what kind? voltage? temperature?
 */

   char buffer[MAX_KEITHLEY_REPLY_LEN+1];

   ibwrtstr(K706Ud,"C37C38X"); /* configure K706 plus direction */
   ibwrtstr(K706Ud,"C32X");

   /* MERENI NORMALU */

   ibwrtstr(K706Ud,"C9X");
   ibwrtstr(K2182Ud,"*trg");
   ibwrtstr(K2182Ud,"DATA:FRESh?"); /* measure normal voltage plus */
   ibrd(K2182Ud,buffer,MAX_KEITHLEY_REPLY_LEN); /* _voltage_ as measured on norm
al */
   buffer[ibcnt]='\0';
   voltage_as_measured_on_normal = atof(buffer);
   *current_plus = voltage_as_measured_on_normal/NORMAL;

   ibwrtstr(K706Ud,"N9X"); /* change channel to measure sample in furnace */
   ibwrtstr(K706Ud,"C1X");

   /* MERENI VZORKU */

   ibwrtstr(K2182Ud,"*trg");
   ibwrtstr(K2182Ud,":SENSE:DATA:FRESh?");
   ibrd(K2182Ud,buffer,MAX_KEITHLEY_REPLY_LEN);
   buffer[ibcnt]='\0';
   *voltage_plus = atof(buffer);

   ibwrtstr(K706Ud,"N1N32N37N38X");
}

The biggest bug fixed (again) was when ibcnt==16:

   char result_V_plus[16];
   result_normal_plus[ibcnt]='\0';
   char result_normal_plus[16];
   result_V_plus[ibcnt]='\0';

I expect that you have this kind of bug repeated throughout your code.
It's left to you to find and fix the others.
no need for separate buffers.
choose meaningful variable names. "result" is a bad name.
voltage_as_measured_on_normal is better, but still bad.
It's up to you to choose a good name.
Good variables names are important.
The "NORMAL" name is also lacking in information.
How about NORMALIZATION_FACTOR?
Why x/NORMAL? why not x*NORMAL?
(Use whichever is easiest for your brain to understand.
Don't worry about speed.)
What are the units of NORMAL? (How does NORMAL convert volts to current?)


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links