wiki:Docs/Prog/Manual/ApplicationLibraries/lib825ev/Weight/MnBdSetWIM

MnBdSetWIM

Initiate mainboard for high speed buffered weight reading

int MnBdSetWIM(uint16 onDivisions, uint16 offDivisions, uint8 onCount, uint8 offCount, uint16 flag)

Parameters

  • onDivisions - weight division value to starting recording when weight is above this value for at least onCount
  • offDivisions - weight division value to stop recording when weight is below this value for at least offCount
  • onCount - number of consecutive weight values that must be above onDivisions to start weight recording
  • offCount - number of consecutive weight values that must be below offDivisions to stop weight recording
  • flag - special settings bitfield

Return Value

  • Returns OK (MNBD_REQ_ACK_RCVD) if successful, MNBD_REQ_NACK_RCVD if error response, MNBD_REQ_TIMEOUT if no response.

Remarks

Requires at least main board version 1.20.009 and OS version 1.12.024.

Must be used in conjunction with StartRepeatMulti. WIM data will be received in MultiRcv function.

This function instructs the main board to prepare for buffered weight recording. When the gross weight division value exceeds the on threshold for consecutive on count the buffering begins. Gross weights are recorded into the buffer. When the gross weight drops below the off threshold for consecutive off count the buffering stops. This allows the application to process high speed.

Example

int minor_ver = 0;
int ver = GetMnBdVer(&minor_ver);
if(ver < 120 || (ver == 120 && minor_ver < 9))
{
   DrawErrorBox("Min mnbd ver 1.20.009", 10);
   MnBdShutdown();
   exit(0);
}

uint32_t cardinal_ver = GetCardinalOSVer();
if(cardinal_ver < MAKE_VER(1, 12, 24))
{
   DrawErrorBox(Min OS ver 1.12.024", 10);
   MnBdShutdown();
   exit(0);
}

SetBackgroundEvent(BackgroundEventComm);

MnBdSetEvent(MNBD_REQ_REP_MULTI, MnBdEventMultiRcv);
StartRepeatMulti(100);

float onWtThres = 1500.0;
uint16 onThres = (int)(onWtThres / g_cal_param_n[1].interval);

uint8 onCount = 3;

float offWtThres = 1000.0;
uint16 offThres = (uint16)(offWtThres / g_cal_param_n[1].interval);

uint8 offCount = 3;

uint16 flags = 0;

if(MnBdSetWIM(onThres, offThres, onCount, offCount, flags) != OK)
{
    DrawErrorBox("Cannot start MNBD WIM", 15);
}

BACKGROUND_EVENT(Comm)
{
  int n;
  for(n - 0; n <= GetNumScales(); n++)
  {
     MnBdRead(n);
  }
  return 0;
}

void ProcessMnBdAxleRcvd(struct mnbd_swim_struct* pAxle)
{
   uint16 maxDivs = pAxle->peakWt;
   uint16 numSamples = pAxle->numSamples;
   int maxWt = maxDivs * g_cal_param_n[1].interval;
   DEBUG_MSG("Axle samples %d peak wt %d start %d end %d diff %d\n",
      numSamples, maxWt, pAxle->startTime, pAxle->endTime, pAxle->endTime - pAxle->startTime);

   // Process weight interval samples
   int n;
   for(n = 0; n < numSamples; n++)
   {
       DEBUG_MSG("%d\n", pAxle->wt[n]);
   }
}

MNBD_EVENT(MultiRcv)
{
   if(repeat_multi_record == 0x45)
   {
       if(wimScreenShowing && g_pMnBdCurSWIMAxle != NULL))
       {
           // Copy pointer to g_pMnBdCurSWIMAxle since it will get updated when next axle is read.
           struct mnbd_swim_struct* pAxle = g_pMnBdCurSWIMAxle;
           ProcessMnBdAxleRcvd(pAxle);
       }

   }
   else if(repeat_multi_record == 0)
   {
      // Handle regular weight display
   }
}

See Also

Last modified 4 years ago Last modified on 02/26/20 09:14:33
Note: See TracWiki for help on using the wiki.