| 22 | | The lib825 library provides features to facilitate access the weight information from an application program. |
| 23 | | |
| 24 | | ==== Cardinal Weighing Library Functions ==== |
| 25 | | |
| 26 | | Header file: mnbdcomm.h |
| 27 | | |
| 28 | | void MnBdStartup() - Opens devices for weight and other external communications |
| 29 | | Parameters - None |
| 30 | | Return value - None |
| 31 | | |
| 32 | | int MnBdProcess() - Services devices checking for weight or other data received |
| 33 | | Parameters - None |
| 34 | | Return value - 0 = idle |
| 35 | | mnbdProcWtRcv = weight data received |
| 36 | | |
| 37 | | float GetGrossWt(int scale) - Returns the gross weight |
| 38 | | Parameters - scale = scale number |
| 39 | | Return value - weight |
| 40 | | |
| 41 | | float GetTareWt(int scale) - Returns the tare weight |
| 42 | | Parameters - scale = scale number |
| 43 | | Return value - weight |
| 44 | | |
| 45 | | float GetNetWt(int scale) - Returns the net weight |
| 46 | | Parameters - scale = scale number |
| 47 | | Return value - weight |
| 48 | | |
| 49 | | byte GetWtStatus(int scale) |
| 50 | | Parameters - scale = scale number |
| 51 | | Return value - status byte bitmapped - possible bits |
| 52 | | nStatusBitMotion |
| 53 | | nStatusBitOverCap |
| 54 | | nStatusBitBelowZero |
| 55 | | nStatusBitCenterZero |
| 56 | | nStatusBitError |
| 57 | | nStatusBitKeypadTare |
| 58 | | |
| 59 | | bool GetMotion(int scale) |
| 60 | | Parameters - scale = scale number |
| 61 | | Return value - true if specified scale is in motion, otherwise false |
| 62 | | |
| 63 | | bool GetOverCap(int scale) |
| 64 | | Parameters - scale = scale number |
| 65 | | Return value - true if specified scale is in over capacity, otherwise false |
| 66 | | |
| 67 | | bool GetBelowZero(int scale) |
| 68 | | Parameters - scale = scale number |
| 69 | | Return value - true if specified scale is below zero, otherwise false |
| 70 | | |
| 71 | | bool GetCenterZero(int scale) |
| 72 | | Parameters - scale = scale number |
| 73 | | Return value - true if specified scale is at center of zero, otherwise false |
| 74 | | |
| 75 | | bool GetWtError(int scale) |
| 76 | | Parameters - scale = scale number |
| 77 | | Return value - true if specified scale is in weight error condition, otherwise false |
| 78 | | |
| 79 | | bool GetKeypadTare(int scale) |
| 80 | | Parameters - scale = scale number |
| 81 | | Return value - true if specified scale is in weight error condition, otherwise false |
| 82 | | |
| 83 | | int GetWtMode(int scale) |
| 84 | | Parameters - scale = scale number |
| 85 | | Return value - wtmode_gross, or wtmode_net mode of the specified scale |
| 86 | | |
| 87 | | void ToggleWtMode(int scale) - Toggles the specified scale between gross and net modes |
| 88 | | Parameters - scale = scale number |
| 89 | | Return value - None |
| 90 | | |
| 91 | | void SetWtMode(int scale, int wtmode) |
| 92 | | Parameters - scale = scale number |
| 93 | | wtmode = wtmode_gross, or wtmode_net |
| 94 | | Return value - None |
| 95 | | |
| 96 | | int GetNumScales(void) |
| 97 | | Parameters - None |
| 98 | | Return value - Number of scales |
| 99 | | |
| 100 | | char* FormatGrossWt(int scale, char* buf) |
| 101 | | Parameters - scale = scale number |
| 102 | | buf = character array buffer for output |
| 103 | | Return value - Pointer to buffer for convenience |
| 104 | | |
| 105 | | |
| 106 | | |
| 107 | | |
| 108 | | |
| 109 | | |
| 110 | | |
| 111 | | |
| | 22 | The lib825ev library provides features to facilitate access the weight information from an application program. |
| | 61 | {{{ |
| | 62 | #include <stdio.h> |
| | 63 | #include <stdlib.h> |
| | 64 | #include <unistd.h> |
| | 65 | #include <fcntl.h> |
| | 66 | |
| | 67 | #include <string.h> |
| | 68 | |
| | 69 | #include <math.h> |
| | 70 | #include <time.h> |
| | 71 | |
| | 72 | #include <signal.h> |
| | 73 | |
| | 74 | #include "lcd.h" |
| | 75 | |
| | 76 | #include "touch.h" |
| | 77 | #include "kypdbeep.h" |
| | 78 | #include "form.h" |
| | 79 | #include "mnbdcomm.h" |
| | 80 | #include "login.h" |
| | 81 | |
| | 82 | extern struct mnbd_wt_struct wtdata[MAX_SCALES]; |
| | 83 | |
| | 84 | extern uint32 g_nRepWtIntv; |
| | 85 | |
| | 86 | extern int* pwim; |
| | 87 | |
| | 88 | extern int g_keycnt; |
| | 89 | extern uint8 g_keybuf[10]; |
| | 90 | |
| | 91 | #define ON_THRES 3 |
| | 92 | #define OFF_THRES 1 |
| | 93 | |
| | 94 | int main () |
| | 95 | { |
| | 96 | int i, x, stat, n = 0; |
| | 97 | struct timespec delaytm; |
| | 98 | char szMsg[41]; |
| | 99 | time_t tnow; |
| | 100 | struct tm *tmnow; |
| | 101 | int prev_sec = -1; |
| | 102 | |
| | 103 | delaytm.tv_sec = 0; |
| | 104 | delaytm.tv_nsec = 20000000; // 20 ms |
| | 105 | |
| | 106 | read_touch_cal(); |
| | 107 | |
| | 108 | OpenBeeper(); |
| | 109 | |
| | 110 | OpenMnBd(0); // Mainboard settings |
| | 111 | |
| | 112 | OpenTouch(); |
| | 113 | |
| | 114 | InitLCD(); |
| | 115 | |
| | 116 | read_current_operator(); |
| | 117 | |
| | 118 | OpenMnBd(0); |
| | 119 | |
| | 120 | OpenMnBd(TOT_SCALE); |
| | 121 | |
| | 122 | |
| | 123 | printf("Calling SetWIM %d\r\n", TOT_SCALE); |
| | 124 | |
| | 125 | SetWIM(TOT_SCALE, ON_THRES, OFF_THRES, 200); |
| | 126 | |
| | 127 | printf("after Calling SetWIM\r\n"); |
| | 128 | |
| | 129 | g_nRepWtIntv = REP_INTV_SAMPLE_RATE; |
| | 130 | MnBdRequest(REQ_SCALE(0), MNBD_REQ_REP_WT, NO_WAIT_ACK); |
| | 131 | |
| | 132 | stat = 0; |
| | 133 | |
| | 134 | time(&tnow); |
| | 135 | tmnow = localtime(&tnow); |
| | 136 | |
| | 137 | while(1) |
| | 138 | { |
| | 139 | ReadKeypad(); |
| | 140 | |
| | 141 | if(g_keycnt > 0) |
| | 142 | { |
| | 143 | g_keycnt = 0; |
| | 144 | if(g_keybuf[0] == BKSP || g_keybuf[0] == ESC) |
| | 145 | break; |
| | 146 | } |
| | 147 | |
| | 148 | nanosleep(&delaytm, NULL); |
| | 149 | |
| | 150 | x = CheckWIM(TOT_SCALE); |
| | 151 | if(x > 1) |
| | 152 | { |
| | 153 | if(stat == 0 && pwim[0] > ON_THRES) // Item on scale |
| | 154 | { |
| | 155 | stat = 1; |
| | 156 | printf("On Scale\r\n"); |
| | 157 | } |
| | 158 | |
| | 159 | printf("WIM samples %d\r\n", x); |
| | 160 | for(i = 0; i < x; i += 2) |
| | 161 | { |
| | 162 | printf("%d %.3f %.3f\r\n", i, *(float*)&pwim[i], *(float*)&pwim[i+1]); |
| | 163 | n++; |
| | 164 | } |
| | 165 | sprintf(szMsg, "%10.3f %10.3f", *(float*)&pwim[x - 2], *(float*)&pwim[x - 1]); |
| | 166 | |
| | 167 | LocateLCD(0, 0); |
| | 168 | PrintLCD(szMsg); |
| | 169 | |
| | 170 | time(&tnow); |
| | 171 | tmnow = localtime(&tnow); |
| | 172 | |
| | 173 | if(tmnow->tm_sec != prev_sec) |
| | 174 | { |
| | 175 | LocateLCD(FONT_WIDTH * 30,0); |
| | 176 | sprintf(szMsg, "%02d %4d", tmnow->tm_sec, n); |
| | 177 | PrintLCD(szMsg); |
| | 178 | |
| | 179 | prev_sec = tmnow->tm_sec; |
| | 180 | n = 0; |
| | 181 | } |
| | 182 | } |
| | 183 | else if(ind_check_for_wt_rcv(0)) |
| | 184 | { |
| | 185 | if(stat != 0) |
| | 186 | { |
| | 187 | if(wtdata[0].grosswt < OFF_THRES) |
| | 188 | { |
| | 189 | printf("Off Scale\r\n"); |
| | 190 | |
| | 191 | stat = 0; |
| | 192 | } |
| | 193 | } |
| | 194 | } |
| | 195 | } |
| | 196 | |
| | 197 | g_nRepWtIntv = 0; |
| | 198 | MnBdRequest(REQ_SCALE(0), MNBD_REQ_REP_WT, NO_WAIT_ACK); |
| | 199 | |
| | 200 | printf("Done\r\n"); |
| | 201 | |
| | 202 | return 0; |
| | 203 | } |
| | 204 | |
| | 205 | }}} |