void sp_DataReceived(object sender, SerialDataReceivedEventArgs e) { UpdateFrameCountReceived ufcr = delegate(int count) { tbFrameCount.Text = count.ToString(); }; int n = sp.BytesToRead; if (n > 0) { byte[] array = new byte[n]; sp.Read(array, 0, n); sp3.Append(array); while (sp3.isFrameExisted()) { if (sp3.Length == 53) // modified { byte[] data = new byte[sp3.Length - 1]; data[0] = sp3.Command; sp3.Content.CopyTo(data, 1); UpdateRobotStatusDelegate ursd = new UpdateRobotStatusDelegate(UpdateRobotStatus); Dispatcher.Invoke(ursd, data); } else if (sp3.Length == 6) { byte status = sp3.Command; if (status == 1) { isTransferDone = true; } else { isTransferDone = false; } frameRcvCount = BitConverter.ToInt16(sp3.Content, 0); frameMotionCount = BitConverter.ToInt16(sp3.Content, 2); frameRcvCountList.Add(frameRcvCount); frameMotionCountList.Add(frameMotionCount); bufferSize = frameRcvCount - frameMotionCount; Dispatcher.BeginInvoke(ufcr, bufferSize); } } } }
void sp_DataReceived(object sender, SerialDataReceivedEventArgs e) { UpdateFrameCountReceived ufcr = delegate(int count) { tbFrameCount.Text = count.ToString(); }; int n = sp.BytesToRead; if (n > 0) { byte[] array = new byte[n]; sp.Read(array, 0, n); sp3.Append(array); while (sp3.isFrameExisted()) { if (sp3.Length == 53) // modified { byte[] data = new byte[sp3.Length - 1]; data[0] = sp3.Command; sp3.Content.CopyTo(data, 1); UpdateRobotStatusDelegate ursd = new UpdateRobotStatusDelegate(UpdateRobotStatus); Dispatcher.Invoke(ursd, data); } else if(sp3.Length == 6) { byte status = sp3.Command; if (status == 1) { isTransferDone = true; } else { isTransferDone = false; } frameRcvCount = BitConverter.ToInt16(sp3.Content, 0); frameMotionCount = BitConverter.ToInt16(sp3.Content, 2); frameRcvCountList.Add(frameRcvCount); frameMotionCountList.Add(frameMotionCount); bufferSize = frameRcvCount - frameMotionCount; Dispatcher.BeginInvoke(ufcr, bufferSize); } } } }