Analytical Balance: Linking to the CIS

Installation of Mettler/Toledo Balance

  1. Hardware: Mettler/Toledo College B Balance equipped with LC-B Interface card and LC cable.
  2. Software: TRIMtool driver TRIMhome\bin\scale.exe; TRIMtool application: TRIMhome\cis\balance.gap
  3. Procedure:

Controlling the balance from a GUI application

  1. Weighing Procedure: The weighing process is started from the Ship Sample Application by selecting the Bottle Number to be weighed and pressing the 'Weigh Action Button'. The balance displays 'bottle' on its LCD which is a prompt for the user to place an empty bottle on the balance and to tare. The balance then displays the quantity of chemical to weigh. After weighing this amount into the bottle, the user presses the tare key again and the weight is automatically sent to the Ship Field of the Ship Sample application.
  2. How it Works: Multiple steps are required to communicate with the balance.
The 'Weigh Action Button' trigger follows:
{
char ret[42];
/* The WEIGH ACTION was designed after the example given on page 70 of
   the "Mettler/Toledo Reference Manual Standard Interface Command Set" */

if (list_curr(p.wl,@p.unit) != "M")    /* Unit must be mg to weigh on balance */
  error("Unit must be 'M' to fetch a balance weight");
active_field(4);                               /* put cursor on balance field */
if (balance("@")!="I4 A ")                                 /* reset balance   */
  break;
if (balance("""K 3""")!="K A") /* disable key function on bal & return key id */
  break;
if (balance("""D 'BOTTLE'""")!="D A")       /* display 'BOTTLE' on balance LCD*/
  break;
if (balance("""""") != "K C 3")  /*send balance a NULL & wait for user to tare*/
  break;
if (balance("T")!="T S  ")                       /* send tare cmnd to balance */
  break;
if (balance("""D '"                         /* display mg to weigh on bal LCD */
            ^^list_curr(p.wl,@p.QTY)/1000^^"'""")!= "D A")
  break;
if (balance("""""") != "K C 3")  /*send balance a NULL & wait for user to tare*/
  break;
if (balance("S")!="S S  ")                  /* get compound weight fm balance */
  break;
}
The code for the user trigger balance() follows:
{
char response[5];
list response_list;
list return_list;

list_mod(g.balance_list,1,"port",  g.port); /* com parms defined in wrcis.ini */
list_mod(g.balance_list,1,"baud",  g.baud);
list_mod(g.balance_list,1,"parity",g.parity);
list_mod(g.balance_list,1,"bits",  g.bits);
list_mod(g.balance_list,1,"flow",  g.flow);
list_mod(g.balance_list,1,"outfile",substr(g.outfile,5)); /* cut gui! fm outfi*/
list_mod(g.balance_list,1,"command",parm.0);     /* command from weigh action */
list_file(g.balance_list,g.cache_dir^^"infile.ini","a");
if (!list_find(g.cache_list,0,"infile.ini"))
  list_mod(g.cache_list,1,"infile.ini");

winexec("scale "^^g.cache_dir^^"infile.ini",1);

return_list= list_open(g.outfile,10);
if (!list_find(g.cache_list,0,g.outfile))
  list_mod(g.cache_list,1,g.outfile);
response = substr(list_curr(return_list,0),1,5);

if (!response_list){
  response_list= list_open("5 80",6,"Responses from scale");
  list_mod(response_list,1,"D A","Response to the prompted text.");
  list_mod(response_list,1,"DW A","Sample weight displayed on balance.");

  list_mod(response_list,1,"ES", "Syntax error");
  list_mod(response_list,1,"ET", "Transmission error. The balance has "
                                 "received a 'faulty' command, e.g. "
                                 "a parity error or interface break.");
  list_mod(response_list,1,"EL", "Logical error. Balance "
                                 "can not execute the received command.");
  list_mod(response_list,1,"I4 A ","Balance is reset and ready for operation.");
  list_mod(response_list,1,"K A","Key control command understood and "
                                 "successfully executed.");
  list_mod(response_list,1,"K I","Key control command understood, but "
                                 "not executable at present. Balance may "
                                 "be in menu or input mode.");
  list_mod(response_list,1,"K L","Key control command understood, but "
                                 "command parameter wrong.");
  list_mod(response_list,1,"K C 3","Tare key was pressed briefly, or tare key "
                                 "was released after more than 2 seconds.");
  list_mod(response_list,1,"K R","Tare key was held about 2 seconds. "
                                 "This response repeats every 2 seconds "
                                 "as long as the tare remains pressed.");
  list_mod(response_list,1,"S I","Command not executable. "
                                 "Balance is executing another command "
                                 "(e.g. taring) or stability not reached.");
  list_mod(response_list,1,"S +","Balance in overload range.");
  list_mod(response_list,1,"S -","Balance in underload range.");
  list_mod(response_list,1,"T I","Taring not performed. Balance is currently "
                                  "executing another command (e.g. zero "
                                  "setting) or unable to stabilize.");
  list_mod(response_list,1,"T +","Upper limit of taring range exceeded.");
  list_mod(response_list,1,"T -","Lower limit of taring range exceeded.");
}

if(response == "S S  "){
  bell();
  status("Balance returned a stable weight of "
         ^^translate(substr(list_curr(return_list,0),5)," ","")^^".");
  field= 1000*(to_number(substr(list_curr(return_list,0),5,10)));
  g.modified=true;
  }

else if(response == "T S  "){
  bell();
  status("Balance is tared and has a value of "
         ^^translate(substr(list_curr(return_list,0),5)," ","")^^
         " in tare memory.");
  }

else if (list_find(response_list,0,response)){
    bell(); bell();
    status("Balance returned '"^^list_curr(response_list,0)^^"': "
           ^^list_curr(response_list,1) );
    field= NULL;
    g.modified=true;
  }
else{
  bell(); bell();
  status(list_curr(return_list,0));
  field      = NULL;
  g.modified = true;
  }
return_list    = NULL;
g.balance_list = NULL;
delete(g.outfile);
return(response);
}
BALANCE() writes a file called TRIMhome\cache\infile.ini which looks like this:

Updated 13 February, 1999. Copyright DataAspects Corp. 1998