采集器数据采集器【采集器往外发的数据的格式】

来源:邓小平理论 发布时间:2019-07-06 14:31:13 点击:

GPRS 采集器往外发的数据的格式:?

dT1xx.x dS2 xx.x dp3 xx.x dD4 xx.x dT5 xx.x dN 6xx.x dT7 xx.x

x —表示数字的ASCII 码。

字母分大小写,字母是ASCII 码码

为了更好说明,我们将上、下位机部分程序如下:

GPRS 采集器接收的数据的格式:?

1、例如下位机CC2430通信程序

if (command == SENSOR_REPORT_CMD_ID)

{

// Received report from a sensor

sensorReading = pData[1];

// If tool available, write to serial port

if (pData[0] == TEMP1_REPORT) //温度1

{

uint8 strDevice[] = "d";

uint8 strTemp[] = "T";

tmpLen = (uint8)osal_strlen( (char*)strDevice );

pBuf = osal_memcpy( buf, strDevice, tmpLen );

_ltoa( source, pBuf, 16 );

//pBuf += 4;

//*pBuf++ = " ";

tmpLen = (uint8)osal_strlen( (char*)strTemp );

pBuf = osal_memcpy( pBuf, strTemp, tmpLen );

*pBuf++ = "1";

*pBuf++ = (sensorReading / 10 ) + "0"; // convent msb to ascii

Show_Buf[0]=(sensorReading / 10 ) + "0";

*pBuf++ = (sensorReading % 10 ) + "0"; // convert lsb to ascii

Show_Buf[1]=(sensorReading % 10 ) + "0";

*pBuf++ = "0";

Show_Buf[2]= " ";

Show_Buf[3]= " ";

*pBuf++ = "0";

//send_chn(Salinity);

OCM_send(0x90,0);

for(y=0;y

{OCM_send(Show_All[0][y],1);}

set_position(1,4);

for(z=0;z

{OCM_send(Show_Buf[z],1);}

}

else if ( pData[0] == SALINITY_REPORT ) //盐度

{

uint8 strDevice[] = "d";

uint8 strBattery[] = "S";

tmpLen = (uint8)osal_strlen( (char*)strBattery );

tmpLen = (uint8)osal_strlen( (char*)strDevice );

pBuf = osal_memcpy( buf, strDevice, tmpLen );

_ltoa( source, pBuf, 16 );

//pBuf += 4;

//*pBuf++ = " ";

pBuf = osal_memcpy( pBuf, strBattery, tmpLen );

*pBuf++ = "2";//这里的1以及后面再此行出现的数字指程序中之前定义的各参数的编码

*pBuf++ = (sensorReading / 100 ) + "0"; // convent msb to ascii

Show_Buf[0]=(sensorReading / 100 ) + "0";

*pBuf++ = ((sensorReading%100) / 10 ) + "0";

Show_Buf[1]=((sensorReading%100)/10)+"0";

*pBuf++ = "0"; // decimal point

Show_Buf[2]= ".";

*pBuf++ = (sensorReading % 10 ) + "0";

Show_Buf[3]= (sensorReading % 10 ) + "0";

OCM_send(0x90,0);

for(y=0;y

OCM_send(Show_All[1][y],1);

set_position(1,4);

for(z=0;z

OCM_send(Show_Buf[z],1);

}

else if ( pData[0] == PH_REPORT ) //PH

{

uint8 strDevice[] = "d";

uint8 strBattery[] = "p";

tmpLen = (uint8)osal_strlen( (char*)strBattery );

tmpLen = (uint8)osal_strlen( (char*)strDevice );

pBuf = osal_memcpy( buf, strDevice, tmpLen );

_ltoa( source, pBuf, 16 );

//pBuf += 4;

//*pBuf++ = " ";

pBuf = osal_memcpy( pBuf, strBattery, tmpLen );

*pBuf++ = "3";

*pBuf++=(sensorReading / 100 ) + "0";

Show_Buf[0]=(sensorReading / 100 ) + "0";

*pBuf++ = ((sensorReading % 100 ) /10) + "0";

Show_Buf[1]=((sensorReading % 100 ) /10) + "0";

*pBuf++ = "0"; // decimal point ( battery reading is in units of 0.1 V

Show_Buf[2]= ".";

*pBuf++ = (sensorReading % 10 ) + "0"; // convert lsb to ascii

Show_Buf[3]= (sensorReading % 10 ) + "0";

OCM_send(0x98,0);

for(y=0;y

{OCM_send(Show_All[2][y],1);}

set_position(3,4);

for(z=0;z

{OCM_send(Show_Buf[z],1);}

}

2、VB 编的上位机通信

Private Sub Winsock_DataArrival(Index As Integer, ByVal bytesTotal As Long) " 数据接受事件

Dim ReceiveStr As String

Dim i As Integer

Dim str As String

Dim s

Dim modul_num As String

Dim begin_code As String

Dim j As Integer

j = 0

"DoEvents

m_noDataDelay(Index) = 0

Winsock(Index).GetData ReceiveStr, vbString //此处为接收数据ReceiveStr

If j = 0 Then

j = 1

Graph1.ScaleTop = 50

Graph1.ScaleLeft = 0

Graph1.ScaleWidth = 50

Graph1.ScaleHeight = -50

Call drawline1

Graph2.ScaleTop = 14

Graph2.ScaleLeft = 0

Graph2.ScaleWidth = 50

Graph2.ScaleHeight = -14

Call drawline2

Graph3.ScaleTop = 50

Graph3.ScaleLeft = 0

Graph3.ScaleWidth = 50

Graph3.ScaleHeight = -50

Call drawline3

Graph4.ScaleTop = 50

Graph4.ScaleLeft = 0

Graph4.ScaleWidth = 50

Graph4.ScaleHeight = -50

Call drawline4

Graph5.ScaleTop = 20

Graph5.ScaleLeft = 0

Graph5.ScaleWidth = 50

Graph5.ScaleHeight = -20

Call drawline5

Graph6.ScaleTop = 5

Graph6.ScaleLeft = 0

Graph6.ScaleWidth = 50

Graph6.ScaleHeight = -5

Call drawline6

End If

strDataS = ReceiveStr //将数据赋值给strDataS

Call Receive

End Sub

PublicSubReceive() Dim i, y, h, r, w, z, d As Integer

Dim sm, sn, sm1, sn1, sm2, sn2, sm3, sn3, sm4, sn4, sm5, sn5 As String

Dim str, str1, str2, str3, str4, str5, str6, str7 As String

Static Vi%, Ui%, Wi%, Vii%, Uii%, Wii%

str = Trim(strDataS) //删除字符串首部和尾部的空格

" 盐度曲线

y = InStr(str, "S2") //将盐度的数值取出来进行处理

If y 0 Then

str1 = Mid(str, y + 2, 4)

sm = Left(str1, 2)

sn = Right(str1, 1)

TextSalt.Text = sm & "." & sn & "‰" //送窗口显示

sy = Val(sm & "." & sn)

If Vi = 0 Then

Vi = Vi + 1

Graph1.Cls " 清除图形

Call drawline1

x1old = 0

y1old = 0

Graph1.DrawWidth = 1.55

Graph1.Line (x1old, y1old)-(Vi, sy), vbBlack //绘线

Graph1.DrawWidth = 1

x1old = Vi

y1old = sy

Else

Graph1.DrawWidth = 1.5

Graph1.Line (x1old, y1old)-(Vi, sy), vbBlack " 绘线

Graph1.DrawWidth = 1

x1old = Vi

y1old = sy

End If

Vi = Vi + 1 "指针加1

If Vi > 50 Then Vi = 0 "判断是否到了绘图极限

End If

"PH 曲线

h = InStr(str, "p3") //取PH 数值

If h 0 Then

str2 = Mid(str, h + 2, 4)

sm1 = Left(str2, 2)

sn1 = Right(str2, 1)

PH.Text = sm1 & "." & sn1 //对数值进行处理 送窗口显示等

sh = Val(sm1 & "." & sn1)

If Vii = 0 Then

Vii = Vii + 1

Graph2.Cls " 清除图形

Call drawline2

x2old = 0

y2old = 0

Graph2.DrawWidth = 1.5

Graph2.Line (x2old, y2old)-(Vii, sh), vbBlack " 绘线

Graph2.DrawWidth = 1

x2old = Vii

y2old = sh

Else

Graph2.DrawWidth = 1.5

Graph2.Line (x2old, y2old)-(Vii, sh), vbBlack " 绘线

Graph2.DrawWidth = 1

x2old = Vii

y2old = sh

End If

Vii = Vii + 1 "指针加1

If Vii > 50 Then Vii = 0 "判断是否到了绘图极限

End If

" 溶氧曲线

r = InStr(str, "D4") //取溶氧数值

If r 0 Then

str3 = Mid(str, r + 2, 4)

sm2 = Left(str3, 2)

sn2 = Right(str3, 1)

TextDO.Text = sm2 & "." & sn2 & " mg/l" //对数值进行处理 送窗口显示等 sr = Val(sm2 & "." & sn2)

If Ui = 0 Then

Ui = Ui + 1

Graph3.Cls " 清除图形

Call drawline3

x3old = 0

y3old = 0

Graph3.DrawWidth = 1.5

Graph3.Line (x3old, y3old)-(Ui, sr), vbBlue " 绘线

Graph3.DrawWidth = 1

x3old = Ui

y3old = sr

Else

Graph3.DrawWidth = 1.5

Graph3.Line (x3old, y3old)-(Ui, sr), vbBlue " 绘线

Graph3.DrawWidth = 1

x3old = Ui

y3old = sr

End If

Ui = Ui + 1 "指针加1

If Ui > 50 Then Ui = 0 "判断是否到了绘图极限

End If

" 温度1曲线

w = InStr(str, "T1") //取温度1数值

If w 0 Then

str4 = Mid(str, w + 2, 4)

sm3 = Left(str4, 2)

sn3 = Right(str4, 1)

Temp1.Text = sm3 & "." & sn3 & " ℃" //对数值进行处理 送窗口显示等 sw = Val(sm3 & "." & sn3)

If Uii = 0 Then

Uii = Uii + 1

Graph4.Cls " 清除图形

Call drawline4

x4old = 0

y4old = 0

Graph4.DrawWidth = 1.5

Graph4.Line (x4old, y4old)-(Uii, sw), vbBlue " 绘线

Graph4.DrawWidth = 1

x4old = Uii

y4old = sw

Else

Graph4.DrawWidth = 1.5

Graph4.Line (x4old, y4old)-(Uii, sw), vbBlue " 绘线

Graph4.DrawWidth = 1

x4old = Uii

y4old = sw

End If

Uii = Uii + 1 "指针加1

If Uii > 50 Then Uii = 0 "判断是否到了绘图极限

End If

" 浊度曲线

z = InStr(str, "T5") //取浊度数值

If z 0 Then

str5 = Mid(str, z + 2, 4)

sm4 = Left(str5, 2)

sn4 = Right(str5, 1)

Textturb.Text = sm4 & "." & sn4 & "NTU" //对数值进行处理 送窗口显示等 sz = Val(sm4 & "." & sn4)

If Wi = 0 Then

Wi = Wi + 1

Graph5.Cls " 清除图形

Call drawline5

x5old = 0

y5old = 0

Graph5.DrawWidth = 1.5

Graph5.Line (x5old, y5old)-(Wi, sz), vbRed " 绘线

Graph5.DrawWidth = 1

x5old = Wi

y5old = sz

Else

Graph5.DrawWidth = 1.5

Graph5.Line (x5old, y5old)-(Wi, sz), vbRed "绘线

Graph5.DrawWidth = 1

x5old = Wi

y5old = sz

End If

Wi = Wi + 1 "指针加1

If Wi > 50 Then Wi = 0 "判断是否到了绘图极限

End If

" 亚硝酸盐曲线

d = InStr(str, "N6" ) //取亚硝酸盐数值

If d 0 Then

str6 = Mid(str, d + 2, 4)

sm5 = Left(str6, 2)

sn5 = Right(str6, 1)

Temp2.Text = sm5 & "." & sn5 & " m" //对数值进行处理 送窗口显示等 sd = Val(sm5 & "." & sn5)

If Wii = 0 Then

Wii = Wii + 1

Graph6.Cls " 清除图形

Call drawline6

x6old = 0

y6old = 0

Graph6.DrawWidth = 1.5

Graph6.Line (x6old, y6old)-(Wii, sd), vbRed " 绘线

Graph6.DrawWidth = 1

x6old = Wii

y6old = sd

Else

Graph6.DrawWidth = 1.5

Graph6.Line (x6old, y6old)-(Wi, sd), vbRed "绘线

Graph6.DrawWidth = 1

x6old = Wii

y6old = sd

End If

Wii = Wii + 1 "指针加1

If Wii > 50 Then Wii = 0 "判断是否到了绘图极限

End If strDataS = "" End Sub

推荐访问:
上一篇:莱芜项目冷热源方案论证_冷热源
下一篇:最后一页

Copyright @ 2013 - 2018 红色文库网_诗词鉴赏_国学_散文 All Rights Reserved

红色文库网_诗词鉴赏_国学_散文 版权所有 湘ICP备11019447号-75