CPP SDK adapt to CPP Stuck on a problem cant pass need help

Windows specific forum
LiK137
Enthusiast
Enthusiast
Posts: 279
Joined: Wed Jun 23, 2010 5:13 pm

CPP SDK adapt to CPP Stuck on a problem cant pass need help

Post by LiK137 »

Hi,

There is a scanner device which I want to use and this scanner comes with SDK with C++ (QT) and C# examples.

I am able to start device, check status, run all dll calls and receive RETurn values. But unfortunately after the scanner goes to ready mode the only way to talk to device is through sending commands to thread to pass to scanner.

1st: The structure to use with thread consist of pointers to functions. Some little example:

Code: Select all

typedef struct LSClient
{

		/*!\brief pointer on some object of upper software.
		 *
		 * It is allocated and is initialized by upper software.
		 * It Is Sent as parameter in all \ref callback "callbacks" from
		 * the thread of rolling to upper software.
		 */
		LSC_HNDL Client;

		/*!\brief Getting the commands from upper software to thread.
		 *
		 * The Function is called from thread for getting the command from upper software.
		 * \param Cl - a pointer on object of upper software.
		 * \return command for thread of rolling.
		 */
		LSC_COMMAND (*GetCommand)( LSC_HNDL Cl );

		/**\brief Transmission of the final image from thread to upper software.
		 *
		 * Called when process is finished.
		 * \param Cl - a pointer on object of upper software.
		 * \param img_num - a number of the images
		 * \param Buf - a pointer on buffer with final image.
		 * The Depth of the buffer 8bpp(256 grays), scale x00ppi, the first byte - an upper left pixel.
		 * Can be NULL in this case will set variable scan_errors.
		 * \param W - a width of the image
		 * \param H - a height of the image
		 * \param scan_errors - a mask \ref scan_errors "error of imaging"
		 * In case of critical error parameter Buf returns as NULL
		 * \return 0.
		 */
		int (*TakeImage)( LSC_HNDL Cl, int img_num, unsigned char *Buf, int W, int H, unsigned int img_errors );

This was a part of structure.


2: And SendCommands to thread part:

Code: Select all

/* Send start scan command to scanner */
void mainForm::startSlot()
{
	sendCommand( &lsc_handle, LSC_CMD_SCAN );
}

/* Send stop  command to scanner*/
void mainForm::stopSlot()
{
	sendCommand( &lsc_handle, LSC_CMD_STOP );
}

3: And sendCommand itself

Code: Select all

void sendCommand( LSC_HNDL handle, LSC_COMMAND command )
{
	LSC_HANDLE* hndl = (LSC_HANDLE*) handle;

	while( hndl->command != LSC_CMD_NOP )
	{
#ifdef _WIN32
		SleepEx( 10, TRUE );
#else
		usleep( 10000 );
#endif
	}

	hndl->command = command;
}

/*
 send command to lsclient
 It's calledfrom lsclient
 */
LSC_COMMAND getCommand( LSC_HNDL handle )
{
	LSC_HANDLE* hndl = (LSC_HANDLE*) handle;
	LSC_COMMAND cmd;

	cmd = hndl->command;
	hndl->command = LSC_CMD_NOP;

	return cmd;
}
 
int takeImage( LSC_HNDL handle, int img_num, unsigned char *buf, int width, int height, unsigned int img_errors )
{
	LSC_HANDLE* hndl = (LSC_HANDLE*) handle;
	QCustomEvent* event = new QCustomEvent( (QEvent::Type) (QEvent::User + TAKEIMAGE_EVENT) );
	QMutexLocker _lock( hndl->image_lock );

	hndl->img_errors = img_errors;
	hndl->img_num = img_num;
	if( hndl->img )
	{
		free( hndl->img);
		hndl->img= NULL;
	}
	hndl->img_width = width;
	hndl->img_height = height;

	if( buf != NULL )
	{
		hndl->img = (unsigned char*) malloc( width * height );
		if( !hndl->img )
		{
			printf( "Error allocating %d bytes!\n", width * height );
			return -1;
		}

		memcpy( hndl->img, buf, width * height );
	}

	_lock.unlock();
	QApplication::postEvent( (QObject*) hndl->visual_ptr, event );
	return 0;
}

Thats it
Thank You for any help