wiki:Docs/Prog/Manual/DeviceSupport/Weighing

Version 4 (modified by Don Wilson, 15 years ago) ( diff )

--

Weighing

The 825 OS provides access to weight data by means of the mnbd-comm device driver. This device driver provides device files: /dev/wt1 - /dev/wt10 corresponding to scale 1 - scale 10. Device file /dev/wttot is used for total weight if the totalizer feature is enabled.

Get Weight

Command prompt testing

Make sure no applications are running or the weight server. Otherwise, the application or weight server may grab the response before you are able to retrieve it from the command prompt.

From the 825 command prompt type:

echo "W" > /dev/wt1
cat /dev/wt1
WA01004456A486000000004456A4860000

The response "WA" indicates the response for the "W" weight request is acknowledged "A". The following characters are hexadecimal encoded values for the floating point gross, tare, net weights and weight status information. Because this data represents floating point math values it is difficult to interpret. You may change the weight on the scale and repeat the test to see that the values change.

Access the weight data from a program

The lib825 library provides features to facilitate access the weight information from an application program.

Cardinal Weighing Library Functions

Header file: mnbdcomm.h

void MnBdStartup() - Opens devices for weight and other external communications

Parameters - None Return value - None

int MnBdProcess() - Services devices checking for weight or other data received

Parameters - None Return value - 0 = idle

mnbdProcWtRcv = weight data received

float GetGrossWt(int scale) - Returns the gross weight

Parameters - scale = scale number Return value - weight

float GetTareWt(int scale) - Returns the tare weight

Parameters - scale = scale number Return value - weight

float GetNetWt(int scale) - Returns the net weight

Parameters - scale = scale number Return value - weight

byte GetWtStatus(int scale)

Parameters - scale = scale number Return value - status byte bitmapped - possible bits

nStatusBitMotion nStatusBitOverCap nStatusBitBelowZero nStatusBitCenterZero nStatusBitError nStatusBitKeypadTare

bool GetMotion(int scale)

Parameters - scale = scale number Return value - true if specified scale is in motion, otherwise false

bool GetOverCap(int scale)

Parameters - scale = scale number Return value - true if specified scale is in over capacity, otherwise false

bool GetBelowZero(int scale)

Parameters - scale = scale number Return value - true if specified scale is below zero, otherwise false

bool GetCenterZero(int scale)

Parameters - scale = scale number Return value - true if specified scale is at center of zero, otherwise false

bool GetWtError(int scale)

Parameters - scale = scale number Return value - true if specified scale is in weight error condition, otherwise false

bool GetKeypadTare(int scale)

Parameters - scale = scale number Return value - true if specified scale is in weight error condition, otherwise false

int GetWtMode(int scale)

Parameters - scale = scale number Return value - wtmode_gross, or wtmode_net mode of the specified scale

void ToggleWtMode(int scale) - Toggles the specified scale between gross and net modes

Parameters - scale = scale number Return value - None

void SetWtMode(int scale, int wtmode)

Parameters - scale = scale number

wtmode = wtmode_gross, or wtmode_net

Return value - None

int GetNumScales(void)

Parameters - None Return value - Number of scales

char* FormatGrossWt(int scale, char* buf)

Parameters - scale = scale number

buf = character array buffer for output

Return value - Pointer to buffer for convenience

// Simple get weight sample

#include <stdio.h>
#include <stdlib.h>

#include "mnbdcomm.h"
#include "lcd.h"
#include "util.h"

int main()
{
   int n;
   char gross_wt_str[41];
   CSleep slp(0, 5);

   InitLCD();
   MnBdStartup();

   while(1)
   {
      n = MnBdProcess();
      if(n == mnbdProcWtRcv)
      {
          FormatGrossWt(GetProcessWt(), gross_wt_str);
          DisplayText(0, 0, gross_wt_str);
      }
      slp.Pause();
   }
   return 0;
}

This displays the gross weight at the upper left corner of the display. The weight will update as changes are made to the scale. This program as an endless loop. If you started the program from the command line without using the "&" parameter you can press CTRL-C to end the program. Otherwise use PS to see the process list and KILL to terminate the appropriate process number.

Note: See TracWiki for help on using the wiki.