@@ -412,16 +412,9 @@ PlusStatus vtkPlusClarius::InternalConnect()
412412 this ->OrientationSensorTool = NULL ;
413413 this ->GetToolByPortName (" OrientationSensor" , this ->OrientationSensorTool );
414414
415- vtkPlusClarius* device = vtkPlusClarius::GetInstance ();
416415 // Initialize Clarius Listener Before Connecting
417- if (!device-> Connected )
416+ if (!this -> IsConnected () )
418417 {
419- int argc = 1 ;
420- char ** argv = new char * [1 ];
421- argv[0 ] = new char [4 ];
422- strcpy (argv[0 ], " abc" );
423- const char * path = device->PathToSecKey .c_str ();
424-
425418 // Callbacks
426419 CusNewProcessedImageFn processedImageCallbackPtr = static_cast <CusNewProcessedImageFn>(&vtkPlusClarius::ProcessedImageCallback);
427420 CusNewRawImageFn rawDataCallBackPtr = static_cast <CusNewRawImageFn>(&vtkPlusClarius::RawImageCallback);
@@ -432,32 +425,32 @@ PlusStatus vtkPlusClarius::InternalConnect()
432425
433426 // No B-mode data sources. Disable B mode callback.
434427 std::vector<vtkPlusDataSource*> bModeSources;
435- device ->GetVideoSourcesByPortName (vtkPlusDevice::BMODE_PORT_NAME , bModeSources);
428+ this ->GetVideoSourcesByPortName (vtkPlusDevice::BMODE_PORT_NAME , bModeSources);
436429 if (bModeSources.empty ())
437430 {
438431 processedImageCallbackPtr = nullptr ;
439432 }
440433
441434 // No RF-mode data sources. Disable RF mode callback.
442435 std::vector<vtkPlusDataSource*> rfModeSources;
443- device ->GetVideoSourcesByPortName (vtkPlusDevice::RFMODE_PORT_NAME , rfModeSources);
436+ this ->GetVideoSourcesByPortName (vtkPlusDevice::RFMODE_PORT_NAME , rfModeSources);
444437 if (rfModeSources.empty ())
445438 {
446439 rawDataCallBackPtr = nullptr ;
447440 }
448441
449442 try
450443 {
451- if (cusCastInit (argc, argv, path ,
444+ if (cusCastInit (0 , NULL , this -> PathToSecKey . c_str () ,
452445 processedImageCallbackPtr,
453446 rawDataCallBackPtr,
454447 nullptr , // ClariusSpectralImageInfo
455448 freezeCallBackFnPtr,
456449 buttonCallBackFnPtr,
457450 progressCallBackFnPtr,
458451 errorCallBackFnPtr,
459- device ->FrameWidth ,
460- device ->FrameHeight ) < 0 )
452+ this ->FrameWidth ,
453+ this ->FrameHeight ) < 0 )
461454 {
462455 return PLUS_FAIL ;
463456 }
@@ -480,12 +473,15 @@ PlusStatus vtkPlusClarius::InternalConnect()
480473 }
481474
482475 // Attempt to connect;
483- int isConnected = -1 ;
484- const char * ip = device->IpAddress .c_str ();
476+ const char * ip = this ->IpAddress .c_str ();
485477 try
486478 {
487479 CusReturnFn returnFunction = (CusReturnFn)(&vtkPlusClarius::ConnectReturnFn);
488- isConnected = cusCastConnect (ip, device->TcpPort , returnFunction);
480+ cusCastConnect (ip, this ->TcpPort , returnFunction);
481+
482+ // Wait for connection to complete and get udp port.
483+ const double connectionDelaySeconds = 1.0 ;
484+ vtkIGSIOAccurateTimer::DelayWithEventProcessing (connectionDelaySeconds);
489485 }
490486 catch (const std::runtime_error& re)
491487 {
@@ -503,17 +499,17 @@ PlusStatus vtkPlusClarius::InternalConnect()
503499 return PLUS_FAIL ;
504500 }
505501
506- if (isConnected < 0 )
502+ if (! this -> IsConnected () )
507503 {
508- LOG_ERROR (" Could not connect to scanner at Ip = " << ip << " port number= " << device ->TcpPort << " isConnected = " << isConnected );
504+ LOG_ERROR (" Could not connect to scanner at ip: " << ip << " port number: " << this ->TcpPort );
509505 return PLUS_FAIL ;
510506 }
511507 }
512508 else
513509 {
514- LOG_DEBUG (" Scanner already connected to IP address=" << device ->IpAddress
515- << " TCP Port Number =" << device ->TcpPort << " Streaming Image at UDP Port=" << device ->UdpPort );
516- device ->Connected = 1 ;
510+ LOG_DEBUG (" Scanner already connected to IP address=" << this ->IpAddress
511+ << " TCP Port Number =" << this ->TcpPort << " Streaming Image at UDP Port=" << this ->UdpPort );
512+ this ->Connected = 1 ;
517513 return PLUS_SUCCESS ;
518514 }
519515 return PLUS_SUCCESS ;
@@ -533,6 +529,7 @@ void vtkPlusClarius::ConnectReturnFn(int udpPort)
533529 device->FrameWidth = DEFAULT_FRAME_WIDTH ;
534530 device->FrameHeight = DEFAULT_FRAME_HEIGHT ;
535531 }
532+ device->Connected = 1 ;
536533 }
537534 else
538535 {
@@ -645,11 +642,11 @@ void vtkPlusClarius::ProcessedImageCallback(const void* newImage, const CusProce
645642 }
646643
647644
648- LOG_TRACE (" new image (" << newImage << " ): " << nfo->width << " x " << nfo->height << " @ " << nfo->bitsPerPixel
645+ LOG_TRACE (" New image (" << newImage << " ): " << nfo->width << " x " << nfo->height << " @ " << nfo->bitsPerPixel
649646 << " bits. @ " << nfo->micronsPerPixel << " microns per pixel. imu points: " << npos);
650647
651648 // Check if still connected
652- if (device->Connected == 0 )
649+ if (! device->IsConnected () )
653650 {
654651 LOG_ERROR (" Trouble connecting to Clarius Device. IpAddress = " << device->IpAddress
655652 << " port = " << device->TcpPort );
@@ -905,7 +902,7 @@ void vtkPlusClarius::RawImageCallback(const void* newImage, const CusRawImageInf
905902 << nfo->axialSize << " axial microns per sample, " << nfo->lateralSize << " lateral microns per line." );
906903
907904 // Check if still connected
908- if (device->Connected == 0 )
905+ if (! device->IsConnected () )
909906 {
910907 LOG_ERROR (" Trouble connecting to Clarius Device. IpAddress = " << device->IpAddress
911908 << " port = " << device->TcpPort );
0 commit comments