Weight.c
3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#include "includes.h"
#include "hardware.h"
#include "all_value.h"
short WeightAll;
short F_WeightInitVa;//称重校准值/KG
u8 TIM4_USART5_SendNums;//串口5发送信息时间计数
u16 F_WeightMax;
#if WeightEn==1
void UART5_IRQHandler(void)//串口5中断服务程序
{
u8 res;
OSIntEnter();
if(USART_GetITStatus(UART5, USART_IT_RXNE) != RESET)
{
res=USART_ReceiveData(UART5);
if(USART5_RX_CNT<Length_Usart5_RX)
{
USART5_RX_BUF[USART5_RX_CNT]=res; //记录接收到的值
if( ((res==0x01) && (USART5_RX_CNT==0))|
((res==0x03) && (USART5_RX_CNT==1))|
// ((res==0x24) && (USART5_RX_CNT==2))|
((USART5_RX_BUF[0]==0x01)&& (USART5_RX_BUF[1]==0x03)&& (USART5_RX_BUF[2]==0x24)) ){ CCD_M[1].Tim4_Usart56Nums=0;USART5_RX_CNT++;}//接收数据增加1
}
}
USART_ClearITPendingBit(UART5,USART_IT_RXNE);
OSIntExit();
}
void Weight_Data_Analysis(u8*Buffer)//相机数据解析+位置转换函数
{
u32 Va32;
u32 Weight;
u8 Va8[4];
u8 S_index;
if(USART5_RX_CNT==Length_Usart5_RX)
{
Weight=0;
if( (Buffer[0]==0x01) &&(Buffer[1]==0x03)&& (Buffer[2]==0x24) )
{
S_index=3;
Va8[3]=Buffer[S_index];
Va8[2]=Buffer[S_index+1];
Va8[1]=Buffer[S_index+2];
Va8[0]=Buffer[S_index+3];
memcpy(&Va32,Va8,4);//第1路压力数值
Weight+=Va32;
S_index=7;
Va8[3]=Buffer[S_index];
Va8[2]=Buffer[S_index+1];
Va8[1]=Buffer[S_index+2];
Va8[0]=Buffer[S_index+3];
memcpy(&Va32,Va8,4);//第2路压力数值
Weight+=Va32;
S_index=11;
Va8[3]=Buffer[S_index];
Va8[2]=Buffer[S_index+1];
Va8[1]=Buffer[S_index+2];
Va8[0]=Buffer[S_index+3];
memcpy(&Va32,Va8,4);//第3路压力数值
Weight+=Va32;
S_index=15;
Va8[3]=Buffer[S_index];
Va8[2]=Buffer[S_index+1];
Va8[1]=Buffer[S_index+2];
Va8[0]=Buffer[S_index+3];
memcpy(&Va32,Va8,4);//第4路压力数值
Weight+=Va32;//单位*0.1KG
Weight=Weight/10;//kg,
// if (Weight>F_WeightInitVa)WeightAll=Weight-F_WeightInitVa;
// else WeightAll=0;
WeightAll=(short)((float)Weight-(float)F_WeightInitVa);
if(SysKey==89)
{
if(VaIndexDW_R(&Touch_Contr,13))F_WeightInitVa=(short)Weight;//强制称重归零
}
}
memset(Buffer,0,9);
USART5_RX_CNT=0;
}
}
u8 USART5_SX_BUF[Length_Usart5_SX];
void Usart5_Sx_Deal(void)//称重发送指令信息
{
USART5_SX_BUF[0]=0x01;//通讯地址
USART5_SX_BUF[1]=0x03;
USART5_SX_BUF[2]=0x03;
USART5_SX_BUF[3]=0x00;
USART5_SX_BUF[4]=0x00;
USART5_SX_BUF[5]=0x12;
USART5_SX_BUF[6]=0xC5;
USART5_SX_BUF[7]=0x83;
}
#endif
void Weight_Pro(void)//相机相关程序外部总入口
{
#if WeightEn==1
if(VaIndexDW_R(&F_AgvContr,12))//有称重器件时
{ if (TIM4_USART5_SendNums>Usart5_SendPerNums)
{ Usart5_Sx_Deal();
usart5_senddata(Length_Usart5_SX,USART5_SX_BUF);
TIM4_USART5_SendNums=0;
}
Weight_Data_Analysis(USART5_RX_BUF);//称重信息解析
if (CCD_M[1].Tim4_Usart56Nums>100)
{ VaIndexW_W(&NodeOnLine,14,0);
Set_ErrID(59,1);} //ErrID=59;称重异常
else{ VaIndexW_W(&NodeOnLine,14,1);Set_ErrID(59,0);}
}
#endif
}