DatabindXY,集合已修改;可能无法执行枚举操作。
List<float> datalist = new List<float>();
List<float> timelist = new List<float>();
public float[][] listArray = new float[128][];
public float[][] listFFT = new float[128][];
public float[][] listShock = new float[128][];
public float[][] ideal_line = new float[128][];
public int frames = 0; //listArray中行数,偶数行代表时间数据,奇数行代表加速度数据
public int curShowFrame = 0; //显示上下帧数据时的参数
private void server_start() //上位机作为服务器,接收下位机发来的数据包
{
while (true)
{
try
{
int port = 2001; //监听2001端口
string host = "127.0.0.1"; //本机回发的Ip
IPAddress ip = IPAddress.Parse(host);
IPEndPoint ipe = new IPEndPoint(ip, port);
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);//创建一个Socket类
s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
//this.label12.Text = this.label12.Text + "绑定2001端口并开始监听.....\n";
s.Bind(ipe); //绑定2001端口
s.Listen(0); //开始监听
//this.label12.Text = this.label12.Text + "等待客户发送请求......\n";
Socket temp = s.Accept(); //为新建连接创建新的Socket。
// this.label12.Text = this.label12.Text + "获得一个客户端,开始接收数据......\n";
byte[] bytes = new byte[1200];
int bytesint;
bytesint = temp.Receive(bytes, bytes.Length, 0);//从客户端接受信息
int n = 0;
Byte[] changebytes = new byte[4]; //暂存四个字节数据
for (int j = 0; j < 4 * 2 * 128; j++)
{
if (n == 4)
{
//Array.Reverse(changebytes);
if (j <= 2 * 2 * 128)
datalist.Add(BitConverter.ToSingle(changebytes, 0)); //存储加速度序列
else
timelist.Add(BitConverter.ToSingle(changebytes, 0));
n = 0;
j = j - 1;
}
else if (j == 4 * 2 * 128 - 1)
{
changebytes[n++] = bytes[j];
timelist.Add(BitConverter.ToSingle(changebytes, 0));//存储时间序列
}
else
changebytes[n++] = bytes[j];
}
frames = frames + 2;
curShowFrame = frames;
listArray[frames - 2] = new float[128];
listArray[frames - 1] = new float[128];
for (int k = 0; k < 128; k++)
{
listArray[frames - 2][k] = timelist[k]; //存入交叉数组中,偶数行为时间值,奇数行为加速度值
listArray[frames - 1][k] = datalist[k];