/// <summary> /// 将STP318传感器的数据映射进指定控件中 /// </summary> /// <param name="dat">input the parameter</param> /// <param name="tx"> ref textbox </param> /// <param name="lb"> ref label</param> /// public void DataMapping2Control_STP318(LIN_STP318_ReadData dat, ref TextBox tx, ref Label lb) { tx.Text = (dat.TOF / 58.0).ToString(); if (dat.status == 1) { lb.Text = SensingStatus[0]; } else if (dat.status == 2) { lb.Text = SensingStatus[1]; } else if (dat.status == 4) { lb.Text = SensingStatus[2]; } else if (dat.status == 8) { lb.Text = SensingStatus[3]; } else if (dat.status == 16) { lb.Text = SensingStatus[4]; } else { lb.Text = "正常"; } }
/// <summary> /// 根据ID号读取相应传感器的数值 /// </summary> /// <param name="id">输入所要读取的ID号</param> /// <returns></returns> public LIN_STP318_ReadData ReadData_STP318(int DevHandle, byte id) { int ret; LIN_STP318_ReadData rd_msg = new LIN_STP318_ReadData(); USB2LIN.LIN_MSG[] msg = new USB2LIN.LIN_MSG[1]; msg[0].Data = new Byte[9]; msg[0].DataLen = 3; msg[0].ID = id; IntPtr[] ptArray = new IntPtr[1]; ptArray[0] = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USB2LIN.LIN_MSG)) * msg.Length); IntPtr pt = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(USB2LIN.LIN_MSG))); Marshal.Copy(ptArray, 0, pt, 1); //将数组中的数据拷贝到指针所指区域 for (int k = 0; k < msg.Length; k++) { Marshal.StructureToPtr(msg[k], (IntPtr)((UInt32)pt + k * Marshal.SizeOf(typeof(USB2LIN.LIN_MSG))), true); } ret = USB2LIN.LIN_Read(DevHandle, LINIndex, pt, 1); if (ret < USB2LIN.LIN_SUCCESS) { Console.WriteLine("LIN read data failed!\n"); return(rd_msg); } else { msg[0] = (USB2LIN.LIN_MSG)Marshal.PtrToStructure((IntPtr)((UInt32)pt + 0 * Marshal.SizeOf(typeof(USB2LIN.LIN_MSG))), typeof(USB2LIN.LIN_MSG)); rd_msg.TOF = BitConverter.ToUInt16(msg[0].Data, 0); rd_msg.status = msg[0].Data[2]; return(rd_msg); } }
private void STP318_Process(LIN_STP318_ReadData m_318Data, LocationPoint InstallationPosition, ref UltrasonicAxis ultrasonic_location) { if (m_318Data.status == 0) { if (m_318Data.TOF != 0) { double distance = m_318Data.TOF * TemperatureCompensation(25);//cm ultrasonic_location.x = InstallationPosition.x + distance * Math.Cos(InstallationPosition.yaw); ultrasonic_location.y = InstallationPosition.y + distance * Math.Sin(InstallationPosition.yaw); ultrasonic_location.state = UltrasonicStatus.Normal; } else { ultrasonic_location.x = 0; ultrasonic_location.y = 0; ultrasonic_location.state = UltrasonicStatus.OverDetection; } } else if (m_318Data.status == 16) { ultrasonic_location.x = 0; ultrasonic_location.y = 0; ultrasonic_location.state = UltrasonicStatus.BlindZone; } ultrasonic_location.x *= 0.01; ultrasonic_location.y *= 0.01; }
/// <summary> /// 将STP318传感器的数据映射进指定控件中 /// </summary> /// <param name="dat">input the parameter</param> /// <param name="tx"> ref textbox </param> /// <param name="lb"> ref label</param> /// public void DataMapping2Control_STP318(LIN_STP318_ReadData dat, ref Label[] tx) { tx[0].Text = (dat.TOF / 58.0).ToString("F2"); if (dat.status == 1) { tx[1].Text = SensingStatus[0]; } else if (dat.status == 2) { tx[1].Text = SensingStatus[1]; } else if (dat.status == 4) { tx[1].Text = SensingStatus[2]; } else if (dat.status == 8) { tx[1].Text = SensingStatus[3]; } else if (dat.status == 16) { tx[1].Text = SensingStatus[4]; } else if (dat.status == 0) { tx[1].Text = "正常"; } else { tx[1].Text = "异常"; } }
public void DataMapping2Control_STP318(LIN_STP318_ReadData dat, ref Label tx) { tx.Text = (dat.TOF / 58.0).ToString("F2"); }