
#include "stdafx.h"
#include "MultiZebrasDemo.h"
#include "MultiZebrasDemoDlg.h"
#include "FileOpenCombo.h"
#include "afxdialogex.h"

#include "AppResetZebraCard.h"

LPTSTR lpAnsi2lpWChar(LPSTR lpstr);
LPSTR  lpWChar2lpAnsi(LPTSTR lptstr);

#ifndef ZEBRAZ4U3DLLWIN32_EXPORTS
#include "ZebraZ4U3DllWin32.h"
#else
int resetZebraFromApp(__HZHANDLE__ hZhandle, int *resultState);
void resetZebraByUSBDev(__HZHANDLE__ hZhandle);
__PZEBRA_BOARD_INFO__ getZebraBoardInfo(__HZHANDLE__ hZhandle, TCHAR **pUsbPortName);
void CloseUsbDevice(__HZHANDLE__ hZhandle);
#endif

void ResetAttachedZebraBoard(void *pThis, __HZHANDLE__ hZhandle, int myId, int ResetByApp)
{
	CMultiZebrasDemoDlg *pMain = (CMultiZebrasDemoDlg *)pThis;
	__PZEBRA_BOARD_INFO__ pZebraBoardInfo;

	if (ResetByApp == 1)
	{
		int state;
		if (resetZebraFromApp(hZhandle, &state) > 0)
		{
			pMain->UpdateProgressMsg(myId, -1, L"Removed ! Zebra reset ...!");

			pZebraBoardInfo = getZebraBoardInfo(hZhandle, NULL);
			pZebraBoardInfo->nZebraStatus = __Zebra_Removed__;
			CloseUsbDevice(hZhandle);
		}
		//else
		//	SetDlgItemText(IDC_EDT_RESET_REPORT, L"Can't reset Zebra");
	}
	else
	{
		pMain->UpdateProgressMsg(myId, -1, L"Removed ! Zebra reset ...!");

		resetZebraByUSBDev(hZhandle);
		pZebraBoardInfo = getZebraBoardInfo(hZhandle, NULL);
		pZebraBoardInfo->nZebraStatus = __Zebra_Removed__;
		CloseUsbDevice(hZhandle);
	}
}