User Manual

- 19 -
handle.DeviceName = "\\\\.\\COMxx"; /*port number*/
ret = Connect(&handle); /*device connect*/
if
(ret !=
RET_OK
)
{
printf
("device connect failedret = %d\n", ret);
}
device initialization, the default configuration is standby mode and asynchronous
communication mode, mainly to create an asynchronous thread, obtain the device address (the
rest of the commands use the device address), allocate memory space, etc.
/* Device initialization */
ret = ConfigInit(&handle);
if
(
RET_OK
!= ret)
{
printf
("Initialization failed! error code is: %d\n", ret);
}
printf
("Initialization succeed! \n");
Set measure mode: single measure or continuously measure
/* Set to continuously measurement mode */
handle.RunMode =
RUN_CONTINUOUS
;
HPS3D_SetRunMode(&handle);
/* Set to single measurement mode */
Handle.RunMode =
RUN_SINGLE_SHOT
;
HPS3D_SetRunMode(&handle);
After the configuration is completed according to the above steps, you can get the complete
deep data packet of the measurement output under the default configuration.
Among them, the continuous mode requires an asynchronous thread to continuously output.
In this case, the observer mode can be used to monitor the measured return data. The sample
code is as follows:
/*
* User processing function,Continuous measurement or asynchronous mode
* in which the observer notifies the callback function
* */
void
*
User_Fun
(HPS3D_HandleTypeDef *handle,AsyncIObserver_t *event)
{
if
(event->AsyncEvent ==
ISubject_Event_DataRecvd
)
{
switch
(event->RetPacketType)
{
case
SIMPLE_ROI_PACKET
:
printf
("distance
average:%d\n",event->MeasureData.simple_roi_data[0].distance_average);
break
;
case
FULL_ROI_PACKET
: