打算用用C#写上位机,直接复制例程的代码,觉得没问题啊,可是wifi板就是接不到指令,但是我用第一代的CommandEngine,wifi板就能收到指令,求指导。。。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.IO.Ports;
using WIFIRobotCMDEngineV2;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
string ControlIp = "192.168.1.1";
string Port = "2001";
public WifiRobotCMDEngineV2 RobotEngine2;
static IPAddress ips;
static IPEndPoint ipe;
static Socket socket = null;
string CMD_Forward = "FF0000FF";
public Form1()
{
InitializeComponent();
RobotEngine2 = new WifiRobotCMDEngineV2((Object)this.button1);
}
bool ret = false;
private bool InitWIFISocket(String controlIp, String port)
{
ips = IPAddress.Parse(controlIp.ToString());
ipe = new IPEndPoint(ips, Convert.ToInt32(port.ToString()));
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect(ipe);
RobotEngine2.SOCKET = socket;
RobotEngine2.IPE = ipe;
ret = RobotEngine2.SocketConnect();
return ret;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
InitWIFISocket(ControlIp, Port);
label1.Text = ret.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
SerialPort comm = new SerialPort();
RobotEngine2.SendCMD(0, CMD_Forward, comm);
}
}
}
|