weight.c 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022
  1. #include <rtthread.h>
  2. #include "buffer.h"
  3. #include "button.h"
  4. #include "ring_buffer.h"
  5. #include "flash.h"
  6. #include <stdlib.h>
  7. #include "usart.h"
  8. #include "plan.h"
  9. #include "weight.h"
  10. #include "ad.h"
  11. #include "display.h"
  12. #include "stm32f1xx_hal.h"
  13. unsigned char isWeight = 0;
  14. static unsigned char WeightConst_RecFlag1 = 0; //正在接收重量标志 0xF0处理完成
  15. static unsigned char WeightConst_RecWeightPoint1 = 0; //接收重量指针
  16. static unsigned char WeightConst_RecWeightData1[250]; //接收重量临时表
  17. static unsigned char WeightConst_Drop=0; //抛弃数据
  18. static unsigned char WeightConst_WeightCount = 0; //重量数
  19. static signed short WeightConst_WeightMax = -32768; //最大重量
  20. static signed short WeightConst_WeightMin = 32767; //最小重量
  21. signed long WeightConst_WeightCurTem = 0; //当前临时重量
  22. unsigned char WeightConst_WeightCurTemZF = 1; //当前临时重量正负,用TMRII
  23. unsigned char WeightConst_WeightWS = 0; //小数位数
  24. unsigned char WeightConst_Weight_ZWS = 0; //整数位数
  25. signed short WeightConst_WeightLast; //上次按键重量 1S一次
  26. signed short WeightConst_WeightCur; //当前重量 1S一次
  27. signed short WeightConst_WeightOK; //OK重量 1S一次
  28. static unsigned char WeightConst_WeightCurCount = 0; //重量计数,用于每15秒取一次重量
  29. static signed short WeightConst_WeightCurTemLast = 0; //上次临时重量
  30. static unsigned short WeightConst_RecWeight_he1 = 0; //校验重量准确性
  31. static unsigned short WeightConst_RecWeight_he2 = 0; //校验重量准确性
  32. static unsigned short WeightConst_RecWeight_he3 = 0; //校验重量准确性
  33. static signed short WeightConst_WeightCur_last1=0;
  34. static signed short WeightConst_WeightCur_last2=0;
  35. static signed short WeightConst_WeightCur_last3=0;
  36. static long WeightConst_WeightSum = 0; //当前重量总和
  37. unsigned char WeightConst_oksum = 0; //符合目标重量数
  38. unsigned char WeightConst_allsum = 0; //总重量值数
  39. static unsigned char WeightConst_uoksum = 0;
  40. static unsigned char WeightConst_foksum = 0;
  41. static unsigned char WeightConst_uallsum = 0;
  42. unsigned char WeightConst_AutoSingleNSecondNum[30][3]; //自动跳转每秒值的数组
  43. unsigned char WeightConst_AutoSingleNSecondPoint = 0; //自动跳转的每秒的当前指针
  44. static unsigned char WeightConst_WeightTargetTpo = 65; //自动跳转的权重阀值固定为65%
  45. static unsigned char WeightConst_autotpo = 0; //自动跳转的权重阀值
  46. union timeweight_t timeweight;
  47. rt_sem_t weight_lock = RT_NULL;
  48. unsigned long mypow(unsigned char x,unsigned char y) {
  49. unsigned long z;
  50. if (y==0) z=1;
  51. else z=x;
  52. for (int i=1; i<y; i++)
  53. z = z*x;
  54. return z;
  55. }
  56. void weight_usart_Init(UART_HandleTypeDef* uartHandle)
  57. {
  58. extern unsigned char WeightConst_TQ;
  59. extern unsigned char iscowweight;
  60. if ((uartHandle->Instance==USART1) ||
  61. (uartHandle->Instance==USART2 && (WeightConst_BLE==1 || WeightConst_BLE==3)))
  62. {
  63. if (WeightConst_TQ==1)
  64. {
  65. uartHandle->Init.BaudRate = 9600;
  66. }
  67. else if (WeightConst_TQ==7)
  68. {
  69. //RCC_PCLK2Config(RCC_HCLK_Div2);
  70. uartHandle->Init.BaudRate = 600;
  71. }
  72. else if (WeightConst_TQ==4)
  73. uartHandle->Init.BaudRate = 19200;
  74. else if (WeightConst_TQ==8)
  75. uartHandle->Init.BaudRate = 38400;
  76. // else if (WeightConst_TQ==9)
  77. // uartHandle->Init.BaudRate = 1200;
  78. else if (WeightConst_TQ==9)
  79. {
  80. uartHandle->Init.BaudRate = 9600;
  81. uartHandle->Init.Parity = UART_PARITY_NONE;
  82. uartHandle->Init.WordLength = UART_WORDLENGTH_8B; //8位数据
  83. // uartHandle->Init.StopBits = UART_STOPBITS_2; //停止位2位 海丰需要
  84. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  85. }
  86. else if (WeightConst_TQ==10)
  87. {
  88. uartHandle->Init.BaudRate = 9600;
  89. uartHandle->Init.Parity = UART_PARITY_NONE;
  90. uartHandle->Init.WordLength = UART_WORDLENGTH_8B; //8位数据
  91. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  92. }
  93. else
  94. uartHandle->Init.BaudRate = 9600;
  95. if (iscowweight==1 ){
  96. uartHandle->Init.BaudRate = 19200;
  97. uartHandle->Init.Parity = UART_PARITY_NONE;
  98. uartHandle->Init.WordLength = UART_WORDLENGTH_9B; //8位数据
  99. uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  100. }
  101. }
  102. // else if ((uartHandle->Instance==USART3) && (iscowweight==1))
  103. // {
  104. // uartHandle->Init.BaudRate = 19200;
  105. // uartHandle->Init.Parity = UART_PARITY_EVEN;
  106. // uartHandle->Init.WordLength = UART_WORDLENGTH_9B; //8位数据
  107. // uartHandle->Init.StopBits = UART_STOPBITS_1; //停止位1位
  108. // }
  109. }
  110. static void setWeightSM() { // 设定合计重量
  111. if ((WeightConst_WeightCurTem > (WeightConst_WeightCurTemLast+1000) ||
  112. (WeightConst_WeightCurTem < (WeightConst_WeightCurTemLast - 1000) && WeightConst_WeightCurTem!=32768))
  113. && WeightConst_RecWeight_he3 < 3)
  114. {
  115. WeightConst_WeightCurTem = WeightConst_WeightCurTemLast;
  116. WeightConst_RecWeight_he3 ++;
  117. }
  118. else //if (WeightConst_WeightCurTem>-32768)
  119. {
  120. WeightConst_WeightCurTemLast = WeightConst_WeightCurTem;
  121. WeightConst_RecWeight_he3 = 0;
  122. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  123. if (WeightConst_WeightMax < WeightConst_WeightCurTem) WeightConst_WeightMax = WeightConst_WeightCurTem; //修改最大重量
  124. if (WeightConst_WeightMin > WeightConst_WeightCurTem) WeightConst_WeightMin = WeightConst_WeightCurTem; //修改最小重量
  125. WeightConst_WeightSum = WeightConst_WeightSum + WeightConst_WeightCurTem; // 重量和
  126. WeightConst_WeightCount++; // 重量采样数
  127. WeightConst_allsum++;
  128. rt_sem_release(weight_lock);
  129. //判断是否在范围内
  130. if(pf_comp.data.autosecond>0 && WeightConst_WeightHaveBegin==1) { //跳转时间大于0
  131. if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin &&
  132. WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMax && WeightConst_ChanCheShu>1)
  133. || (WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0 && WeightConst_ChanCheShu==1)) //大目标 为正,且当前值小于大目标
  134. {
  135. if ((WeightConst_SBType==4||WeightConst_SBType==6) && WeightConst_Stop==0 && isn==0) {
  136. rt_event_send(&display_event, EVENT_Stop);
  137. WeightConst_Stop=1;
  138. }
  139. WeightConst_oksum++;
  140. WeightConst_WeightOK=WeightConst_WeightCurTem;
  141. }
  142. //WeightConst_WeightTargetAllow
  143. if ((WeightConst_WeightCurTem>WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==0)
  144. ||(WeightConst_WeightCurTem<WeightConst_WeightTargetAllowMin && pf_comp.data.addorout==1))
  145. {
  146. alarm_on();
  147. //----------------------------if (WeightConst_SBType==5) ControlPlay(2, 1);
  148. }
  149. else if ((WeightConst_WeightCurTem < WeightConst_WeightTargetAllowMin && pf_comp.data.addorout == 0)
  150. || (WeightConst_WeightCurTem > WeightConst_WeightTargetAllowMin && pf_comp.data.addorout == 1))
  151. {
  152. //----------------------------if (WeightConst_SBType==5) ControlPlay(2, 0);
  153. alarm_off();
  154. }
  155. }
  156. }
  157. HAL_GPIO_TogglePin(led_GPIO_Port, led_Pin);
  158. }
  159. void sendWeight() {
  160. /* key0 协议 34字节(上报实时重量):0x7E 0x20 0x01 0xF0 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x01 1位起始位 + 1位长度 + 1位源地址 + 1位命令 + 28位重量(四段) + 1帧编号 + 1校验
  161. */
  162. if (rb_full_count(RecWeightQueue) > 28) {
  163. unsigned char buf[34] ;
  164. unsigned char CRCNum=0;
  165. buf[0]= 0x7E;
  166. buf[1]= 0x20;
  167. buf[2]= XbeeConst_DeviceAddress;
  168. buf[3]= 0xF0;
  169. for (int i=0; i <28; i++) buf[i+4]= rb_remove(RecWeightQueue);
  170. buf[32] = XbeeConst_FrameNum ++;
  171. for (int i=0; i< 33; i++) CRCNum+=buf[i];
  172. buf[33]= 0xff - CRCNum;
  173. for (int i=0; i <(int)(sizeof(buf)/sizeof(unsigned char)); i++)
  174. rb_push_insert(SendWeightQueue,buf[i]);
  175. }
  176. }
  177. void sendEIDWeight(unsigned char * eidbuf, signed short WeightCur) {
  178. /* key6 协议 34字节(上报电子称重):0x7E 0x0D 0x01 0xF6 0x00 0x00 0x00 0x00 0x00 0x00 0x00 1位起始位 + 1位长度 + 1位源地址 + 1位命令 + 7位耳标 + 2位重量 + 1帧编号 + 1校验
  179. */
  180. unsigned char buf[15] ;
  181. unsigned char CRCNum=0;
  182. if( eidbuf[0] == 5 && WeightCur>20){
  183. buf[0]= 0x7E;
  184. buf[1]= 0x0D;
  185. buf[2]= XbeeConst_DeviceAddress;
  186. buf[3]= 0xF6;
  187. for (int i=0; i <7; i++) buf[i+4]= eidbuf[i+1];
  188. buf[11]= (WeightCur>>8) &0xFF;
  189. buf[12]= WeightCur &0xFF;
  190. buf[13] = XbeeConst_FrameNum ++;
  191. for (int i=0; i< 14; i++) CRCNum+=buf[i];
  192. buf[14]= 0xff - CRCNum;
  193. for (int i=0; i <(int)(sizeof(buf)/sizeof(unsigned char)); i++)
  194. rb_push_insert(SendWeightQueue,buf[i]);
  195. }
  196. }
  197. void CheckWeightthread(void) {
  198. while (1) {
  199. if (pf_comp.data.delaytime>0 && WeightConst_DELAYON>0) //搅拌延时
  200. {
  201. WeightConst_DELAYTIME ++;
  202. if (WeightConst_DELAYTIME > (pf_comp.data.delaytime * 60)) //10 &&pf_comp.data.delaytime>0 )
  203. {
  204. write_Flash("begintime", &TimeConst, sizeof(TimeConst));
  205. // WeightConst_WeightBegin = WeightConst_WeightCur;
  206. // write_Flash("beginweight", &WeightConst_WeightBegin, sizeof(WeightConst_WeightBegin));
  207. // pf_comp.data.delaytime = 0;
  208. // WeightConst_DELAYON = 0;
  209. rt_sem_release(pop_product_sem);//弹出最新内容
  210. }
  211. }
  212. // else {
  213. // WeightConst_DELAYTIME = 0;
  214. // WeightConst_DELAYON=0;
  215. // }
  216. if ( WeightConst_allsum > 0) {
  217. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  218. if (WeightConst_WeightCount>2) {
  219. WeightConst_WeightSum = WeightConst_WeightSum - WeightConst_WeightMin; // 重量和 减去最小值
  220. WeightConst_WeightSum = WeightConst_WeightSum - WeightConst_WeightMax; // 重量和 减去最大值
  221. WeightConst_WeightCount = WeightConst_WeightCount - 2;
  222. }
  223. WeightConst_WeightCur = WeightConst_WeightSum / WeightConst_WeightCount;
  224. if (WeightConst_WeightCurCount >= 0x0F) { //15秒准备发送后台重
  225. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  226. timeweight.Buffer[3] =TimeConst.Buffer[0];
  227. timeweight.Buffer[4] =TimeConst.Buffer[1];
  228. timeweight.Buffer[5] =TimeConst.Buffer[2];
  229. timeweight.Buffer[6] =TimeConst.Buffer[3];
  230. rt_sem_release(setTIME_lock);
  231. timeweight.data.Weight = WeightConst_WeightCur;
  232. timeweight.data.WeightWS = WeightConst_WeightWS;
  233. timeweight.data.WeightRun = WeightConst_Product_Run;
  234. timeweight.data.reserved = 0;
  235. ts_pushArrary(&ts_weightdb, timeweight.Buffer, 7);
  236. WeightConst_WeightCur_last3 = WeightConst_WeightCur_last2;
  237. WeightConst_WeightCur_last2 = WeightConst_WeightCur_last1;
  238. WeightConst_WeightCur_last1 = WeightConst_WeightCur;
  239. // if (WeightConst_WeightCur<0)
  240. // rb_push_insert(RecWeightQueue, (0<<7) | (WeightConst_WeightWS<<6>>1));//这边有问题,需要修改
  241. // else
  242. // rb_push_insert(RecWeightQueue, (0<<7) | (WeightConst_WeightWS<<6>>1));//这边有问题,需要修改
  243. WeightConst_WeightCurCount=0;
  244. }
  245. rt_sem_release(weight_lock);
  246. if (WeightConst_AutoSingleNSecondPoint>=pf_comp.data.autosecond || WeightConst_AutoSingleNSecondPoint>=30)
  247. WeightConst_AutoSingleNSecondPoint = 0;
  248. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][0] = WeightConst_oksum;
  249. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][1] = WeightConst_allsum;
  250. if (//( WeightConst_WeightMax - WeightConst_WeightMin)>WeightConst_WeightTargetAllow &&
  251. WeightConst_WeightCur > WeightConst_WeightTargetAllowMax
  252. && pf_comp.data.autosecond>0 && WeightConst_WeightHaveBegin==1)
  253. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][2] = 1;
  254. else
  255. WeightConst_AutoSingleNSecondNum[WeightConst_AutoSingleNSecondPoint][2] = 0;
  256. WeightConst_WeightSum = 0;
  257. WeightConst_WeightCount = 0; //重量数
  258. WeightConst_WeightMax = -32768; //最大重量
  259. WeightConst_WeightMin = 32767; //最小重量
  260. WeightConst_AutoSingleNSecondPoint++;
  261. WeightConst_uoksum = 0;
  262. WeightConst_uallsum = 0;
  263. WeightConst_foksum = 0;
  264. for (int CheckWeight_i = 0; CheckWeight_i < pf_comp.data.autosecond; CheckWeight_i++) {
  265. WeightConst_uoksum = WeightConst_uoksum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][0];
  266. WeightConst_uallsum = WeightConst_uallsum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][1];
  267. WeightConst_foksum = WeightConst_foksum + WeightConst_AutoSingleNSecondNum[CheckWeight_i][2];
  268. }
  269. if (WeightConst_uallsum == 0)
  270. WeightConst_uallsum = 100; //如果没接称,allsum有可能为0,此处进行保护
  271. WeightConst_autotpo = WeightConst_uoksum * 100 / WeightConst_uallsum; //合理停留秒数内接收到的符合跳转的数据占总接收数据的百分比
  272. if (WeightConst_autotpo > 100) WeightConst_autotpo = 0; //对百分比进行保护
  273. if ((WeightConst_autotpo > WeightConst_WeightTargetTpo)
  274. || (WeightConst_foksum>(pf_comp.data.autosecond>>1) && pf_comp.data.JMP)
  275. ) //触发自动按键
  276. {
  277. for (int CheckWeight_i = 0; CheckWeight_i < 30; CheckWeight_i++) {
  278. WeightConst_AutoSingleNSecondNum[CheckWeight_i][0]=0;
  279. WeightConst_AutoSingleNSecondNum[CheckWeight_i][1]=0;
  280. WeightConst_AutoSingleNSecondNum[CheckWeight_i][2]=0;
  281. }
  282. if (WeightConst_DELAYON == 0 && delayKeying == 0)
  283. {
  284. rt_sem_release(delay_key_sem);
  285. sendkey1(0xF1, 0);
  286. }
  287. button_state.b1 = 1; //5秒内禁止按1键
  288. }
  289. WeightConst_oksum = 0;
  290. WeightConst_allsum = 0;
  291. WeightConst_uoksum = 0;
  292. WeightConst_uallsum = 0;
  293. WeightConst_foksum = 0;
  294. // sendWeight(); //检查是否需要保存实时重量
  295. }
  296. WeightConst_WeightCurCount++;
  297. if (WeightConst_Product_Run > 0)
  298. {
  299. if (WeightConst_Nextfeed[0] == 0x20){
  300. if (findNextplan()>0)
  301. rt_event_send(&display_event, EVENT_Next);
  302. }
  303. if (WeightConst_Product_Run_time < 65535 && WeightConst_Product_Run_time>0 && pf_comp.data.addorout==0)
  304. WeightConst_Product_Run_time++;
  305. }
  306. else WeightConst_Product_Run_time = 0;
  307. rt_thread_mdelay(998);
  308. }
  309. }
  310. static void P_300G0() {
  311. // 02 20 2D 20 20 20 36 37 2E 30 6B 67 03 -67.0KG
  312. // 02 20 20 20 20 20 36 37 2E 36 6B 7F 03
  313. // 02 2B 30 30 30 30 30 30 33 03
  314. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  315. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  316. {
  317. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  318. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //TDI300G0
  319. {
  320. if (WeightConst_RecWeightPoint1 == 12 && WeightConst_RecWeightData1[0] == 0x02) {
  321. WeightConst_WeightCurTem = 0;
  322. WeightConst_WeightWS = 0;
  323. WeightConst_Weight_ZWS = 0;
  324. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  325. if (WeightConst_RecWeightData1[ReadWeight_i + 3] >= 0x30 && WeightConst_RecWeightData1[ReadWeight_i + 3] <= 0x39) {
  326. WeightConst_WeightCurTem = WeightConst_WeightCurTem + (WeightConst_RecWeightData1[ReadWeight_i + 3] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  327. WeightConst_Weight_ZWS++;
  328. } else if (WeightConst_RecWeightData1[ReadWeight_i + 3] == 0x2E) {
  329. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  330. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  331. }
  332. }
  333. if (WeightConst_RecWeightData1[2] == 0x2D) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  334. setWeightSM();
  335. WeightConst_RecFlag1 = 0x00;
  336. WeightConst_Drop = 1; //开始抛弃数据
  337. }
  338. WeightConst_RecWeightPoint1 = 0; //指针还原
  339. } else
  340. WeightConst_RecWeightPoint1++;
  341. }
  342. else
  343. {
  344. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  345. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) {
  346. WeightConst_Drop = 0;
  347. WeightConst_RecWeightPoint1 = 0; //指针还原
  348. }
  349. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  350. {
  351. WeightConst_Drop = 0;
  352. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  353. WeightConst_RecWeightPoint1 = 1;
  354. WeightConst_RecFlag1 = 0x00;
  355. }
  356. else {
  357. WeightConst_Drop++;
  358. WeightConst_RecWeightPoint1++;
  359. }
  360. }
  361. }
  362. static void P_300G1() {
  363. // 02 2D 20 20 20 36 37 2E 30 6B 67 03 -67.0KG
  364. // 02 20 20 20 20 32 2E 33 30 6B 67 03
  365. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  366. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  367. {
  368. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  369. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //TDI300G0
  370. {
  371. if (WeightConst_RecWeightPoint1 == 11 && WeightConst_RecWeightData1[0] == 0x02) {
  372. WeightConst_WeightCurTem = 0;
  373. WeightConst_WeightWS = 0;
  374. WeightConst_Weight_ZWS = 0;
  375. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  376. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30 && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  377. WeightConst_WeightCurTem = WeightConst_WeightCurTem + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  378. WeightConst_Weight_ZWS++;
  379. } else if (WeightConst_RecWeightData1[ReadWeight_i + 2] == 0x2E) {
  380. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  381. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  382. }
  383. }
  384. if (WeightConst_RecWeightData1[1] == 0x2D) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  385. setWeightSM();
  386. WeightConst_RecFlag1 = 0x00;
  387. WeightConst_Drop = 1; //开始抛弃数据
  388. }
  389. WeightConst_RecWeightPoint1 = 0; //指针还原
  390. }
  391. else
  392. WeightConst_RecWeightPoint1++;
  393. }
  394. else
  395. {
  396. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  397. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) {
  398. WeightConst_Drop = 0;
  399. WeightConst_RecWeightPoint1 = 0; //指针还原
  400. }
  401. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  402. {
  403. WeightConst_Drop = 0;
  404. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  405. WeightConst_RecWeightPoint1 = 1;
  406. WeightConst_RecFlag1 = 0x00;
  407. }
  408. else {
  409. WeightConst_Drop++;
  410. WeightConst_RecWeightPoint1++;
  411. }
  412. }
  413. }
  414. static void P_TDI200I() {
  415. //02 2B 30 30 30 30 30 30 33 03
  416. //02 +/- 十万 万 千 百 十 个 小数点位数 03
  417. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  418. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  419. {
  420. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  421. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //英展电子秤
  422. {
  423. if (WeightConst_RecWeightPoint1 == 9 && WeightConst_RecWeightData1[0] == 0x02) {
  424. WeightConst_WeightCurTem = 0;
  425. WeightConst_WeightWS = 0;
  426. WeightConst_Weight_ZWS = 0;
  427. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  428. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30
  429. && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  430. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  431. + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  432. WeightConst_Weight_ZWS++;
  433. }
  434. WeightConst_WeightWS = WeightConst_RecWeightData1[8] - 0x30; //设置小数位数
  435. }
  436. if (WeightConst_RecWeightData1[1] != 0x2B)
  437. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  438. setWeightSM();
  439. WeightConst_RecFlag1 = 0x00;
  440. WeightConst_Drop = 1; //开始抛弃数据
  441. }
  442. WeightConst_RecWeightPoint1 = 0; //指针还原
  443. } else
  444. WeightConst_RecWeightPoint1++;
  445. }
  446. else
  447. {
  448. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  449. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //英展电子秤
  450. {
  451. WeightConst_Drop = 0;
  452. WeightConst_RecWeightPoint1 = 0; //指针还原
  453. }
  454. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  455. {
  456. WeightConst_Drop = 0;
  457. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  458. WeightConst_RecWeightPoint1 = 1;
  459. WeightConst_RecFlag1 = 0x00;
  460. }
  461. else {
  462. WeightConst_Drop++;
  463. WeightConst_RecWeightPoint1++;
  464. }
  465. }
  466. }
  467. static void P_XK3190_C8() {
  468. //兼容XK3118K9
  469. //02 2D 30 30 30 31 32 30 31 03
  470. //02 2D 30 30 30 31 32 30 31 31 46 03
  471. //02 +/- 0 1 2 3 4 5 点位数 03
  472. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  473. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  474. {
  475. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  476. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //英展电子秤
  477. {
  478. if (WeightConst_RecWeightPoint1 == 11 && WeightConst_RecWeightData1[0] == 0x02) {
  479. WeightConst_WeightCurTem = 0;
  480. WeightConst_WeightWS = 0;
  481. WeightConst_Weight_ZWS = 0;
  482. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  483. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30
  484. && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  485. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  486. + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  487. WeightConst_Weight_ZWS++;
  488. }
  489. }
  490. WeightConst_WeightWS = WeightConst_RecWeightData1[8] - 0x30; //设置小数位数
  491. if (WeightConst_WeightWS==1)
  492. {
  493. WeightConst_WeightWS = 0;
  494. WeightConst_WeightCurTem = WeightConst_WeightCurTem/10;
  495. }
  496. if (WeightConst_RecWeightData1[1] != 0x2B)
  497. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  498. setWeightSM();
  499. WeightConst_RecFlag1 = 0x00;
  500. WeightConst_Drop = 1; //开始抛弃数据
  501. }
  502. WeightConst_RecWeightPoint1 = 0; //指针还原
  503. } else {
  504. WeightConst_RecWeightPoint1++;
  505. }
  506. }
  507. else
  508. {
  509. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  510. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x03) //英展电子秤
  511. {
  512. WeightConst_Drop = 0;
  513. WeightConst_RecWeightPoint1 = 0; //指针还原
  514. }
  515. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  516. {
  517. WeightConst_Drop = 0;
  518. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  519. WeightConst_RecWeightPoint1 = 1;
  520. WeightConst_RecFlag1 = 0x00;
  521. }
  522. else {
  523. WeightConst_Drop++;
  524. WeightConst_RecWeightPoint1++;
  525. }
  526. }
  527. }
  528. static void P_AWH_30_SA() {
  529. //展会 //53 54 2C 47 53 2C 2B 20 20 30 2E 38 37 36 6B 67 0d 0a
  530. if (WeightConst_RecWeightPoint1>39) WeightConst_RecWeightPoint1 = 0; //指针还原
  531. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  532. {
  533. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  534. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  535. {
  536. if (WeightConst_RecWeightPoint1 == 17) {
  537. WeightConst_WeightCurTem = 0;
  538. WeightConst_WeightWS = 0;
  539. WeightConst_Weight_ZWS = 0;
  540. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  541. if (WeightConst_RecWeightData1[ReadWeight_i + 7] >= 0x30
  542. && WeightConst_RecWeightData1[ReadWeight_i + 7] <= 0x39) {
  543. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  544. + (WeightConst_RecWeightData1[ReadWeight_i + 7] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  545. WeightConst_Weight_ZWS++;
  546. } else if (WeightConst_RecWeightData1[ReadWeight_i + 7] == 0x2E) {
  547. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  548. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  549. }
  550. }
  551. if (WeightConst_RecWeightData1[6] != 0x2b)
  552. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  553. setWeightSM();
  554. WeightConst_RecFlag1 = 0x00;
  555. WeightConst_Drop = 1; //开始抛弃数据
  556. }
  557. WeightConst_RecWeightPoint1 = 0; //指针还原
  558. } else {
  559. WeightConst_RecWeightPoint1++;
  560. }
  561. }
  562. else
  563. {
  564. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  565. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  566. {
  567. WeightConst_Drop = 0;
  568. WeightConst_RecWeightPoint1 = 0; //指针还原
  569. WeightConst_RecFlag1 = 0x00;
  570. } else {
  571. WeightConst_Drop++;
  572. WeightConst_RecWeightPoint1++;
  573. }
  574. }
  575. }
  576. static void P_digi() {
  577. //2E 44 30 2D 20 20 2D 33 36 30 30 30 39 09
  578. //2E 44 30 2D 20 33 39 32 32 30 30 30 42 09
  579. //2E 44 30 74 54 6F 74 61 6C 20 57 65 69 67 68 74 20 38 09
  580. if (WeightConst_RecWeightPoint1>140) WeightConst_RecWeightPoint1 = 0; //指针还原
  581. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  582. if (WeightConst_RecFlag1 != 0xF0) //上一条完整数据没有处理完
  583. {
  584. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09 &&
  585. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10] == 0x2D) //英展电子秤
  586. {
  587. WeightConst_WeightWS = 0;
  588. WeightConst_Weight_ZWS = 0;
  589. WeightConst_WeightCurTem = 0;
  590. WeightConst_WeightCurTemZF = 0;
  591. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  592. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] >= 0x30
  593. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] <= 0x39) {
  594. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  595. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  596. WeightConst_Weight_ZWS++;
  597. } else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] == 0x2D)
  598. WeightConst_WeightCurTemZF = 1;
  599. }
  600. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  601. setWeightSM();
  602. WeightConst_RecFlag1 = 0x00;
  603. WeightConst_Drop = 0; //开始抛弃数据
  604. }
  605. WeightConst_RecWeightPoint1 = 0; //指针还原
  606. } else {
  607. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09) //英展电子秤
  608. {
  609. WeightConst_Drop = 0;
  610. WeightConst_RecWeightPoint1 = 0; //指针还原
  611. WeightConst_RecFlag1 = 0x00;
  612. }
  613. else WeightConst_RecWeightPoint1++;
  614. }
  615. }
  616. static void P_AWT_ZM303() {
  617. //展会 //20 20 20 20 20 31 37 34 20 6B 67 20 47 0D 0A
  618. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  619. if (WeightConst_RecWeightPoint1>50) WeightConst_RecWeightPoint1 = 0; //指针还原
  620. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  621. {
  622. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  623. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  624. {
  625. if (WeightConst_RecWeightPoint1 == 13 && WeightConst_RecWeightData1[0] == 0x3D) {
  626. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  627. WeightConst_WeightCurTem = 0;
  628. WeightConst_WeightCurTemZF = 0;
  629. WeightConst_WeightWS = 0;
  630. WeightConst_Weight_ZWS = 0;
  631. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  632. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30
  633. && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  634. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  635. + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30)
  636. * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  637. WeightConst_Weight_ZWS++;
  638. }
  639. }
  640. if (WeightConst_RecWeightData1[1] == 0x2D) WeightConst_WeightCurTemZF = 1;
  641. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  642. setWeightSM();
  643. WeightConst_RecFlag1 = 0x00;
  644. WeightConst_Drop = 0; //开始抛弃数据
  645. }
  646. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-6]==0x20 &&
  647. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-5]==0x6B ) {
  648. //20 20 20 20 20 31 37 34 20 6B 67 20 47 0D 0A
  649. //20 20 20 20 20 2D 31 38 20 6B 67 20 47 0D 0A
  650. WeightConst_WeightCurTem = 0;
  651. WeightConst_WeightCurTemZF = 0;
  652. WeightConst_WeightWS = 0;
  653. WeightConst_Weight_ZWS = 0;
  654. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  655. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 -12 + ReadWeight_i ] >= 0x30
  656. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 -12 + ReadWeight_i ] <= 0x39) {
  657. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  658. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 -12 + ReadWeight_i ] - 0x30)
  659. * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  660. WeightConst_Weight_ZWS++;
  661. }
  662. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 -12 + ReadWeight_i ] == 0x2D)
  663. WeightConst_WeightCurTemZF = 1;
  664. }
  665. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  666. setWeightSM();
  667. WeightConst_RecFlag1 = 0x00;
  668. WeightConst_Drop = 0; //开始抛弃数据
  669. }
  670. else if (WeightConst_RecWeightPoint1 == 43 && WeightConst_RecWeightData1[0] == 0x31) {
  671. // 31 2C 53 54 2C 20 20 20 20 20 20 20 2D 32 35 2C 20 20 20 20 20 20 20 20 20 20 20 30 2C 20 20 20 20 20 20 20 20 20 30 2C 6B 67 0D 0A
  672. WeightConst_WeightCurTem = 0;
  673. WeightConst_WeightCurTemZF = 0;
  674. WeightConst_WeightWS = 0;
  675. WeightConst_Weight_ZWS = 0;
  676. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  677. if (WeightConst_RecWeightData1[ReadWeight_i + 9] >= 0x30
  678. && WeightConst_RecWeightData1[ReadWeight_i + 9] <= 0x39) {
  679. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  680. + (WeightConst_RecWeightData1[ReadWeight_i + 9] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  681. WeightConst_Weight_ZWS++;
  682. }
  683. else if (WeightConst_RecWeightData1[ReadWeight_i + 9] == 0x2D)
  684. WeightConst_WeightCurTemZF = 1;
  685. }
  686. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  687. setWeightSM();
  688. WeightConst_RecFlag1 = 0x00;
  689. WeightConst_Drop = 0; //开始抛弃数据
  690. }
  691. WeightConst_RecWeightPoint1 = 0; //指针还原
  692. }
  693. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09 &&
  694. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10] == 0x2D) //英展电子秤
  695. {
  696. WeightConst_WeightWS = 0;
  697. WeightConst_Weight_ZWS = 0;
  698. WeightConst_WeightCurTem = 0;
  699. WeightConst_WeightCurTemZF = 0;
  700. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  701. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] >= 0x30
  702. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] <= 0x39) {
  703. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  704. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  705. WeightConst_Weight_ZWS++;
  706. } else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 9 + ReadWeight_i] == 0x2D)
  707. WeightConst_WeightCurTemZF = 1;
  708. }
  709. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  710. setWeightSM();
  711. WeightConst_RecFlag1 = 0x00;
  712. WeightConst_Drop = 0; //开始抛弃数据
  713. } else {
  714. WeightConst_RecWeightPoint1++;
  715. }
  716. }
  717. else
  718. {
  719. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  720. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  721. {
  722. WeightConst_Drop = 0;
  723. WeightConst_RecWeightPoint1 = 0; //指针还原
  724. WeightConst_RecFlag1 = 0x00;
  725. }
  726. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x09 ) //英展电子秤
  727. {
  728. WeightConst_Drop = 0;
  729. WeightConst_RecWeightPoint1 = 0; //指针还原
  730. WeightConst_RecFlag1 = 0x00;
  731. }
  732. else {
  733. WeightConst_Drop++;
  734. WeightConst_RecWeightPoint1++;
  735. }
  736. }
  737. }
  738. static void P_T_2000() {
  739. // 55 53 2C 47 53 20 20 20 20 32 2E 37 32 6B 67 0D 0A 2.72 不稳定
  740. // 53 54 2C 47 53 20 20 20 20 32 2E 34 33 6B 67 0D 0A 2.43 稳定
  741. // 55 53 2C 47 53 2D 20 20 20 30 2E 33 38 6B 67 0D 0A -0.38 不稳定
  742. // 77 6E 30 30 30 30 38 33 33 35 6B 67 0D 0A
  743. if (WeightConst_RecWeightPoint1>40) WeightConst_RecWeightPoint1 = 0; //指针还原
  744. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  745. {
  746. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  747. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A ||
  748. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x0D) //英展电子秤
  749. {
  750. if (WeightConst_RecWeightPoint1 >= 12) {
  751. WeightConst_WeightCurTem = 0;
  752. WeightConst_WeightWS = 0;
  753. WeightConst_Weight_ZWS = 0;
  754. if (WeightConst_RecWeightPoint1==12) {
  755. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  756. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 9] >= 0x30
  757. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 9] <= 0x39) {
  758. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  759. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 9] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  760. WeightConst_Weight_ZWS++;
  761. } else if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 90] == 0x2E) {
  762. WeightConst_WeightWS = 5 - ReadWeight_i; //设置小数位数
  763. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  764. }
  765. }
  766. } else if (WeightConst_RecWeightPoint1>=13) {
  767. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  768. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 10] >= 0x30
  769. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 10] <= 0x39) {
  770. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  771. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 10] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  772. WeightConst_Weight_ZWS++;
  773. } else if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 10] == 0x2E) {
  774. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  775. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  776. }
  777. }
  778. }
  779. if (WeightConst_RecWeightData1[3] == 0x2D)
  780. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  781. setWeightSM();
  782. WeightConst_RecFlag1 = 0x00;
  783. WeightConst_Drop = 0; //开始抛弃数据
  784. }
  785. WeightConst_RecWeightPoint1 = 0; //指针还原
  786. } else {
  787. WeightConst_RecWeightPoint1++;
  788. }
  789. }
  790. else
  791. {
  792. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  793. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  794. {
  795. WeightConst_Drop = 0;
  796. WeightConst_RecWeightPoint1 = 0; //指针还原
  797. }
  798. else {
  799. WeightConst_Drop++;
  800. WeightConst_RecWeightPoint1++;
  801. }
  802. }
  803. }
  804. static void P_HF() {
  805. // 01 10 00 01 00 02 04 00 00 17 9C 3D FA 01 10 00 01 00 02 10 08
  806. // 02 10 00 01 00 02 04 08 00 00 A2 BE FE 02 10 00 01 00 02 10 3B
  807. // 03 10 00 01 00 02 04 08 00 00 A4 3A 00 03 10 00 01 00 02 10 3B
  808. if (WeightConst_RecWeightPoint1>140) WeightConst_RecWeightPoint1 = 0; //指针还原
  809. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  810. if (WeightConst_RecFlag1 != 0xF0) //上一条完整数据没有处理完
  811. {
  812. if ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]&0xf0) == 0x10 &&
  813. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x02 &&
  814. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x00 &&
  815. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-3] == 0x01 &&
  816. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-4] == 0x00 &&
  817. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-5] == 0x10 &&
  818. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-6] == XbeeConst_DeviceAddress) //英展电子秤
  819. {
  820. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19] == XbeeConst_DeviceAddress)
  821. {
  822. WeightConst_WeightWS = 0;
  823. WeightConst_Weight_ZWS = 0;
  824. WeightConst_WeightCurTem = ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-11]<<16)
  825. |
  826. (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10]<<8)
  827. |
  828. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-9]);
  829. if ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-12]&0x08) == 0x08)
  830. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  831. setWeightSM();
  832. WeightConst_RecFlag1 = 0x00;
  833. WeightConst_Drop = 0; //开始抛弃数据
  834. }
  835. WeightConst_RecWeightPoint1 = 0; //指针还原
  836. } else {
  837. WeightConst_RecWeightPoint1++;
  838. }
  839. }
  840. else
  841. {
  842. WeightConst_RecWeightPoint1++;
  843. }
  844. }
  845. static void P_E_2000() {
  846. // 3D 30 30 30 30 31 30 30 0D 0A
  847. // 3D 2D 30 30 30 31 30 30 0D 0A
  848. if (WeightConst_RecWeightPoint1>40) WeightConst_RecWeightPoint1 = 0; //指针还原
  849. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  850. {
  851. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  852. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D) //英展电子秤
  853. {
  854. if (WeightConst_RecWeightPoint1 > 9) {
  855. WeightConst_WeightCurTem = 0;
  856. WeightConst_WeightWS = 0;
  857. WeightConst_Weight_ZWS = 0;
  858. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  859. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] >= 0x30
  860. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] <= 0x39) {
  861. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  862. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] - 0x30)
  863. * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  864. WeightConst_Weight_ZWS++;
  865. }
  866. }
  867. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-7] == 0x2D)
  868. {
  869. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  870. WeightConst_WeightCurTemZF = 1;
  871. }
  872. setWeightSM();
  873. WeightConst_RecFlag1 = 0x00;
  874. WeightConst_Drop = 1; //开始抛弃数据
  875. }
  876. WeightConst_RecWeightPoint1 = 0; //指针还原
  877. } else {
  878. WeightConst_RecWeightPoint1++;
  879. }
  880. }
  881. else
  882. {
  883. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  884. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0A) //英展电子秤
  885. {
  886. WeightConst_Drop = 0;
  887. WeightConst_RecWeightPoint1 = 0; //指针还原
  888. WeightConst_RecFlag1 = 0x00;
  889. }
  890. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x53 &&
  891. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x47 &&
  892. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x2C) {
  893. WeightConst_RecWeightData1[0] = 0x2C;
  894. WeightConst_RecWeightData1[1] = 0x47;
  895. WeightConst_RecWeightData1[2] = 0x53;
  896. WeightConst_RecWeightPoint1 = 2; //指针还原
  897. WeightConst_RecFlag1 = 0x00;
  898. WeightConst_Drop = 0;
  899. }
  900. else {
  901. WeightConst_Drop++;
  902. WeightConst_RecWeightPoint1++;
  903. }
  904. }
  905. }
  906. static void P_TMI_II() {
  907. //23 03 BD 18 00 2D 34 37 39 38 0A 00 0D 00 00 00 00 00 00 00 00 00 00 00 AF BA 04 - 4 7 9 8 //波特率19200
  908. //23 03 02 18 00 20 2D 31 38 32 0A 00 0D 00 00 00 00 00 00 00 00 00 00 00 7D FE 04
  909. //23 03 03 18 00 20 2D 31 38 32 0A 00 0D 00 00 00 00 00 00 00 00 00 00 00 D4 A3 04
  910. //23 03 04 18 00 20 2D 31 38 32 0A 00 0D 00 00 00 00 00 00 00 00 00 00 00 92 03 04 -182
  911. WeightConst_RecWeightPoint1++;
  912. if (WeightConst_RecWeightPoint1>53) WeightConst_RecWeightPoint1 = 0; //指针还原
  913. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  914. if (WeightConst_RecWeightPoint1>=1 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x03 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x23) {
  915. WeightConst_RecWeightData1[0] = 0x23;
  916. WeightConst_RecWeightData1[1] = 0x03;
  917. WeightConst_RecWeightPoint1 = 1; //指针还原
  918. WeightConst_RecFlag1 = 0x00;
  919. WeightConst_Drop = 0;
  920. }
  921. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  922. {
  923. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x04 ||
  924. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x00) //英展电子秤
  925. {
  926. if (WeightConst_RecWeightPoint1 == 26 && WeightConst_RecWeightData1[0] == 0x23 && WeightConst_RecWeightData1[1] == 0x03
  927. && WeightConst_RecWeightData1[10] == 0x0A) {
  928. WeightConst_WeightCurTem = 0;
  929. WeightConst_WeightCurTemZF = 0;
  930. WeightConst_WeightWS = 0;
  931. WeightConst_Weight_ZWS = 0;
  932. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  933. if (WeightConst_RecWeightData1[ReadWeight_i + 5] >= 0x30
  934. && WeightConst_RecWeightData1[ReadWeight_i + 5] <= 0x39) {
  935. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  936. + (WeightConst_RecWeightData1[ReadWeight_i + 5] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  937. WeightConst_Weight_ZWS++;
  938. } else if (WeightConst_RecWeightData1[ReadWeight_i + 5] == 0x2D) {
  939. WeightConst_WeightCurTemZF = 1;
  940. }
  941. }
  942. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  943. setWeightSM();
  944. WeightConst_RecFlag1 = 0x00;
  945. WeightConst_Drop = 1; //开始抛弃数据
  946. }
  947. }
  948. }
  949. /*
  950. else
  951. {
  952. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x04 || WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x00) //英展电子秤
  953. {
  954. WeightConst_Drop = 0;
  955. WeightConst_RecWeightPoint1 = 0; //指针还原
  956. } else {
  957. WeightConst_Drop++;
  958. WeightConst_RecWeightPoint1++;
  959. }
  960. }*/
  961. }
  962. static void P_TMI_III() {
  963. //0x20 0x2d 0x31 0x34 0x32 0x0d -142
  964. //2D 33 36 35 34 0D
  965. if (WeightConst_RecWeightPoint1>17) WeightConst_RecWeightPoint1 = 0; //指针还原
  966. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  967. {
  968. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  969. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D) //英展电子秤
  970. {
  971. if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x29 &&
  972. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-4] == 0x28 )
  973. { //3D 30 30 30 30 30 30 36 28 6B 67 29 0D 0A
  974. //3D 2D 30 30 30 30 36 34 28 6B 67 29 0D 0A
  975. WeightConst_WeightCurTem = 0;
  976. WeightConst_WeightCurTemZF = 0;
  977. WeightConst_WeightWS = 0;
  978. WeightConst_Weight_ZWS = 0;
  979. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  980. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(9-ReadWeight_i)] >= 0x30
  981. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(9-ReadWeight_i)] <= 0x39) {
  982. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  983. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(9-ReadWeight_i)] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  984. WeightConst_Weight_ZWS++;
  985. };
  986. }
  987. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-11] == 0x2D && WeightConst_WeightCurTemZF==0)
  988. {
  989. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  990. WeightConst_WeightCurTemZF = 1;
  991. }
  992. setWeightSM();
  993. WeightConst_RecFlag1 = 0x00;
  994. WeightConst_Drop = 1; //开始抛弃数据
  995. }
  996. /*else if (WeightConst_RecWeightPoint1>10 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x67 &&
  997. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x6B )
  998. {
  999. //77 6E 2D 30 30 30 30 30 35 31 6B 67 0D 0A
  1000. WeightConst_WeightCurTem = 0;
  1001. WeightConst_WeightCurTemZF = 0;
  1002. WeightConst_WeightWS = 0;
  1003. WeightConst_Weight_ZWS = 0;
  1004. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  1005. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(7-ReadWeight_i)] >= 0x30
  1006. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(7-ReadWeight_i)] <= 0x39) {
  1007. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1008. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(7-ReadWeight_i)] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  1009. WeightConst_Weight_ZWS++;
  1010. };
  1011. }
  1012. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-10] == 0x2D && WeightConst_WeightCurTemZF==0)
  1013. {
  1014. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1015. WeightConst_WeightCurTemZF = 1;
  1016. }
  1017. setWeightSM();
  1018. WeightConst_RecFlag1 = 0x00;
  1019. WeightConst_Drop = 1; //开始抛弃数据
  1020. }*/
  1021. else if (WeightConst_RecWeightPoint1>4 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] != 0x20) {
  1022. WeightConst_WeightCurTem = 0;
  1023. WeightConst_WeightCurTemZF = 0;
  1024. WeightConst_WeightWS = 0;
  1025. WeightConst_Weight_ZWS = 0;
  1026. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  1027. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] >= 0x30
  1028. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] <= 0x39) {
  1029. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1030. + (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  1031. WeightConst_Weight_ZWS++;
  1032. }
  1033. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-(5-ReadWeight_i)] == 0x2D)
  1034. WeightConst_WeightCurTemZF = 1;
  1035. }
  1036. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1037. if (WeightConst_RecWeightPoint1>6 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-7] == 0x2D && WeightConst_WeightCurTemZF==0)
  1038. {
  1039. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1040. WeightConst_WeightCurTemZF = 1;
  1041. }
  1042. setWeightSM();
  1043. WeightConst_RecFlag1 = 0x00;
  1044. WeightConst_Drop = 1; //开始抛弃数据
  1045. }
  1046. WeightConst_RecWeightPoint1 = 0; //指针还原
  1047. } else {
  1048. WeightConst_RecWeightPoint1++;
  1049. }
  1050. }
  1051. else
  1052. {
  1053. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1054. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D) //英展电子秤
  1055. {
  1056. WeightConst_Drop = 0;
  1057. WeightConst_RecWeightPoint1 = 0; //指针还原
  1058. }
  1059. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x20 ||
  1060. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x30 ||
  1061. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x3D ||
  1062. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x2D)
  1063. {
  1064. WeightConst_Drop = 0;
  1065. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  1066. WeightConst_RecWeightPoint1 = 1;
  1067. WeightConst_RecFlag1 = 0x00;
  1068. }
  1069. else {
  1070. WeightConst_Drop++;
  1071. WeightConst_RecWeightPoint1++;
  1072. }
  1073. }
  1074. }
  1075. static void P_EZ4300() {
  1076. //82 2D A0 A0 A0 B1 39 8D 库恩表头出来是7位数据,8位是校验位,将数据的高位去掉,则得到下面正确的数据
  1077. //02 2D 20 20 20 31 39 0D
  1078. if (WeightConst_RecWeightPoint1>10) WeightConst_RecWeightPoint1 = 0; //指针还原
  1079. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1080. {
  1081. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1) & 0x7F;
  1082. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  1083. {
  1084. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  1085. WeightConst_RecWeightPoint1 = 1;
  1086. WeightConst_RecFlag1 = 0x00;
  1087. WeightConst_Drop = 0;
  1088. }
  1089. else if (WeightConst_RecWeightPoint1 >= 7 && WeightConst_RecWeightData1[0] == 0x02 && WeightConst_RecWeightData1[6] != 0x20) {
  1090. WeightConst_WeightCurTem = 0;
  1091. WeightConst_WeightWS = 0;
  1092. WeightConst_Weight_ZWS = 0;
  1093. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  1094. if (WeightConst_RecWeightData1[ReadWeight_i + 2] >= 0x30
  1095. && WeightConst_RecWeightData1[ReadWeight_i + 2] <= 0x39) {
  1096. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1097. + (WeightConst_RecWeightData1[ReadWeight_i + 2] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  1098. WeightConst_Weight_ZWS++;
  1099. }
  1100. WeightConst_WeightWS = 0;
  1101. }
  1102. if (WeightConst_RecWeightData1[1] == 0x2D) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1103. setWeightSM();
  1104. WeightConst_RecFlag1 = 0x00;
  1105. WeightConst_Drop = 0; //开始抛弃数据
  1106. WeightConst_RecWeightPoint1 = 0; //指针还原
  1107. }
  1108. else WeightConst_RecWeightPoint1++;
  1109. }
  1110. else
  1111. {
  1112. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1)& 0x7F;
  1113. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x0D)
  1114. {
  1115. WeightConst_Drop = 0;
  1116. WeightConst_RecWeightPoint1 = 0; //指针还原
  1117. }
  1118. else if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x02)
  1119. {
  1120. WeightConst_RecWeightData1[0] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1];
  1121. WeightConst_RecWeightPoint1 = 1;
  1122. WeightConst_RecFlag1 = 0x00;
  1123. WeightConst_Drop = 0;
  1124. }
  1125. else {
  1126. WeightConst_Drop++;
  1127. WeightConst_RecWeightPoint1++;
  1128. }
  1129. }
  1130. }
  1131. static void P_TQ() {
  1132. // 7E 7E F0 10 55 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 AB FE
  1133. // 7E 7E F0 10 00 00 00 00 00 00 00 03 04 00 00 00 00 00 03 04 F2 FE
  1134. // 7E 7E F0 10 01 00 00 00 00 00 00 06 08 80 00 00 00 00 06 08 63 FE
  1135. // 7E 7E FF 10 01 00 00 00 00 00 00 06 08 80 00 00 00 00 06 08 54 FE
  1136. if (WeightConst_RecWeightPoint1>43) WeightConst_RecWeightPoint1 = 0; //指针还原
  1137. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1138. if (WeightConst_RecWeightPoint1>=1 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x7E && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x7E) {
  1139. WeightConst_RecWeightData1[0] = 0x7E;
  1140. WeightConst_RecWeightData1[1] = 0x7E;
  1141. WeightConst_RecWeightPoint1 = 1; //指针还原
  1142. WeightConst_RecFlag1 = 0x00;
  1143. WeightConst_Drop = 0;
  1144. }
  1145. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1146. {
  1147. if (WeightConst_RecWeightPoint1<44) {
  1148. if (WeightConst_RecWeightPoint1 >= 21 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-21]==0x7E
  1149. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-20]==0x7E
  1150. && (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19]==0xF0 || WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-19]==0xFF)
  1151. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-17]!=0x55) {
  1152. WeightConst_RecWeight_he2 = 0;
  1153. WeightConst_RecWeight_he1 = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]
  1154. + WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] * 256; //判断接收到的重量协议是否正确
  1155. for(int i=0; i<18; i++) WeightConst_RecWeight_he2 += WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2-i];
  1156. WeightConst_RecWeight_he2 = ~WeightConst_RecWeight_he2+1;
  1157. if (WeightConst_RecWeight_he1==WeightConst_RecWeight_he2)
  1158. {
  1159. WeightConst_WeightCurTem = 0;
  1160. WeightConst_WeightWS = 0;
  1161. WeightConst_Weight_ZWS = 0;
  1162. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1163. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 7] <= 0x09) {
  1164. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1165. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 7]) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1166. WeightConst_Weight_ZWS++;
  1167. }
  1168. }
  1169. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-8] == 0x80)
  1170. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1171. WeightConst_WeightWS = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1 - 16]; //设置小数位数
  1172. setWeightSM();
  1173. }
  1174. WeightConst_RecFlag1 = 0x00;
  1175. WeightConst_Drop = 1; //开始抛弃数据
  1176. WeightConst_RecWeightPoint1 = 0; //指针还原
  1177. } else
  1178. WeightConst_RecWeightPoint1++;
  1179. }
  1180. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1181. }
  1182. else
  1183. {
  1184. WeightConst_RecWeightPoint1++;
  1185. }
  1186. }
  1187. static void P_XL10000() {
  1188. // 02 2A 30 20 30 30 30 32 32 30 30 30 30 30 30 30 0D 33
  1189. if (WeightConst_RecWeightPoint1>38) WeightConst_RecWeightPoint1 = 0; //指针还原
  1190. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1191. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] & 0x7F;
  1192. if (WeightConst_RecWeightPoint1>=3 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02 ) {
  1193. WeightConst_RecWeightData1[0] = 0x02;
  1194. WeightConst_RecWeightPoint1 = 0; //指针还原
  1195. WeightConst_RecFlag1 = 0x00;
  1196. WeightConst_Drop = 0;
  1197. }
  1198. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1199. {
  1200. if (WeightConst_RecWeightPoint1<38) {
  1201. if (WeightConst_RecWeightPoint1 >= 17 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-17]==0x02
  1202. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x0D)
  1203. {
  1204. WeightConst_WeightCurTem = 0;
  1205. WeightConst_WeightWS = 0;
  1206. WeightConst_Weight_ZWS = 0;
  1207. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1208. if (WeightConst_RecWeightData1[ReadWeight_i + 4] >= 0x30
  1209. && WeightConst_RecWeightData1[ReadWeight_i + 4] <= 0x39) {
  1210. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1211. + (WeightConst_RecWeightData1[ReadWeight_i + 4] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1212. WeightConst_Weight_ZWS++;
  1213. }
  1214. }
  1215. if ((WeightConst_RecWeightData1[2] & 0x02) == 0x02)
  1216. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1217. WeightConst_WeightWS = 0; //设置小数位数
  1218. setWeightSM();
  1219. WeightConst_RecFlag1 = 0x00;
  1220. WeightConst_Drop = 1; //开始抛弃数据
  1221. WeightConst_RecWeightPoint1 = 0; //指针还原
  1222. } else
  1223. WeightConst_RecWeightPoint1++;
  1224. }
  1225. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1226. }
  1227. else
  1228. {
  1229. WeightConst_RecWeightPoint1++;
  1230. }
  1231. }
  1232. static void XK3190_A27E() {
  1233. // 77 6E 30 30 30 30 30 36 31 35 6B 67 0D 0A 615 boudrate=1200
  1234. // 77 6E 2D 30 30 30 30 30 36 35 6B 67 0D 0A -65
  1235. // 77 6E 2D 30 30 30 31 32 20 6B 67 0D 0A
  1236. // 77 6E 30 30 30 30 31 2E 32 6B 67 0D 0A
  1237. if (WeightConst_RecWeightPoint1>37) WeightConst_RecWeightPoint1 = 0; //指针还原
  1238. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1239. if ((WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x77 &&
  1240. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x6E) ||
  1241. (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x77 &&
  1242. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x77)) {
  1243. WeightConst_RecWeightData1[0] = 0x77;
  1244. WeightConst_RecWeightData1[1] = 0x6E;
  1245. WeightConst_RecWeightPoint1 = 1; //指针还原
  1246. WeightConst_RecFlag1 = 0x00;
  1247. WeightConst_Drop = 0;
  1248. }
  1249. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1250. {
  1251. if (WeightConst_RecWeightPoint1<15) {
  1252. if (WeightConst_RecWeightPoint1 >= 12
  1253. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1]==0x0D
  1254. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x0A) {
  1255. WeightConst_WeightCurTem = 0;
  1256. WeightConst_WeightWS = 0;
  1257. WeightConst_Weight_ZWS = 0;
  1258. if (WeightConst_RecWeightPoint1 == 13)
  1259. {
  1260. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  1261. if (WeightConst_RecWeightData1[ReadWeight_i+3] >= 0x30
  1262. && WeightConst_RecWeightData1[ReadWeight_i+3] <= 0x39) {
  1263. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1264. + (WeightConst_RecWeightData1[ReadWeight_i+3] - 0x30) * mypow(10, 6 - ReadWeight_i); //计算重量,无小数位的
  1265. WeightConst_Weight_ZWS++;
  1266. } else if (WeightConst_RecWeightData1[ReadWeight_i + 3] == 0x2E) {
  1267. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  1268. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  1269. }
  1270. }
  1271. }
  1272. else if(WeightConst_RecWeightPoint1 == 12)
  1273. {
  1274. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++) {
  1275. if (WeightConst_RecWeightData1[ReadWeight_i+3] >= 0x30
  1276. && WeightConst_RecWeightData1[ReadWeight_i+3] <= 0x39) {
  1277. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1278. + (WeightConst_RecWeightData1[ReadWeight_i+3] - 0x30) * mypow(10, 4 - ReadWeight_i); //计算重量,无小数位的
  1279. WeightConst_Weight_ZWS++;
  1280. } else if (WeightConst_RecWeightData1[ReadWeight_i + 2] == 0x2E) {
  1281. WeightConst_WeightWS = 6 - ReadWeight_i; //设置小数位数
  1282. WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  1283. }
  1284. }
  1285. if (WeightConst_WeightWS == 0) WeightConst_WeightCurTem = WeightConst_WeightCurTem / 10;
  1286. }
  1287. if (WeightConst_RecWeightData1[2] == 0x2D)
  1288. WeightConst_WeightCurTemZF = 1;
  1289. else WeightConst_WeightCurTemZF = 0;
  1290. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1291. //WeightConst_WeightWS = 0; //设置小数位数
  1292. setWeightSM();
  1293. WeightConst_RecFlag1 = 0x00;
  1294. WeightConst_Drop = 1; //开始抛弃数据
  1295. WeightConst_RecWeightPoint1 = 0; //指针还原
  1296. } else
  1297. WeightConst_RecWeightPoint1++;
  1298. }
  1299. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1300. }
  1301. else
  1302. {
  1303. WeightConst_RecWeightPoint1++;
  1304. }
  1305. }
  1306. static void P_NEWLabel() {
  1307. // 57 20 FC 01 29 00 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 44 C4 00 88 00 80 00 00 00 00 00 08 40 44 8C 00
  1308. // 20 20 20 20 20 20 20 4E 45 54 20 57 45 49 47 48 54 20 20 20 20 20 20 20 54 4F 54 41 4C 20 57 45 49 47
  1309. // 48 54 3A 20 20 20 20 20 20 20 20 31 35 20 58 80 5C
  1310. //4F 54 41 4C 20 57 45 49 47 48 54 3A 20 20 20 20 20 20 20 20 31 35 20
  1311. // 16 17 18 19 20 21
  1312. //波特率 115200
  1313. WeightConst_RecWeightPoint1++;
  1314. if (WeightConst_RecWeightPoint1>60) WeightConst_RecWeightPoint1 = 0; //指针还原
  1315. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1316. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x4F) {
  1317. WeightConst_RecWeightData1[0] = 0x4F;
  1318. WeightConst_RecWeightPoint1 = 0; //指针还原
  1319. WeightConst_RecFlag1 = 0x00;
  1320. WeightConst_Drop = 0;
  1321. }
  1322. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1323. {
  1324. // if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x74
  1325. // && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x68
  1326. // && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x67) //英展电子秤
  1327. {
  1328. //C9 74 2D 35 38 31 30 80 00 00 54 6F 74 61 6C 20 77 65 69 67 68 74
  1329. // if (WeightConst_RecWeightPoint1 == 22 && WeightConst_RecWeightData1[0] == 0xC9 && WeightConst_RecWeightData1[22] == 0x74) {
  1330. // if (WeightConst_RecWeightPoint1 == 6 && WeightConst_RecWeightData1[0] == 0x02) {
  1331. if (WeightConst_RecWeightPoint1 == 21 && WeightConst_RecWeightData1[0] == 0x4F && WeightConst_RecWeightData1[1] == 0x54 && WeightConst_RecWeightData1[2] == 0x41) {
  1332. WeightConst_WeightCurTem = 0;
  1333. WeightConst_WeightCurTemZF = 0;
  1334. WeightConst_WeightWS = 0;
  1335. WeightConst_Weight_ZWS = 0;
  1336. for (int ReadWeight_i = 0; ReadWeight_i < 7; ReadWeight_i++) {
  1337. if (WeightConst_RecWeightData1[ReadWeight_i + 16] >= 0x30
  1338. && WeightConst_RecWeightData1[ReadWeight_i + 16] <= 0x39) {
  1339. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1340. + (WeightConst_RecWeightData1[ReadWeight_i + 16] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1341. WeightConst_Weight_ZWS++;
  1342. } else if (WeightConst_RecWeightData1[ReadWeight_i + 16] == 0x2D) {
  1343. WeightConst_WeightCurTemZF = 1;
  1344. }
  1345. }
  1346. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1347. setWeightSM();
  1348. WeightConst_RecFlag1 = 0x00;
  1349. WeightConst_Drop = 1; //开始抛弃数据
  1350. }
  1351. }
  1352. }
  1353. }
  1354. static void P_PTM() {
  1355. // 02 30 30 54 4F 54 41 4C 20 57 45 49 47 48 54 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 4B 67 20 20 20 20 20 38 54 20 80 81 81 38 3E 03
  1356. //波特率 38400
  1357. WeightConst_RecWeightPoint1++;
  1358. if (WeightConst_RecWeightPoint1>68) WeightConst_RecWeightPoint1 = 0; //指针还原
  1359. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1360. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  1361. WeightConst_RecWeightData1[0] = 0x02;
  1362. WeightConst_RecWeightPoint1 = 0; //指针还原
  1363. WeightConst_RecFlag1 = 0x00;
  1364. WeightConst_Drop = 0;
  1365. }
  1366. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1367. {
  1368. // if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] == 0x74
  1369. // && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-1] == 0x68
  1370. // && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-2] == 0x67) //英展电子秤
  1371. {
  1372. //C9 74 2D 35 38 31 30 80 00 00 54 6F 74 61 6C 20 77 65 69 67 68 74
  1373. // if (WeightConst_RecWeightPoint1 == 22 && WeightConst_RecWeightData1[0] == 0xC9 && WeightConst_RecWeightData1[22] == 0x74) {
  1374. // if (WeightConst_RecWeightPoint1 == 6 && WeightConst_RecWeightData1[0] == 0x02) {
  1375. if (WeightConst_RecWeightPoint1 == 48 && WeightConst_RecWeightData1[0] == 0x02 && WeightConst_RecWeightData1[48] == 0x03) {
  1376. WeightConst_WeightCurTem = 0;
  1377. WeightConst_WeightCurTemZF = 0;
  1378. WeightConst_WeightWS = 0;
  1379. WeightConst_Weight_ZWS = 0;
  1380. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1381. if (WeightConst_RecWeightData1[ReadWeight_i + 35] >= 0x30
  1382. && WeightConst_RecWeightData1[ReadWeight_i + 35] <= 0x39) {
  1383. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1384. + (WeightConst_RecWeightData1[ReadWeight_i + 35] - 0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1385. WeightConst_Weight_ZWS++;
  1386. } else if (WeightConst_RecWeightData1[ReadWeight_i + 35] == 0x2D) {
  1387. WeightConst_WeightCurTemZF = 1;
  1388. }
  1389. }
  1390. if (WeightConst_WeightCurTemZF==1) WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1391. setWeightSM();
  1392. WeightConst_RecFlag1 = 0x00;
  1393. WeightConst_Drop = 1; //开始抛弃数据
  1394. }
  1395. }
  1396. }
  1397. }
  1398. static void P_XDNZ_BC02() {
  1399. // 02 22 32 20 30 30 30 30 30 33 30 30 30 30 30 30 0D -3
  1400. // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D 48
  1401. // 02 22 30 20 30 30 30 30 36 34 30 30 30 30 30 30 0D 64
  1402. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  1403. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1404. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] & 0x7F;
  1405. if (WeightConst_RecWeightPoint1>=1 && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  1406. WeightConst_RecWeightData1[0] = 0x02;
  1407. WeightConst_RecWeightPoint1 = 0; //指针还原
  1408. WeightConst_RecFlag1 = 0x00;
  1409. WeightConst_Drop = 0;
  1410. }
  1411. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1412. {
  1413. if (WeightConst_RecWeightPoint1<34) {
  1414. if (WeightConst_RecWeightPoint1 >= 16
  1415. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-16]==0x02
  1416. && (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-14]==0x30
  1417. || WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-14]==0x32)
  1418. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x0D) {
  1419. WeightConst_WeightCurTem = 0;
  1420. WeightConst_WeightWS = 0;
  1421. WeightConst_Weight_ZWS = 0;
  1422. // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D 48
  1423. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1424. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] >= 0x30
  1425. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] <= 0x39)
  1426. {
  1427. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1428. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] -0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1429. WeightConst_Weight_ZWS++;
  1430. }
  1431. }
  1432. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-14] == 0x32)
  1433. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1434. WeightConst_WeightWS = 0; //设置小数位数
  1435. setWeightSM();
  1436. WeightConst_RecFlag1 = 0x00;
  1437. WeightConst_Drop = 1; //开始抛弃数据
  1438. WeightConst_RecWeightPoint1 = 0; //指针还原
  1439. } else
  1440. WeightConst_RecWeightPoint1++;
  1441. }
  1442. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1443. }
  1444. else
  1445. {
  1446. WeightConst_RecWeightPoint1++;
  1447. }
  1448. }
  1449. static void P_ID511() {
  1450. // 02 3A 50 70 30 30 30 30 30 35 30 30 30 30 30 30 0D
  1451. // 02 22 30 20 30 30 30 30 34 38 30 30 30 30 30 30 0D
  1452. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  1453. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1454. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  1455. WeightConst_RecWeightData1[0] = 0x02;
  1456. WeightConst_RecWeightPoint1 = 0; //指针还原
  1457. WeightConst_RecFlag1 = 0x00;
  1458. WeightConst_Drop = 0;
  1459. }
  1460. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1461. {
  1462. if (WeightConst_RecWeightPoint1<34) {
  1463. if (WeightConst_RecWeightPoint1 >= 16
  1464. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-16]==0x02
  1465. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x0D) {
  1466. WeightConst_WeightCurTem = 0;
  1467. WeightConst_WeightWS = 0;
  1468. WeightConst_Weight_ZWS = 0;
  1469. // 02 3A 50 70 30 30 30 30 30 35 30 30 30 30 30 30 0D
  1470. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1471. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] >= 0x30
  1472. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] <= 0x39)
  1473. {
  1474. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1475. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 12] -0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1476. WeightConst_Weight_ZWS++;
  1477. }
  1478. }
  1479. //if ((WeightConst_RecWeightData1[2] & 0x02)>0)
  1480. // WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1481. if (WeightConst_RecWeightData1[2] ==0x62)
  1482. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1483. WeightConst_WeightWS = 0; //设置小数位数
  1484. setWeightSM();
  1485. WeightConst_RecFlag1 = 0x00;
  1486. WeightConst_Drop = 1; //开始抛弃数据
  1487. WeightConst_RecWeightPoint1 = 0; //指针还原
  1488. } else
  1489. WeightConst_RecWeightPoint1++;
  1490. }
  1491. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1492. }
  1493. else
  1494. {
  1495. WeightConst_RecWeightPoint1++;
  1496. }
  1497. }
  1498. static void P_AD250() {
  1499. // C9 20 20 20 20 33 38 3B 34 D9 38
  1500. // C9 20 20 C4 31 32 38 36 38 D9 -128
  1501. // C9 30 20 20 31 33 32 3C 3F D9 132
  1502. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  1503. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1504. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0xC9) {
  1505. WeightConst_RecWeightData1[0] = 0xC9;
  1506. WeightConst_RecWeightPoint1 = 0; //指针还原
  1507. WeightConst_RecFlag1 = 0x00;
  1508. WeightConst_Drop = 0;
  1509. }
  1510. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1511. {
  1512. if (WeightConst_RecWeightPoint1<34) {
  1513. if (WeightConst_RecWeightPoint1 >= 9
  1514. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1-9]==0xC9
  1515. && WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0xD9) {
  1516. WeightConst_WeightCurTem = 0;
  1517. WeightConst_WeightWS = 0;
  1518. WeightConst_Weight_ZWS = 0;
  1519. WeightConst_WeightCurTemZF = 0;
  1520. // C9 54 20 20 20 20 30 3C 3D D9
  1521. for (int ReadWeight_i = 0; ReadWeight_i < 6; ReadWeight_i++) {
  1522. if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 8] >= 0x30
  1523. && WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 8] <= 0x39)
  1524. {
  1525. WeightConst_WeightCurTem = WeightConst_WeightCurTem
  1526. + (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 8] -0x30) * mypow(10, 5 - ReadWeight_i); //计算重量,无小数位的
  1527. WeightConst_Weight_ZWS++;
  1528. }
  1529. else if (WeightConst_RecWeightData1[ReadWeight_i + WeightConst_RecWeightPoint1 - 8] == 0xC4)
  1530. WeightConst_WeightCurTemZF = 1;
  1531. }
  1532. if (WeightConst_WeightCurTemZF)
  1533. WeightConst_WeightCurTem = WeightConst_WeightCurTem * -1;
  1534. WeightConst_WeightWS = 0; //设置小数位数
  1535. setWeightSM();
  1536. WeightConst_RecFlag1 = 0x00;
  1537. WeightConst_Drop = 1; //开始抛弃数据
  1538. WeightConst_RecWeightPoint1 = 0; //指针还原
  1539. } else
  1540. WeightConst_RecWeightPoint1++;
  1541. }
  1542. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1543. }
  1544. else
  1545. {
  1546. WeightConst_RecWeightPoint1++;
  1547. }
  1548. }
  1549. extern unsigned char eid[10];
  1550. unsigned long long curEID = 0; //当前临时耳标
  1551. unsigned long long lastEID = 0; //上次临时耳标
  1552. static void ReadEID() {
  1553. // 02 03 00 16 00 0a 24 3a
  1554. // 02 03 14 ff 57 83 e7 00 6b 96 1d 5d 00 ff 10 43 e6 1c be 99 1a 15 df 5d 31
  1555. if (WeightConst_RecWeightPoint1>33) WeightConst_RecWeightPoint1 = 0; //指针还原
  1556. WeightConst_RecWeightData1[WeightConst_RecWeightPoint1] = rb_remove(rb_usart1);
  1557. if (WeightConst_RecWeightData1[WeightConst_RecWeightPoint1]==0x02) {
  1558. WeightConst_RecWeightData1[0] = 0x02;
  1559. WeightConst_RecWeightPoint1 = 0; //指针还原
  1560. WeightConst_RecFlag1 = 0x00;
  1561. WeightConst_Drop = 0;
  1562. }
  1563. if (WeightConst_RecFlag1 != 0xF0 && WeightConst_Drop==0) //上一条完整数据没有处理完
  1564. {
  1565. if (WeightConst_RecWeightPoint1<34) {
  1566. if (WeightConst_RecWeightPoint1 >= 3
  1567. && (WeightConst_RecWeightPoint1 >= WeightConst_RecWeightData1[2]+2)) {
  1568. // 02 03 14 ff 57 83 e7 00 6b 96 1d 5d 00 ff 10 43 e6 1c be 99 1a 15 df 5d 31
  1569. eid[0]=5;
  1570. for (int ReadWeight_i = 0; ReadWeight_i < 5; ReadWeight_i++)
  1571. eid[ReadWeight_i+1] = WeightConst_RecWeightData1[ReadWeight_i+7];
  1572. eid[eid[0]+1]= WeightConst_RecWeightData1[3];
  1573. eid[eid[0]+2]= WeightConst_RecWeightData1[4];
  1574. // eid[1]=0x00;eid[2]=0x0C;eid[3]=0x12;eid[4]=0x63;eid[5]=0xE0;
  1575. if (eid[eid[0]+1] ==0xFF){
  1576. WeightConst_feed[0]=0xCE;
  1577. WeightConst_feed[1]=0xDE;
  1578. WeightConst_feed[2]=0xB6;
  1579. WeightConst_feed[3]=0xFA;
  1580. WeightConst_feed[4]=0xB1;
  1581. WeightConst_feed[5]=0xEA;
  1582. WeightConst_feed[6]=0x20;
  1583. WeightConst_feed[7]=0x20;
  1584. }
  1585. else
  1586. {
  1587. curEID = 0;
  1588. for (int i = 0; i < eid[0]; i++) {
  1589. curEID = curEID << 8;
  1590. curEID = curEID | eid[i+1];
  1591. }
  1592. if (WeightConst_WeightCur>30 && lastEID != curEID)
  1593. {
  1594. sendEIDWeight(eid, WeightConst_WeightCur);
  1595. lastEID = curEID;
  1596. }
  1597. rt_memset(WeightConst_feed, 0x20, 40);
  1598. for (int SendDisplay_i = 0; SendDisplay_i < 8; SendDisplay_i++) {
  1599. if (SendDisplay_i>0) curEID=curEID/10;
  1600. if (abs(curEID)>0) WeightConst_feed[7-SendDisplay_i] = abs(curEID%10)+'0';
  1601. else break;
  1602. }
  1603. }
  1604. WeightConst_RecFlag1 = 0x00;
  1605. WeightConst_Drop = 1; //开始抛弃数据
  1606. WeightConst_RecWeightPoint1 = 0; //指针还原
  1607. } else
  1608. WeightConst_RecWeightPoint1++;
  1609. }
  1610. else WeightConst_RecWeightPoint1 = 0; //指针还原
  1611. }
  1612. else
  1613. {
  1614. WeightConst_RecWeightPoint1++;
  1615. }
  1616. }
  1617. void ReadWeight(void)
  1618. {
  1619. rt_sem_take(display_lock, RT_WAITING_FOREVER);
  1620. if (WeightConst_TQ==0)
  1621. P_XDNZ_BC02();
  1622. else if (WeightConst_TQ==1)
  1623. //P_300G0();
  1624. P_XDNZ_BC02();
  1625. //P_NEWLabel();
  1626. else if (WeightConst_TQ==2)
  1627. //P_300G1();
  1628. P_AWT_ZM303();
  1629. else if (WeightConst_TQ==3)
  1630. XK3190_A27E();
  1631. else if (WeightConst_TQ==4)
  1632. P_TMI_II();
  1633. else if (WeightConst_TQ==5)
  1634. P_TMI_III();
  1635. else if (WeightConst_TQ==6)
  1636. P_EZ4300();
  1637. else if (WeightConst_TQ==7)
  1638. //P_TQ();
  1639. P_AD250();
  1640. else if (WeightConst_TQ==8)
  1641. P_PTM();
  1642. else if (WeightConst_TQ==9)
  1643. P_T_2000();
  1644. //P_HF();
  1645. else if (WeightConst_TQ==10)
  1646. P_XL10000();
  1647. else if (WeightConst_TQ==11)
  1648. P_XK3190_C8();
  1649. else if (WeightConst_TQ==12)
  1650. P_TDI200I();
  1651. //P_E_2000();
  1652. else if (WeightConst_TQ==13)
  1653. P_ID511();
  1654. else if (WeightConst_TQ==14) {
  1655. if (iscowweight==1) {
  1656. ReadEID();
  1657. }
  1658. else {
  1659. while (rb_full_count(rb_usart1) > 0) {
  1660. rb_remove(rb_usart1);
  1661. }
  1662. }
  1663. }
  1664. rt_sem_release(display_lock);
  1665. }
  1666. uint16_t tempWeight;
  1667. uint16_t tempWeighttime = 0;
  1668. void ReadWeightthread(void) {
  1669. while(1)
  1670. {
  1671. if (WeightConst_TQ==14 );// && CanButton== 0x01);
  1672. {
  1673. tempWeight = get_weight();
  1674. rt_sem_take(display_lock, RT_WAITING_FOREVER);
  1675. if (nag) WeightConst_WeightCurTem = (signed long)(tempWeight*-1);
  1676. else WeightConst_WeightCurTem = (signed long)(tempWeight);
  1677. WeightConst_WeightWS = ad_Point;
  1678. setWeightSM();
  1679. rt_sem_release(display_lock);
  1680. }
  1681. rt_thread_mdelay(125);
  1682. }
  1683. }
  1684. union timekeyweight_t getTimeWeight(int i) {
  1685. if ((i==0xF1) && (WeightConst_WeightOK > -32768)) {
  1686. WeightConst_WeightLast = WeightConst_WeightOK; //保存按键时的重量
  1687. WeightConst_WeightOK = 0;
  1688. }
  1689. else {
  1690. rt_sem_take(weight_lock, RT_WAITING_FOREVER);
  1691. WeightConst_WeightLast = WeightConst_WeightCur; //保存按键时的重量
  1692. rt_sem_release(weight_lock);
  1693. }
  1694. union timekeyweight_t timekeyweight;
  1695. rt_sem_take(setTIME_lock, RT_WAITING_FOREVER);
  1696. timekeyweight.data.datetime.year = TimeConst.data.year;
  1697. timekeyweight.data.datetime.month = TimeConst.data.month;
  1698. timekeyweight.data.datetime.date = TimeConst.data.date;
  1699. timekeyweight.data.datetime.hh = TimeConst.data.hh;
  1700. timekeyweight.data.datetime.mm = TimeConst.data.mm;
  1701. timekeyweight.data.datetime.ss = TimeConst.data.ss;
  1702. rt_sem_release(setTIME_lock);
  1703. timekeyweight.data.WeightBegin = WeightConst_WeightBegin;
  1704. timekeyweight.data.WeightLast = WeightConst_WeightLast;
  1705. timekeyweight.data.WeightWS = WeightConst_WeightWS;
  1706. timekeyweight.data.WeightZF = 0;
  1707. timekeyweight.data.reserved = 0;
  1708. timekeyweight.data.WeightRun = 1;
  1709. // if (WeightConst_WeightLast < 0)
  1710. // s[8] = (0<<7) | (WeightConst_WeightWS<<6>>1);
  1711. // else
  1712. // s[8] = (0<<7) | (WeightConst_WeightWS<<6>>1);
  1713. return timekeyweight;
  1714. }
  1715. static rt_thread_t checkweight_tid = RT_NULL;
  1716. static rt_thread_t readweight_tid = RT_NULL;
  1717. void ReadWeight_thread(void)
  1718. {
  1719. if (WeightConst_TQ==14 )
  1720. {
  1721. readweight_tid = rt_thread_create("ReadWeight",
  1722. ReadWeightthread, RT_NULL,
  1723. 0x800,
  1724. 4, 5);
  1725. /* 如果获得线程控制块,启动这个线程 */
  1726. if (readweight_tid != RT_NULL) rt_thread_startup(readweight_tid);
  1727. }
  1728. }
  1729. void CheckWeight_thread(void)
  1730. {
  1731. checkweight_tid = rt_thread_create("CheckWeight",
  1732. CheckWeightthread, RT_NULL,
  1733. 0x400,
  1734. 4, 5);
  1735. /* 如果获得线程控制块,启动这个线程 */
  1736. if (checkweight_tid != RT_NULL) rt_thread_startup(checkweight_tid);
  1737. }
  1738. void ReadEIDthread(void) {
  1739. while (1) {
  1740. rt_sem_take(uart1_lock, RT_WAITING_FOREVER);
  1741. // 02 03 00 16 00 05 64 3E
  1742. // 02 03 00 16 00 0a 24 3a
  1743. usart1_send_data[0] = 0x02;
  1744. usart1_send_data[1] = 0x03;
  1745. usart1_send_data[2] = 0x00;
  1746. usart1_send_data[3] = 0x16;
  1747. usart1_send_data[4] = 0x00;
  1748. usart1_send_data[5] = 0x05;
  1749. usart1_send_data[6] = 0x64;
  1750. usart1_send_data[7] = 0x3e;
  1751. HAL_UART_Transmit_DMA(&huart1, usart1_send_data, 8); //remoteSerial
  1752. rt_thread_mdelay(50);
  1753. rt_sem_release(uart1_lock);
  1754. rt_thread_mdelay(1000);
  1755. }
  1756. }
  1757. static rt_thread_t readEID_tid = RT_NULL;
  1758. void ReadEID_thread(void)
  1759. {
  1760. extern unsigned char iscowweight;
  1761. if (iscowweight==1 )
  1762. {
  1763. readEID_tid = rt_thread_create("ReadEID",
  1764. ReadEIDthread, RT_NULL,
  1765. 0x200,
  1766. 4, 5);
  1767. /* 如果获得线程控制块,启动这个线程 */
  1768. if (readEID_tid != RT_NULL) rt_thread_startup(readEID_tid);
  1769. }
  1770. }