public void gsz_fuction_OSP_Lidar()
{
m_total_MeasureResultV_t.Clear();//在List内移除所有元素
m_total_tick.Clear();//在List内移除所有元素
m_total_rem_angle.Clear();
gsz_delegate_log.Invoke(uiRichTextBox_log_laser,"开始清除缓存","black","",false );
strLidarIp = new StringBuilder("192.168.1.2");// new StringBuilder(ReadString("Basic", "IPV4_1", "192.168.1.111", strConfigIniAddr));
delegate_myc = new OSP_Lidar.MeasureModeCallback(myMeasureModeCallback);//之前实例化这个委托,现在给他赋值,就是回调函数
//第一个正式的步骤:SDK的初始化
int nBackId_device_init = 0;
nBackId_device_init = OSP_Lidar.device_init();
if (nBackId_device_init < 0)
{
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "device init error", "red", "", false);
return;
}
//第二个正式的步骤:添加硬件
int nBackId_device_add = 0;
//参数1:设备输出句柄
//参数2:设备的IP地址
//参数3:设备数据信息回调函数
//ref:该关键字用于按引用传递参数,这意味着方法内部对参数的修改会影响到方法外部的原始变量
nBackId_device_add = OSP_Lidar.device_add(ref dHandler, strLidarIp, delegate_myc);
if (0 == nBackId_device_add)
{
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "device1_add OK!", "green", "", false);
//uint cc = 0;
//设备初始化
OSP_Lidar.device_general_init(dHandler);
// OSP_Lidar.device_write_fpga_reg(dHandler1, OSP_Fpga_Reg.B_transfer_down,31);
// uint transferdown = OSP_Lidar.device_read_fpga_reg(dHandler1, OSP_Fpga_Reg.B_transfer_down);//这些值读取了 dll会自己使用 不需要上层操作
//cc = OSP_Lidar.device_read_fpga_reg(dHandler1, OSP_Fpga_Reg.B_dist_pow2);
//cc = OSP_Lidar.device_read_fpga_reg(dHandler1, OSP_Fpga_Reg.B_rem_pow2);
//cc = OSP_Lidar.device_read_fpga_reg(dHandler1, OSP_Fpga_Reg.B_out_amp_range_o);
//cc = OSP_Lidar.device_read_fpga_reg(dHandler1, OSP_Fpga_Reg.B_output_phase_range);
//设备信息结构体,可在设备连接之后通过device_get_info函数获取。
OSP_Lidar.device_get_info(dHandler, ref p_device_inf);//必须要加否则数据结构不对
//读寄存器。
////判断是否收敛 1为收敛
uint nC = OSP_Lidar.device_read_fpga_reg(dHandler, OSP_Fpga_Reg.B_path_sel);
int a = System.Environment.TickCount;//一个 32 位带符号整数,它包含自上次启动计算机以来所经过的时间(以毫秒为单位)
for (int i = 0; i < 1024; i++)
{
uint naddr = (uint)(0xc0000000 + 4 * i);
//Console.WriteLine(naddr.ToString("X") + " " + OSP_Lidar.device_read_fpga_reg(dHandler1, naddr));
}
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "初始化用时ms:"+ (System.Environment.TickCount - a), "black", "", false);
//Console.WriteLine("耗时:" + (System.Environment.TickCount - a) + "ms");
//进入测量模式,进入该模式后,数据将由用户注册的回调函数返回给用户。在测量期间,用户无法调用除停止测量之外的其他接口。
OSP_Lidar.device_measure_mode_entry(dHandler);
}
else
{
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "device1_add failure!", "red", "", false);
}
int nSecWait2Stop = ReadInt("Basic", "preserve_time", 5, m_strConfigIniAddr);//从配置文件里面读取测试时间, 就是挚感传感器的采样用时
while (nSecWait2Stop > 0)
{
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "采样倒计时:"+ nSecWait2Stop.ToString(), "black", "", false);
System.Threading.Thread.Sleep(1000);
nSecWait2Stop--;
}
//退出测量模式。
OSP_Lidar.device_measure_mode_exit(dHandler);
//SDK逆初始化函数,该函数必须优先调用。
if (OSP_Lidar.device_deinit() != 0)
{
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "device deinit error", "red", "", false);
return;
}
else
{
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "device deinit success ! ", "green", "", false);
}
//以上数据采集,以下数据整理
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "开始整理数据", "black", "", false);
foreach (MeasureResultV_t temp_MeasureResultV_t in m_total_MeasureResultV_t)
{
m_total_tick.Add(temp_MeasureResultV_t.tick);
foreach (double temp_rem_angle in temp_MeasureResultV_t.rem_angle)
{
m_total_rem_angle.Add(temp_rem_angle);
}
}
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "结束整理数据", "black", "", false);
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "采样tick总数:"+ m_total_tick.Count.ToString(), "black", "", false);
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "采样rem_angle总数:" + m_total_rem_angle.Count.ToString(), "black", "", false);
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "开始数据处理", "black", "", false);
var matlabObj = new Class_dayang();
MWNumericArray input_sampel_rate = 160000;
MWNumericArray double_Arrays_rem_angle = ConvertToMWArray(m_total_rem_angle);
MWArray[] result = matlabObj.fuction_dayang(2, input_sampel_rate, double_Arrays_rem_angle);
double[] doubleResults = new double[10];
for (int i = 0; i < 2; i++)
{
// 将MWArray元素转换为数值类型的MWNumericArray
MWNumericArray numericElement = (MWNumericArray)result[i];
// 将MWNumericArray转换为标量double值
double convertedValue = numericElement.ToScalarDouble();
// 将转换结果存入目标数组
doubleResults[i] = convertedValue;
}
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "数据处理结束", "black", "", false);
gsz_delegate_log.Invoke(uiRichTextBox_log_laser, "查找曲线的窗口", "black", "", false);
}