Analytical Balance: Linking to the CIS
- Hardware: Mettler/Toledo College B Balance equipped with LC-B Interface card and LC cable.
- Software: TRIMtool driver TRIMhome\bin\scale.exe; TRIMtool application: TRIMhome\cis\balance.gap
- Procedure:
- Assure that path in autoexec.bat includes ' set path= TRIMhome\bin'.
- Connect the LC cable to an available RS232 serial port.
- Run balance application {Start CIS, choose Menu/Balance). Complete the Port field (i.e. COM2), Command field (i.e. I4) and Outfile field (i.e. c:\trifox\cache\fm_balance.txt) and push the 'Send' button to transmit your command to the balance. The response from the balance will be displayed in the Results field (i.e. the balance serial number). See the Mettler/Toledo Reference Manual Standard Interface Command Set for a list of balance commands and their responses.
Controlling the balance from a GUI application
- 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.
- How it Works: Multiple steps are required to communicate with the balance.
- The trigger in the 'Weigh Action Button' calls balance(), a user trigger, and passes it a series of commands, one at a time. The commands are listed in the comments included with the 'Weigh Action Trigger' shown below.
- Balance() combines the serial port parameters with the command into a list and writes it to TRIMhome\cache\infile.ini. The contents of this file are shown below.
- TRIMhome\bin\scale.exe, the scale driver, reads infile.ini, opens the serial port, and passes the command to the balance.
- The balance returns its results to the driver, scale.exe, which writes them to a second file, TRIMhome\cache\filename. Filename is assigned to the variable of outfile which was assigned in wrcis.ini.
- The balance() function reads this file, validates the results, and breaks if an error occurred. If the results are valid, then the results are passed back to the 'Weigh Action Button'. All results including errors are displayed on the status line.
- If the results from the scale were validated as correct, the 'Weigh Action Button' trigger executes the next command and these steps are repeated.
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:
- port com2
- baud 9600
- parity 0
- bits 8
- flow 0
- outfile c:\daspects\cache\fm_bal.txt /* filename specified in wrcis.ini */
- command @
Updated 13 February, 1999. Copyright DataAspects Corp. 1998