这是我发送数据的代码
sd = Encoding.UTF8.GetBytes(@"{""c"":""run"",""x"":""0"",""y"":""100"",""z"":""0"",""r"":""0"",""v"":""322""}");
serialPort.Write(sd, 0, sd.Length);
这是我要返回的值的代码
void Comm_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
Byte[] InputBuf = new Byte[128];
serialPort.Read(InputBuf, 0, serialPort.BytesToRead);
ASCIIEncoding encoding = new ASCIIEncoding();
data = encoding.GetString(InputBuf);
new Thread(SetReceiveData).Start();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
这个是我要发送到串口的数据,他就是个坐标值(@"{""c"":""run"",""x"":""0"",""y"":""100"",""z"":""0"",""r"":""0"",""v"":""322""}");
每次发送一遍会返回{"c":"done"x":"0.0 "y":"0.0 "z":"48"r":"0.0 ","v":"26108"}
想让x,y,z,r值由别的地方输入进来,比如说记事本,用ini,不知道要如何写进去,直接在双引号写进去吗比如"x":"ini.?"
如果x=100,那么返回也是x=100,但是c是done,所以好奇如何让他们俩作比对
然后比对成功后,我想让他自动循环5次,以此移动5次
我想到的是for,但是不知道如何实现
for(int i=0;i<=5;i++)
{
string valuex = ini.IniReadValue("坐标值一", "x");
string valuey = ini.IniReadValue("坐标值一", "y");
string valuez = ini.IniReadValue("坐标值一", "z");
string valuer = ini.IniReadValue("坐标值一", "r");
sd = Encoding.UTF8.GetBytes(@"{""c"":""run"",""x"":""valuex"",""y"":""valuey"",""z"":""valuez"",""r"":""valuer"",""v"":""322""}");
serialPort.Write(sd, 0, sd.Length);
if(sd==data)
{
}
}