毕设基于以太网的蓝牙多点测温系统,stm32做服务器,将采集的温度通过以太网送到PC端,PC做客户端,可以通过以太网设置温度,保存成excel和进行折线图的绘制,但是由于能力问题用起来失灵时不灵,会出现40006和40020错误和10048错误,求大神指教
Private Sub Command1_Click() ‘连接按键
If tcpClient.State <> 0 Then
tcpClient.Close
End If
tcpClient.Connect
Timer1.Enabled = True ’开启定时器,定时发送POST采集温度
Command1.Enabled = False ’连接按键失能,防止误操作
End Sub
Private Sub Command2_Click() ‘保存成excel表格
Timer1.Enabled = False
Dim i
Dim j As String
Dim at As String
Dim bt As String
Dim Ti As String
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Users\lenovo\Desktop\123.xls")
Set xlSheet = xlBook.Worksheets(1) '引用第1张工作表As Long
xlSheet.Range("A1") = "序号"
xlSheet.Range("B1") = "A点温度"
xlSheet.Range("C1") = "B点温度"
xlSheet.Range("D1") = "请求发出时间"
xlSheet.Range("D1") = "收到回复时间"
For i = 1 To ListView1.ListItems.Count
j = "A" + CStr(i + 1)
at = "B" + CStr(i + 1)
bt = "C" + CStr(i + 1)
Ti = "D" + CStr(i + 1)
xlSheet.Range(j) = i '可使用Cells属性进行赋值
xlSheet.Range(at) = ListView1.ListItems(i).SubItems(1)
xlSheet.Range(bt) = ListView1.ListItems(i).SubItems(2)
xlSheet.Range(Ti) = ListView1.ListItems(i).SubItems(3)
Next
xlApp.Application.SaveWorkspace '保存
xlApp.Application.Quit '关闭对象
Set xlApp = Nothing '释放引用
Timer1.Enabled = True
End Sub
Private Sub Command3_Click()
'tcpClient.SendData "A点" + Text1.Text
Shape1.FillColor = RGB(255, 0, 0)
End Sub
Private Sub Command4_Click()
tcpClient.SendData "B点" + Text2.Text
End Sub
Private Sub Command5_Click()
Timer1.Enabled = False
Form2.Visible = True
End Sub
Private Sub Form_Load() ‘初始化服务器IP,端口和listview
tcpClient.RemoteHost = "192.168.1.18"
tcpClient.RemotePort = 2060
tcpClient.LocalPort = Rnd ’网上说端口被占用的原因,所以加了个这个还是不行
Text3.Text = 0
Command5.Enabled = False
Text4.Text = ""
ListView1.ListItems.Clear '清空列表
ListView1.ColumnHeaders.Clear '清空列表头
ListView1.View = lvwReport '设置列表显示方式
ListView1.Gridlines = True '显示网络线
ListView1.LabelEdit = lvwManual '禁止标签编辑
ListView1.FullRowSelect = True '选择整行
ListView1.ColumnHeaders.Add , , "序号", 600
ListView1.ColumnHeaders.Add , , "A点温度", 1200
ListView1.ColumnHeaders.Add , , "B点温度", 1200
ListView1.ColumnHeaders.Add , , "请求发出时间", 1500
ListView1.ColumnHeaders.Add , , "回复到达时间", 1500
End Sub
Private Sub Form_Unload(Cancel As Integer)
If tcpClient.State <> 0 Then ‘退出时关闭winsock
tcpClient.Close
End If
End Sub
'添加数据到listview1中
Private Sub tcpClient_DataArrival _
(ByVal bytesTotal As Long)
Dim strData As String
tcpClient.GetData strData
Text5.Text = strData
Dim X
X = ListView1.ListItems.Count + 1
ListView1.ListItems.Add , , X
ListView1.ListItems(X).SubItems(1) = Mid(Text5.Text, 3, 2) & "." & Mid(Text5.Text, 5, 2)
ListView1.ListItems(X).SubItems(2) = Mid(Text5.Text, 9, 2) & "." & Right(Text5.Text, 2)
ListView1.ListItems(X).SubItems(3) = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)
ListView1.ListItems(X).SubItems(4) = Text4.Text
Text3.Text = Text3.Text + 1 ’当收到十个以上的数据时绘图功能开启,技术渣只能通过text3来做全局变量
If Text3.Text > 10 Then
Command5.Enabled = True
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer) ‘温度设置的过滤,保证输入的是数字
If KeyAscii < 48 Or KeyAscii > 57 Then
MsgBox "请输入整数!", 26, "警告"
KeyAscii = 0
Text1.Text = ""
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer) ‘温度设置的过滤,保证输入的是数字
If KeyAscii < 48 Or KeyAscii > 57 Then
MsgBox "请输入整数!", 26, "警告"
KeyAscii = 0
Text2.Text = ""
End If
End Sub
Private Sub Timer1_Timer() ’定时发送POST字符,Text4用于记录发送时间,技术渣
tcpClient.SendData "POST"
Text4.Text = Hour(Time) & ":" & Minute(Time) & ":" & Second(Time)
End Sub
VB代码就这些,求大神帮忙
下面是STM32的lwip协议修改的部分
static err_t http_recv(void *arg, struct tcp_pcb *pcb,struct pbuf *p,err_t err)
{
char * data = NULL;
char *UserName =NULL;
char *PassWord =NULL;
char *LED_CMD =NULL;
char *ch =NULL;
//static uint8_t b[]="A";
data = p->payload; //把接收到的数据指针交给data
if(strncmp(data,"POST",4)==0)
{
tcp_write(pcb,PointA,strlen(PointA),0);
pbuf_free(p); /* 释放该pbuf段 */
}else if(strncmp(data,"OFF",3)==0)
{
// tcp_write(pcb,PointB,strlen(PointB),0);
LED1(OFF);
pbuf_free(p);
}else if(strncmp(data,"A点",3)==0)
{
tcp_write(pcb,PointA_answer,strlen(PointA_answer),0);
}else if(strncmp(data,"B点",3)==0)
{
tcp_write(pcb,PointB_answer,strlen(PointB_answer),0);
}
//tcp_close(pcb);
/* 关闭这个连接 */
err = ERR_OK;
return err;
}
关闭连接给注释掉主要是因为想连接一次一直读数据,加上后用定时器连接服务端STM32老是出40006错误或者40020错误,有时候多等一会儿就可以用了
更多
|