我是视觉工作室的新手。我正在使用VS2010,我正在尝试创建一个具有三个按钮的表单应用程序: CONNECT - 一个按钮,它提供与所连接的dsp的套接字连接并读取我发送的命令(例如握手命令),然后在控制台上显示它 MEASURE - 一个计算我想要的参数的按钮 停止 - 退出程序,两个标签显示我的参数。 问题是,CONNECT按钮中的代码有多个调用来读取和写入命令以及套接字连接代码。我观察到的是,除了套接字连接代码,它不会调用 readData()或 writeData()函数。我用谷歌搜索了几个小时,但显然没有成功。如果有任何错误或是否有任何其他替代解决方案可以让它工作,请告诉我。提前致谢。 我的代码:
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <winsock2.h>
#include <iostream>
#include <windows.h>
#include <string.h>
#include <sys/types.h>
using namespace std;
#pragma comment(lib,"ws2_32.lib")
int m_port = 2500;
int m_sockId;
const char START_FIXED = 0x10;
const char END = 0x16;
const char START_VAR = 0x68;
char m_buffer[32768];
namespace radar {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ START;
protected:
protected:
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ button1;
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
/// <summary>
void InitializeComponent(void)
{
//components initialization
}
int setup()
{
//Socket connecting code
}
bool writeData(const char command, const char length)
{
//data write
}
int readData()
{
//reads the data
}
int printData(int length)
{
for (int i = 0; i<=length; i++)
{
printf("%i\n", m_buffer[i]);
}
return 0;
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
const char command[10] = {250, 249, 247, 245, 241, 242, 243, 206, 103, 111};
unsigned short length;
//connect
setup();
length = readData(); // doesn't call the readData() function defined outside
if (length >= 0)
printData(length); //Prints some random set of data from the memory but not the response of the module
//send and receive 250
writeData(250, length);
length = readData();
if (length>=0)
printData(length);
//send and receive 249
writeData(command[1],length); // doesn't call the writeData() function
length = readData();
if (length >= 0)
printData(length);
if (length != 92){
}
private: System::Void button2_Click_1(System::Object^ sender, System::EventArgs^ e) { exit (0);
}
private: System::Void button1_Click_1(System::Object^ sender, System::EventArgs^ e) {
//measure...
}
}
};
}
PS:当我在' private中定义这些函数时,它给出了错误:System :: Void button1_Click(System :: Object ^ sender,System :: EventArgs ^ e){'