| 28 |   | #include <stdio.h> | 
          
          
            | 29 |   | #include <stdlib.h> | 
          
          
            | 30 |   |  | 
          
          
            | 31 |   | #include "mnbdcomm.h" | 
          
          
            | 32 |   | #include "lcd.h" | 
          
          
            | 33 |   | #include "util.h" | 
          
          
            | 34 |   |  | 
          
          
            | 35 |   | int main() | 
          
          
            | 36 |   | { | 
          
          
            | 37 |   |    int n; | 
          
          
            | 38 |   |    char gross_wt_str[41]; | 
          
          
            | 39 |   |    CSleep slp(0, 5); | 
          
          
            | 40 |   |  | 
          
          
            | 41 |   |    InitLCD(); | 
          
          
            | 42 |   |    MnBdStartup(); | 
          
          
            | 43 |   |  | 
          
          
            | 44 |   |    while(1) | 
          
          
            | 45 |   |    { | 
          
          
            | 46 |   |       n = MnBdProcess(); | 
          
          
            | 47 |   |       if(n == mnbdProcWtRcv) | 
          
          
            | 48 |   |       { | 
          
          
            | 49 |   |           FormatGrossWt(GetProcessWt(), gross_wt_str); | 
          
          
            | 50 |   |           DisplayText(0, 0, gross_wt_str); | 
          
          
            | 51 |   |       } | 
          
          
            | 52 |   |       slp.Pause(); | 
          
          
            | 53 |   |    } | 
          
          
            | 54 |   |    return 0; | 
          
          
            | 55 |   | } | 
          
          
            | 56 |   |  | 
          
          
            | 57 |   | }}} | 
          
          
            | 58 |   |  | 
          
          
            | 59 |   | 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. | 
          
          
            | 60 |   |  | 
          
          
            | 61 |   | ==== Example of high Speed weighing of two scales using total mode ==== | 
          
          
            | 62 |   |  | 
          
          
            | 63 |   | {{{ | 
          
          
            | 64 |   | #include <stdio.h> | 
          
          
            | 65 |   | #include <stdlib.h> | 
          
          
            | 66 |   | #include <unistd.h> | 
          
          
            | 67 |   | #include <fcntl.h> | 
          
          
            | 68 |   |  | 
          
          
            | 69 |   | #include <string.h> | 
          
          
            | 70 |   |  | 
          
          
            | 71 |   | #include <math.h> | 
          
          
            | 72 |   | #include <time.h> | 
          
          
            | 73 |   |  | 
          
          
            | 74 |   | #include <signal.h> | 
          
          
            | 75 |   |  | 
          
          
            | 76 |   | #include "lcd.h" | 
          
          
            | 77 |   |  | 
          
          
            | 78 |   | #include "touch.h" | 
          
          
            | 79 |   | #include "kypdbeep.h" | 
          
          
            | 80 |   | #include "form.h" | 
          
          
            | 81 |   | #include "mnbdcomm.h" | 
          
          
            | 82 |   | #include "login.h" | 
          
          
            | 83 |   |  | 
          
          
            | 84 |   | extern struct mnbd_wt_struct wtdata[MAX_SCALES]; | 
          
          
            | 85 |   |  | 
          
          
            | 86 |   | extern uint32 g_nRepWtIntv; | 
          
          
            | 87 |   |  | 
          
          
            | 88 |   | extern int* pwim; | 
          
          
            | 89 |   |  | 
          
          
            | 90 |   | extern int g_keycnt; | 
          
          
            | 91 |   | extern uint8 g_keybuf[10]; | 
          
          
            | 92 |   |  | 
          
          
            | 93 |   | #define ON_THRES        3 | 
          
          
            | 94 |   | #define OFF_THRES       1 | 
          
          
            | 95 |   |  | 
          
          
            | 96 |   | int main () | 
          
          
            | 97 |   | { | 
          
          
            | 98 |   |         int i, x, stat, nSamplesPerSecond = 0; | 
          
          
            | 99 |   |         struct timespec delaytm; | 
          
          
            | 100 |   |         char szMsg[41]; | 
          
          
            | 101 |   |         time_t tnow; | 
          
          
            | 102 |   |         struct tm *tmnow; | 
          
          
            | 103 |   |         int prev_sec = -1; | 
          
          
            | 104 |   |          | 
          
          
            | 105 |   |         delaytm.tv_sec = 0; | 
          
          
            | 106 |   |         delaytm.tv_nsec = 20000000;  // 20 ms | 
          
          
            | 107 |   |  | 
          
          
            | 108 |   |         read_touch_cal(); | 
          
          
            | 109 |   |  | 
          
          
            | 110 |   |         OpenBeeper(); | 
          
          
            | 111 |   |  | 
          
          
            | 112 |   |         OpenMnBd(0); // Mainboard settings | 
          
          
            | 113 |   |          | 
          
          
            | 114 |   |         OpenTouch(); | 
          
          
            | 115 |   |          | 
          
          
            | 116 |   |         InitLCD(); | 
          
          
            | 117 |   |  | 
          
          
            | 118 |   |         read_current_operator(); | 
          
          
            | 119 |   |  | 
          
          
            | 120 |   |         OpenMnBd(0); | 
          
          
            | 121 |   |          | 
          
          
            | 122 |   |         OpenMnBd(TOT_SCALE); | 
          
          
            | 123 |   |  | 
          
          
            | 124 |   |          | 
          
          
            | 125 |   |         printf("Calling SetWIM %d\r\n", TOT_SCALE); | 
          
          
            | 126 |   |          | 
          
          
            | 127 |   |         SetWIM(TOT_SCALE, ON_THRES, OFF_THRES, 200); | 
          
          
            | 128 |   |  | 
          
          
            | 129 |   |         printf("after Calling SetWIM\r\n"); | 
          
          
            | 130 |   |          | 
          
          
            | 131 |   |         g_nRepWtIntv = REP_INTV_SAMPLE_RATE;  | 
          
          
            | 132 |   |         MnBdRequest(REQ_SCALE(0), MNBD_REQ_REP_WT, NO_WAIT_ACK); | 
          
          
            | 133 |   |  | 
          
          
            | 134 |   |         stat = 0; | 
          
          
            | 135 |   |          | 
          
          
            | 136 |   |         time(&tnow); | 
          
          
            | 137 |   |         tmnow = localtime(&tnow); | 
          
          
            | 138 |   |          | 
          
          
            | 139 |   |         while(1) | 
          
          
            | 140 |   |         { | 
          
          
            | 141 |   |                 ReadKeypad(); | 
          
          
            | 142 |   |                  | 
          
          
            | 143 |   |                 if(g_keycnt > 0) | 
          
          
            | 144 |   |                 { | 
          
          
            | 145 |   |                         g_keycnt = 0; | 
          
          
            | 146 |   |                         if(g_keybuf[0] == BKSP || g_keybuf[0] == ESC) | 
          
          
            | 147 |   |                                 break; | 
          
          
            | 148 |   |                 } | 
          
          
            | 149 |   |                  | 
          
          
            | 150 |   |                 nanosleep(&delaytm, NULL); | 
          
          
            | 151 |   |  | 
          
          
            | 152 |   |                 x = CheckWIM(TOT_SCALE); | 
          
          
            | 153 |   |                 if(x > 1) | 
          
          
            | 154 |   |                 { | 
          
          
            | 155 |   |                         if(stat == 0 && pwim[0] > ON_THRES) // Item on scale | 
          
          
            | 156 |   |                         { | 
          
          
            | 157 |   |                                 stat = 1; | 
          
          
            | 158 |   |                                 printf("On Scale\r\n"); | 
          
          
            | 159 |   |                         } | 
          
          
            | 160 |   |                          | 
          
          
            | 161 |   |                         printf("WIM samples %d\r\n", x); | 
          
          
            | 162 |   |                         for(i = 0; i < x; i += 2) | 
          
          
            | 163 |   |                         { | 
          
          
            | 164 |   |                                 printf("%d %.3f %.3f\r\n", i, *(float*)&pwim[i], *(float*)&pwim[i+1]); | 
          
          
            | 165 |   |                                 nSamplesPerSecond++; | 
          
          
            | 166 |   |                         } | 
          
          
            | 167 |   |                         sprintf(szMsg, "%10.3f %10.3f", *(float*)&pwim[x - 2], *(float*)&pwim[x - 1]); | 
          
          
            | 168 |   |                          | 
          
          
            | 169 |   |                         LocateLCD(0, 0); | 
          
          
            | 170 |   |                         PrintLCD(szMsg); | 
          
          
            | 171 |   |                          | 
          
          
            | 172 |   |                         time(&tnow); | 
          
          
            | 173 |   |                         tmnow = localtime(&tnow); | 
          
          
            | 174 |   |  | 
          
          
            | 175 |   |                         if(tmnow->tm_sec != prev_sec) | 
          
          
            | 176 |   |                         { | 
          
          
            | 177 |   |                                 LocateLCD(FONT_WIDTH * 30,0); | 
          
          
            | 178 |   |                                 sprintf(szMsg, "%02d %4d", tmnow->tm_sec, nSamplesPerSecond); | 
          
          
            | 179 |   |                                 PrintLCD(szMsg); | 
          
          
            | 180 |   |                                  | 
          
          
            | 181 |   |                                 prev_sec = tmnow->tm_sec; | 
          
          
            | 182 |   |                                 nSamplesPerSecond = 0; | 
          
          
            | 183 |   |                         } | 
          
          
            | 184 |   |                 } | 
          
          
            | 185 |   |                 else if(CheckWtRcv(0)) | 
          
          
            | 186 |   |                 { | 
          
          
            | 187 |   |                         if(stat != 0) | 
          
          
            | 188 |   |                         { | 
          
          
            | 189 |   |                                 if(wtdata[0].grosswt < OFF_THRES) | 
          
          
            | 190 |   |                                 { | 
          
          
            | 191 |   |                                         printf("Off Scale\r\n"); | 
          
          
            | 192 |   |                                          | 
          
          
            | 193 |   |                                         stat = 0; | 
          
          
            | 194 |   |                                 } | 
          
          
            | 195 |   |                         } | 
          
          
            | 196 |   |                 } | 
          
          
            | 197 |   |         } | 
          
          
            | 198 |   |          | 
          
          
            | 199 |   |         g_nRepWtIntv = 0;  | 
          
          
            | 200 |   |         MnBdRequest(REQ_SCALE(0), MNBD_REQ_REP_WT, WAIT_ACK); | 
          
          
            | 201 |   |          | 
          
          
            | 202 |   |         printf("Done\r\n"); | 
          
          
            | 203 |   |          | 
          
          
            | 204 |   |         return 0; | 
          
          
            | 205 |   | } | 
          
          
            | 206 |   |  | 
          
          
            | 207 |   |  | 
          
          
            | 208 |   | }}} | 
          
          
            | 209 |   |  | 
          
          
            | 210 |   | This sample demonstrates high speed weigh in motion using to the total scale to read two scales at a time. The display will show the gross weights of scales 1 and 2, the current second, and a count of samples per second. |