//
//
//
//			POSNET BASE EXAMPLES
//			EXAMPLE 1
//
//

#include <stdlib.h>
#include <string>
#include <iostream>
#include <istream>
#include <limits>
#include <cstdlib>
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#ifndef itoa
    char *itoa(int a,char *b,int c)
    {
	if (c==10) sprintf(b,"%d",a); else sprintf(b,"%x",a);
	return b;
    }
#endif
#define Sleep(a) {struct timespec tc,tc1;\
                 tc.tv_sec=a/1000; \
		 tc.tv_nsec=(a%1000)*1000*1000; \
		 nanosleep(&tc,&tc1);   \
		 }
																					  
#endif
#include "../../include/posnet.h"
#include "../../include/posnet_hlapi.h"

using namespace std;

/*
template <class charT, class traits>
inline
std::basic_istream<charT,traits>&
ignoreLine(std::basic_istream<charT,traits>& strm)
{
	strm.ignore(std::numeric_limits<int>::max(),strm.widen('\n'));
	return strm;
}*/


string menuLevel0()
{
	do {
	cout << " TESTY - GRUPA " << endl;
	cout << " A - Ustawienia " << endl;
	cout << " B - Raporty " << endl;
	cout << " C - Bazy " << endl;
	cout << " D - Inne " << endl;
	cout << " Q - Koniec " << endl;
	string s;
	cin >> s;
	if (s=="Q" || s=="q") return "";
	if (s!="") return s;
	} while(1);
}

void doLevel1A(POSNET_HANDLE hLocalDevice)
{
	do {
		cout << " TESTY - USTAWIENIA " << endl;
		cout << " A - Pobierz date                     " << " B - Pobierz czas " << endl;
		cout << " C - Pobierz nagłówek                 " << " D - Ustaw serwis na 10.10.2005,POSNET SA" << endl;
		cout << " E - Ustaw nagłówek                   " << " F - Pobierz stopkę " << endl;
		cout << " G - Ustaw stopke                     " << " H - Pobierz param. wyswietlacza " << endl;
		cout << " I - Ustawienia magazynow             " << " J - Pobierz impuls szuflady " << endl;
		cout << " K - Pobierz konf. dzwiekow           " << " L - Pobierz konf. uspienia " << endl;
		cout << " M - Pobierz konf kart rabatowych     " << " N - Pobierz Konf. wysw. tekstow " << endl;
		cout << " O - Pobierz konf. autoryzacji        " << " P - Stan autoryzacji kasy " << endl;
		cout << " R - Pobierz konf. buf.poz.parag.     " << " S - Pobierz konf. druku " << endl;
		cout << " T - Pobierz konf. kasy               " << " U -  Ustaw czasy wylogowania " << endl;
		cout << " V - Pobierz konf. TCP/IP              " << " W - Włacz bufor parag. " << endl;
		cout << " X - Fiscal Memory Dump               " << " Y -  ModemCfgSet " << endl;
		cout << " Z - HotkeyFuncIns                    " << " 0 -  AuthCodeReset" << endl;
		cout << " 1 - SoundCfgSet                      " << " 2 -  Set IP" << endl;
		cout << " 3 - Hotkey Func Ins                  " << " 4 -  DSPInfoSet" << endl;
		cout << " 5 - VATSet                           " << " 6 -  CommCfgGet" << endl;
		cout << " 7 -                                  " << " 8 -  " << endl;
		cout << " 9 -                                  " << " a -  " << endl;
		
		cout << " Q - Koniec " << endl;
		string s;
		cin >> s;
		if (s=="A")
		{
			void *request;
			char date[16];
			POSS_DateGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_DateGet(request,date);
				cout << date << endl;
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="B")
		{
			void *request;
			char date[16];
			POSS_TimeGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_TimeGet(request,date);
				cout << date << endl;
			}
		}
		if (s=="C")
		{
			void *request;
			char flagi[256],linie[256];
			POSS_HeaderGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_HeaderGet(request,flagi,linie);
				cout << "F: " << flagi << " L: " << linie << endl;
			}
		}
		if (s=="D")
		{
			void *request;
			POSS_MaintenanceSet(hLocalDevice,&request,"2005-10-10","POSNET SA");
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
		}
		if (s=="E")
		{
			void *request;
			
			int ile;
			char buf[64];
			cout << "Ile linii:";
			cin  >> ile ;
			cin.ignore(65535,cin.widen('\n'));
			string s,linie;
			string params;
			int k;
			for (int i=0;i<ile;i++)
			{
				if (i) { linie+="\n"; params+="\n"; }
				cout << "Podaj linię : ";
				getline(cin,s);
				linie+=s;
				cout << "Podaj opcje [0-7] : ";
				cin >> k ;cin.ignore(65535,cin.widen('\n'));
				itoa(k,buf,10);
				params+=buf;
			}
			if (ile)
			POSS_HeaderSet(hLocalDevice,&request,(const char*)params.c_str(),(const char*)linie.c_str());
			else
			POSS_HeaderSet(hLocalDevice,&request,NULL,NULL);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="F")
		{
			void *request;
			char flagi[256],linie[256];
			POSS_FooterGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_FooterGet(request,flagi,linie);
				cout << "F: " << flagi << " L: " << linie << endl;
			}
		}
		if (s=="G")
		{
			void *request;
			
			int ile;
			char buf[64];
			cout << "Ile linii:";
			cin  >> ile ;
			cin.ignore(65535,cin.widen('\n'));
			string s,linie;
			string params;
			int k;
			for (int i=0;i<ile;i++)
			{
				if (i) { linie+="\n"; params+="\n"; }
				cout << "Podaj linię : ";
				getline(cin,s);
				linie+=s;
				cout << "Podaj opcje [0-7] : ";
				cin >> k ;cin.ignore(65535,cin.widen('\n'));
				itoa(k,buf,10);
				params+=buf;
			}
			if (ile)
			POSS_FooterSet(hLocalDevice,&request,(const char*)params.c_str(),(const char*)linie.c_str());
			else
			POSS_FooterSet(hLocalDevice,&request,NULL,NULL);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="H")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_DspParamGet(hLocalDevice,&request,(unsigned char)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b,c;
				unsigned short d;
				POSG_DspParamGet(request,&a,&b,&c,&d);
				cout << "Kont: " << (int)a << " Pods: " << (int)b << " Tryb: " << (int)c << " Opoznienie: " << (int)d << endl;
			}
		}
		if (s=="I")
		{
			void *request;

			POSS_StoreCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b,c,d,e,f;
				POSG_StoreCfgGet(request,&a,&b,&c,&d,&e,&f);
				cout << "Magazyn wł: " << (int)a << " Kontrola min: " << (int)b << " Kontrola sprz.: " << (int)c <<" Mag. opak.: " << (int)d <<" Kontrola min.opak.: " << (int)e <<" Kontrola sprz.opak.: " << (int)f << endl;
			}
		}
		if (s=="J")
		{
			void *request;

			POSS_DrawerImpulseGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned short a;
				POSG_DrawerImpulseGet(request,&a);
				cout << "Dlugosc: " << (int)a << endl;
			}
		}
		if (s=="K")
		{
			void *request;

			POSS_SoundCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				POSG_SoundCfgGet(request,&a,&b);
				cout << "Klawiatura: " << (int)a << " Zrodlo: " << (int)b   << endl;
			}
		}
		if (s=="L")
		{
			void *request;

			POSS_TimeoutsGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				POSG_TimeoutsGet(request,&a,&b);
				cout << "Wylogowanie: " << (int)a << " Wylaczenia: " << (int)b  << endl;
			}
		}
		if (s=="M")
		{
			void *request;

			POSS_DiscntCardCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a;
				unsigned short b,c;
				POSG_DiscntCardCfgGet(request,&a,&b,&c);
				cout << "Wazne: " << (int)a << " Czas: " << (int)b  << " Metoda: " << (int)c<< endl;
			}
		}
		if (s=="N")
		{
			void *request;

			POSS_DspInfoCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				POSG_DspInfoCfgGet(request,&a,&b);
				cout << "Gdy zalogowany: " << (int)a << " Gdy nie zalogowany: " << (int)b  << endl;
			}
		}
		if (s=="O")
		{
			void *request;

			POSS_UserAuthCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				POSG_UserAuthCfgGet(request,&a,&b);
				cout << "Sposob log.: " << (int)a << " Tryb kontroli: " << (int)b  << endl;
			}
		}
		if (s=="P")
		{
			void *request;

			POSS_AuthStatusGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned short a;
				POSG_AuthStatusGet(request,&a);
				cout << "Pozostalo dni: " << (int)a  << endl;
			}
		}
		if (s=="R")
		{
			void *request;

			POSS_BillBufCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b;
				unsigned short c;
				POSG_BillBufCfgGet(request,&a,&b,&c);
				cout << "Aktywny: " << (int)a << " Sygnalizacja: " << (int)b << " Procentowo: " << (int)c  << endl;
			}
		}
		if (s=="S")
		{
			void *request;

			POSS_PrintCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned char a,b,c,d;
				POSG_PrintCfgGet(request,&a,&b,&c,&d);
				cout << "Niefiskalne: " << (int)a << " Zmiany PLU: " << (int)b << " Czulosc pap.: " << (int)c << " Obcinacz: " << (int)d  << endl;
			}
		}
		if (s=="T")
		{
			void *request;
			char flagi[256];
			POSS_CashregParGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				POSG_CashregParGet(request,flagi);
				cout << "Numer kasy: " << flagi << endl;
			}
		}
		if (s=="U")
		{
			void *request;

			int ile,k;
			
			cout << "Do wylogowania:";
			cin  >> ile ;
			cin.ignore(65535,cin.widen('\n'));
			cout << "Do wylaczenia : ";
			cin >> k ;
			cin.ignore(65535,cin.widen('\n'));
			POSS_TimeoutsSet(hLocalDevice,&request,(unsigned char)ile,(unsigned char)k);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="V")
		{
			void *request;
			POSS_CommCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				//POSG_CashregParGet(request,flagi);
				//cout << "Numer kasy: " << flagi << endl;
			}
		}
		if (s=="W")
		{
			void *request;

			POSS_BillBufCfgSet(hLocalDevice,&request,1,1,7500);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
		}
		if (s=="X")
		{
			void *request;

			int ile;

			cout << "Typ rekordów [1 2 4 8 128]:";
			cin  >> ile ;
			POSS_FiscMemFirst(hLocalDevice,&request,(unsigned short)ile);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short typ,numer;
					POSG_FiscMemFirst(request,&typ,&numer);
					if (numer>0)
					{
						do {
							
							// read!
							cout << "Reading record: "	<< (int)numer << endl;
							POSS_FiscMemRead(hLocalDevice,&request,numer);
							if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
							{
								if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
								{
									cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
									break;
								}
								else
								{
									// ok, read it.
									
									POSG_FiscMemReadType(request,&typ);
									cout << "Found: "<< (int)typ << endl;
									switch(typ)
									{
									case 1:
										{
											char buffer[128],tots[1024],wart[1024];
											unsigned short numer,paragonow,anulowanych;
											unsigned long zmianPLU;
											POSG_FiscMemReadDaily  (request,buffer,&numer,&paragonow,&anulowanych,tots,wart,&zmianPLU) ;
											cout << "Data: " << buffer << " Numer: " << (int)numer << " Paragonów: " << int(paragonow) ;
											cout << " Anulowanych: " << (int)anulowanych << " Totalizery: " << tots << " Wartości: " << wart << " ZmianPLU: " << (int)zmianPLU << endl;
										}
										break;
									case 2:
										{
											char buffer[64];
											unsigned short numer,stawkaA,stawkaB,stawkaC,stawkaD,stawkaE,stawkaF,stawkaG;
											POSG_FiscMemReadPTUChange(request,buffer,&numer,&stawkaA,&stawkaB,&stawkaC,&stawkaD,&stawkaE,&stawkaF,&stawkaG);   
											cout << "Data: " << buffer << " Numer: " << (int)numer;
											cout << " StawkaA: " << (double)(stawkaA)/100.0;
											cout << " StawkaB: " << (double)(stawkaB)/100.0;
											cout << " StawkaC: " << (double)(stawkaC)/100.0;
											cout << " StawkaD: " << (double)(stawkaD)/100.0;
											cout << " StawkaE: " << (double)(stawkaE)/100.0;
											cout << " StawkaF: " << (double)(stawkaF)/100.0;
											cout << " StawkaG: " << (double)(stawkaG)/100.0;
											cout << endl;
										}
										break;
									case 4:
										{
											char buffer[64];
											unsigned short c,c1,c0;
											POSG_FiscMemReadClearRAM(request,buffer,&c0,&c,&c1);
											cout << "Data: " << buffer << " Numer zerowania: " << (int)c0<< " Przyczyna FISC: " << (int)c << " Przyczyna Apli: " << (int)c1 << endl;
										}
										break;
									case 8:
										{
											char buffer[64];
											POSG_FiscMemReadSaleStart(request,buffer);
											cout << "Data: " << buffer << endl;
										}
										break;
									case 128:
										{
											char buffer[64],nip[64];
											POSG_FiscMemReadFiscal(request,buffer,nip);
											cout << "Data: " << buffer << " NIP: " << nip << endl;
										}
										break;
									default:
										cout << "Unknown record type" << endl;
										POSG_Default(request);
									}
									
								}
							}
							else
							{
								cout << "Timeout Get" <<endl;
							}
							// get next
							POSS_FiscMemNext(hLocalDevice,&request,ile,numer);
							if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
							{
								if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
								{
									cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
									break;
								}
								else
								{
									POSG_FiscMemNext(request,&typ,&numer);
								}
							}
							else
							{
								cout << "Timeout Next" <<endl;
								numer=0;
							}
						} while(numer);

					}
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}	
		if (s=="Y")
		{
			void *request;

			int ile;
			std::string init;
			std::string telefon;
			cout << "Czy modem:";
			cin  >> ile ;
			cin.ignore(65535,cin.widen('\n'));
			cout << "Init : ";
			cin >> init ;
			cin.ignore(65535,cin.widen('\n'));
			cout << "Telefon : ";
			cin >> telefon;
			cin.ignore(65535,cin.widen('\n'));
			POSS_ModemCfgSet(hLocalDevice,&request,(unsigned char)ile,init.c_str(),telefon.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="Z")
		{
			void *request;

			int ile,ident,czy_nadp;
			long param;
			
			std::string init;
			std::string telefon;
			cout << "Numer klawisza:";
			cin  >> ile ;
			cin.ignore(65535,cin.widen('\n'));
			cout << "Identyfikator funkcji : ";
			cin >> ident ;
			cin.ignore(65535,cin.widen('\n'));
			cout << "Opcje: ";
			cin >> param;
			cin.ignore(65535,cin.widen('\n'));
			cout << "Czy nadpisac : ";
			cin >> czy_nadp ;
			cin.ignore(65535,cin.widen('\n'));
			POSS_HotkeyFuncIns(hLocalDevice,&request,(unsigned short)ile,(unsigned short)ident,(unsigned long)param,(unsigned char)czy_nadp);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="0")
		{
			void *request;
			long status;
			if ( (status=POSS_AuthCodeReset(hLocalDevice,&request,"0000",60,"60\n60\n60\n60\n60\n60"))!=POSNET_STATUS_OK)
			{
				cout << "Error: " << status << endl; 
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="1")
		{
			void *request;
			long status;
			if ( (status=POSS_SoundCfgSet(hLocalDevice,&request,0,0))!=POSNET_STATUS_OK)
			{
				cout << "Error: " << status << endl; 
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="2")
		{
			void *request;
			
			char s[1024],s1[1024],s2[1024];
			cout << "Ustaw IP dla Ethernet  IP=: ";
			cin >> s;
			cout << "Maska: ";
			cin >> s1;
			cout << "Brama: ";
			cin >> s2;
			POSS_CommCfgSet(hLocalDevice,&request,1,2,0,0,1,s,s1,s2);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					POSG_Default(request);
					cout << "OK" << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="3")
		{
			void *request;
			long status;

			if ( (status=POSS_HotkeyFuncIns(hLocalDevice,&request,1,1,33,0))!=POSNET_STATUS_OK)
			{
				cout << "Error: " << status << endl; 
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					POSG_Default(request);
					cout << "OK" << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		
														
		if (s=="4")
		{
			void *request;
			long status;

			if ( (status=POSS_DspInfoSet(hLocalDevice,&request,
				0,				
				"1\n1\n2",
				"To pierwsza linia\nTo druga linia\nOraz linia przewijana",
				NULL,
				"1\n1\n1",
				"0\n0\n0",
				"0\n0\n0"
				))!=POSNET_STATUS_OK)
			{
				cout << "Error: " << status << endl; 
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					POSG_Default(request);
					cout << "OK" << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		

		if (s=="5")
		{
			void *request;
			long status;
			char s[64];
			cout << "Data i czas: " ;
			cin >> s;
			if ( (status=POSS_VATSet(hLocalDevice,&request,s,2200,700,300,0,0xFFFF,0xFFFF,0xFFFE))!=POSNET_STATUS_OK)
			{
				cout << "Error: " << status << endl; 
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					POSG_Default(request);
					cout << "OK" << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="6")
		{
			void *request;
			long status;
			POSS_CommCfgGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned char typ;
					unsigned char id_kanalu;
					unsigned char szyfr;
					unsigned char charset;
					unsigned char tcpip;
					char ipv4_address[16];
					char ipv4_netmask[16];
					char ipv4_gateway[16];
					POSG_CommCfgGet(request,&typ,&id_kanalu,&szyfr,&charset,&tcpip,ipv4_address,ipv4_netmask,ipv4_gateway);
					cout << "Typ: " << (int)typ  << " Kanal: " << (int)id_kanalu << " Szyfr? " << (int)szyfr ;
					cout << " Charset: " << (int)charset << " tcpip? " << (int)tcpip;
					cout << " IP: " << ipv4_address << " Netmask: " << ipv4_netmask << " GW: " << ipv4_gateway;
					cout << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}		

		if (s=="Q" || s=="q") return;
	} while(1);
}

void doLevel1C(POSNET_HANDLE hLocalDevice)
{
	do {
		cout << " TESTY - BAZY " << endl;
		cout << " A - Pobierz VAT                          " << " B - Pobierz pozycję paragonową " << endl;
		cout << " C - Stan zapełnienia bufora paragonowego " << " D - Rabat po nazwie " << endl;
		cout << " E - Pobierz nazwe pierwszej grupy        " << " F - Nastepny wolny num. grupy " << endl;
		cout << " G - Pobierz grupe po nazwie              " << " H - Kasowanie statystyk grup " << endl;
		cout << " I - Statystyka grupy                     " << " J - PLU po nazwie" << endl;
		cout << " K - PLU po barkodzie                     " << " L - Statystyka PLU" << endl;
		cout << " M - Czysc statystyki PLU                 " << " N - Usun wszystkie PLU z not." << endl;
		cout << " O - Usun PLU z notat.                    " << " P - Dodaj PLU do notatnika" << endl;
		cout << " R - Nastepny wolny num. PLU              " << " S - Nastepny wolny numer rabatu" << endl;
		cout << " T - Nastepny wolny num. AutoDiscout      " << " U - Czysc statystyki rabatow" << endl;
		cout << " V - Nastepny wolny numer formy plat.     " << " W - Nastepny wolny numer form.kodu." << endl;
		cout << " X - Nastepny wolny numer hotkey          " << " Y - Dodaj sposob platnosci" << endl;
		cout << " Z - Dodaj PLU                            " << " 0 - Payform read " << endl;
		cout << " 1 - Pack Read                            " << " 2 - Plu Read" << endl;
		cout << " 3 - Auto Discount Insert                 " << " 4 - BarcodeIns" << endl;
		cout << " 5 - CntxPluInit (0,0)                    " << " 6 - BarcodeRead" << endl;
		cout << " 7 - PluSetRead                           " << " 8 - ProgDiscntIns" << endl;
		cout << " 9 - Mu Read Context                      " << " a - PLUReadByBarcode" << endl;
		cout << " b - Pack Ins                             " << " c - " << endl;
		cout << " Q - Koniec " << endl;
		string s;
		cin >> s;
		if (s=="A")
		{
			void *request;
			
			POSS_VATGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				unsigned short A,B,C,D,E,F,G;
				POSG_VATGet(request,&A,&B,&C,&D,&E,&F,&G);
				cout << "A: " << A << " B: " << B << " C: " << C << " D: " << D <<  " E: " << E <<   " F: " << F <<   " G: " << G << endl;
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="B")
		{
			void *request;
			
			POSS_SaleRecGet(hLocalDevice,&request,1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				//
				int ok=1;
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
					POSG_Default(request);
					ok=0;
				}
				
				if (ok)
				{
					cout << "Pozycji paragonowych: " << POS_SalesQueueLength(hLocalDevice) << endl;

					if (POS_SalesQueueLength(hLocalDevice))
					{
						while (request=POS_PopSalesQueue(hLocalDevice,0))
						{
							unsigned char c;
							unsigned short nast,type;
							POSG_SaleRecGetType(request,&c,&nast,&type);
							cout << "Typ rekordu SALE: " << (int)type << " Nastepny: " << nast << endl;
										
							if (type==16)
							{
								char d[64],total[256],anul[128];
								unsigned short a,b,c;
								unsigned long plu;
								POSNET_STATUS s;
								s=POSG_SaleRecGetFiscal(request,d,&a,&b,&c,total,anul,&plu);
								if (s!=POSNET_STATUS_OK)
								{
									cout << "Blad GET: " << s << endl;
								}
								else
								{
									cout << "Data: " << d << " Numer: " << (int) a << " Paragonow: " << (int)b ;
									cout << " Anulowanych: " << (int)c << " Totalizery: " << total ;
									cout << " Anulowane: " << anul << " Zmian PLU: " << (int) plu << endl;
								}
							}
							else
							{
								POSG_Default(request);
							}
							
						}
					}
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="C")
		{
			void *request;
			unsigned char c;
			POSS_SaleSizeGet(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				char buffer[64];
				POSG_SaleSizeGet(request,&c);
				cout << "SaleSize: " << itoa(c,buffer,10) << endl;
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="D")
		{
			void *request;
			
			string s;
			cout << "Podaj nazwę : ";
			cin >> s;
			POSS_DiscntGetByName(hLocalDevice,&request,(const char*)s.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_DiscntGetByName(request,&num);
					cout << "Numer: " << num << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="E")
		{
			void *request;
			
			char buf[64];
			POSS_GroupRead(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_GroupRead(request,&num,buf);
					cout << "Numer: " << num << " Nazwa: " << buf <<  endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="F")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_GroupNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_GroupNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="G")
		{
			void *request;
			
			string s;
			cout << "Podaj nazwę : ";
			cin >> s;
			POSS_GroupGetByName(hLocalDevice,&request,(const char*)s.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_GroupGetByName(request,&num);
					cout << "Numer: " << num << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="H")
		{
			void *request;
			POSS_GroupStatClearAll(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="I")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_GroupStatRead(hLocalDevice,&request,(unsigned short)s,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					char og[48],day[256],mon[256];
					POSG_GroupStatRead(request,&num,og,day,mon);
					cout << "Numer: " << num << " Ogolnie: " << og << " Dziennie: " << day << " Miesiecznie: " << mon <<endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="J")
		{
			void *request;
			
			string s;
			cout << "Podaj nazwę : ";
			cin >> s;
			POSS_PLUGetByName(hLocalDevice,&request,(const char*)s.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_PLUGetByName(request,&num);
					cout << "Numer: " << num << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="K")
		{
			void *request;
			
			string s;
			cout << "Podaj nazwę : ";
			cin >> s;
			POSS_PLUGetByBarcode(hLocalDevice,&request,(const char*)s.c_str());
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_PLUGetByBarcode(request,&num);
					cout << "Numer: " << num << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="L")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PLUStatRead(hLocalDevice,&request,(unsigned short)s,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					char og[48],day[48],mon[48],data[48];
					POSG_PLUStatRead(request,&num,og,day,mon,data);
					cout << "Numer: " << num << " Wartosc: " << og << " Ilosc: " << day << " Stan: " << mon << " Ostatnio:" << data <<endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="M")
		{
			void *request;
			POSS_PLUStatClearAll(hLocalDevice,&request,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="N")
		{
			void *request;
			POSS_PLUNotepadDelAll(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}		
		if (s=="O")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PLUNotepadDel(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="P")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PLUNotepadIns(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="R")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PLUNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_PLUNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="S")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_DiscntNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_DiscntNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="T")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_AutoDiscntNextFreeGet(hLocalDevice,&request,(unsigned char)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_AutoDiscntNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="U")
		{
			void *request;
			
			POSS_DiscntStatClearAll(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="V")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PayformNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_PayformNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="W")
		{
			void *request;
			
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_CodeFmtNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_CodeFmtNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="X")
		{
			void *request;
			
			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_HotkeyNextFreeGet(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					POSG_HotkeyNextFreeGet(request,&num);
					cout << "Nast.Wolny.Numer: " << num  << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="Y")
		{
			void *request;
			unsigned long status;
			int numer,typ,flagi,n,nn;

			cout << "Numer: "; cin  >> numer ; cin.ignore(65535,cin.widen('\n'));
			string nazwa,skrot,kurs;
			cout << "Nazwa: " ;getline(cin,nazwa);
			cout << "Typ: "; cin  >> typ ; cin.ignore(65535,cin.widen('\n'));
			cout << "Flagi: "; cin  >> flagi ; cin.ignore(65535,cin.widen('\n'));
			cout << "Skrot: " ;getline(cin,skrot);
			cout << "kurs (4 zn dzies): " ;getline(cin,kurs);
			cout << "Nadpisac: "; cin  >> n ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nadpisac niezerowe: "; cin  >> nn ; cin.ignore(65535,cin.widen('\n'));

			status=POSS_PayformIns(hLocalDevice,&request,(unsigned short)numer,(const char*)nazwa.c_str(),(unsigned char)typ,(unsigned short)flagi,(const char*)skrot.c_str(),(const char*)kurs.c_str(),(unsigned char)n,(unsigned char)nn);
			if (status!=POSNET_STATUS_OK)
			{
				cout << "Error: " << status << endl;
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="Z")
		{
			void *request;

			int numer,n,nn;

			cout << "Numer: "; cin  >> numer ; cin.ignore(65535,cin.widen('\n'));
			string nazwa,barcode,cena,ilosc_min;
			int numer_opakowania,numer_mu,numer_rabatu,numer_grupy,numer_vat,format_ilosci,cena_sztywna,czy_rabat,czy_notatnik;
			cout << "Nazwa: " ;getline(cin,nazwa);
			cout << "Barcode: " ;getline(cin,barcode);
			cout << "Cena: " ;getline(cin,cena);
			cout << "Ilosc minimalna: " ;getline(cin,ilosc_min);
			cout << "Nr opakowania: "; cin  >> numer_opakowania ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nr MU: "; cin  >> numer_mu ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nr rabatu: "; cin  >> numer_rabatu ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nr grupy: "; cin  >> numer_grupy ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nr VAT: "; cin  >> numer_vat ; cin.ignore(65535,cin.widen('\n'));
			cout << "Format ilosci: "; cin  >> format_ilosci ; cin.ignore(65535,cin.widen('\n'));
			cout << "Cena sztywna: "; cin  >> cena_sztywna ; cin.ignore(65535,cin.widen('\n'));
			cout << "Czy rabat: "; cin  >> czy_rabat ; cin.ignore(65535,cin.widen('\n'));
			cout << "Czy notatnik: "; cin  >> czy_notatnik ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nadpisac: "; cin  >> n ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nadpisac niezerowe: "; cin  >> nn ; cin.ignore(65535,cin.widen('\n'));

			int res=POSS_PLUIns(hLocalDevice,&request,
				(unsigned short)numer, //const unsigned short numer_rekordu,
				(const char*)nazwa.c_str(), //const char *nazwa,
				(const char*)barcode.c_str(), //const char *barcode, 
				(const char*)cena.c_str(), //const char *cena,
				(const char*)ilosc_min.c_str(), //const char *ilosc_min,
				(unsigned char)numer_opakowania,//const unsigned char numer_opakowania,
				(unsigned char)numer_mu,//const unsigned char numer_MU,
				(unsigned char)numer_rabatu,//const unsigned char numer_rabatu,
				(unsigned char)numer_grupy,//const unsigned char numer_grupy,
				(unsigned char)numer_vat,//const unsigned char numer_VAT,
				(unsigned char)format_ilosci,//const unsigned char format_ilosci,
				(unsigned char)cena_sztywna,//const unsigned char cena_sztywna,
				(unsigned char)czy_rabat,//const unsigned char czy_rabat,
				(unsigned char)czy_notatnik,//const unsigned char czy_notatnik,
				(unsigned char)n,//const unsigned char czy_nadpisac,
				(unsigned char)nn);//const unsigned char czy_nadpisac_niezerowy,
			cout << "Błąd: " << res << endl;
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="0")
		{
			void *request;

			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PayformRead(hLocalDevice,&request,(unsigned short)s,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short nastepny,flagi;
					unsigned char c;
					char waluta[48],kurs[48],nazwa[48];
					POSG_PayformRead(request,&nastepny,nazwa,&c,&flagi,waluta,kurs);
					cout << "Nazwa: " << nazwa << " Typ: " << c << " Flagi: " << flagi << " Waluta: " << waluta << " Kurs:" << kurs << " Numer: "<< nastepny <<endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="1")
		{
			void *request;

			int s;
			cout << "Podaj numer : ";
			cin >> s;
			POSS_PackRead(hLocalDevice,&request,(unsigned short)s,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					unsigned char c;
					char waluta[48],kurs[48],nazwa[48],barcode[16];
					POSG_PackRead(request,&num,nazwa,barcode,waluta,kurs,&c);
					cout << "Numer: " << num << " Nazwa: " << nazwa << " Kod kreskowy: " << barcode << " Czy sztywna: " << (int)(c) << " Cena: " << waluta << " Stan: " << kurs  <<endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="2")
		{
			void *request;

			int s,s1;
			cout << "Podaj numer : ";
			cin >> s;
			cout << "Czy z kodem kreskowym [0 1] : ";
			cin >> s1;
			POSS_PLURead(hLocalDevice,&request,(unsigned short)s,s1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					unsigned char c,c1,c2,c3,c4,c5,c6,c7,c8;

					char cena[48],stan[48],nazwa[48],barcodes[64],barcode[16];

					POSG_PLURead(request,&num,nazwa,barcode,cena,stan,&c,&c1,&c2,&c5, &c6,&c7,&c8,  &c3,&c4,barcodes);

					cout << "Numer: " << num << "Nazwa: " << nazwa << " Kod podstawowy: " << barcode << " Cena: " << cena << " Stan: " << stan;
					cout << " Typ: "<< (int)c << " Nr.opak.: "<< (int)c1 << " MU: "<< (int)c2 << " Rabat: "<< (int)c3 << " Grupy: "<< (int)c4 << " PTU: " << (int)c5;
					cout << " Kody kreskowe: " << barcodes  << " Format ilosci: " << c6 << " Flaga ceny: " << c7 << " Flaga rabatow: " << c8 << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="3")
		{
			void *request;
			int status;
			int s,s1,s2;
			std::string from,to;
			cout << "Podaj numer rekordu : ";
			cin >> s;
			cout << " Nr. rabatu : ";
			cin >> s1;
			cout << " Godz od: ";
			cin >> from;
			cout << " Godz do: ";
			cin >> to;
			cout << " Czy nadpisac? [0 1] ";
			cin >> s2;
			if (status=POSS_AutoDiscntIns(hLocalDevice,&request,(unsigned short)s,(unsigned short)s1,from.c_str(),to.c_str(),(unsigned char)s2))
			{
				cout << "Auto discnt ins failed: " << hex << status << dec << endl;
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="4")
		{
			void *request;
			int status;
			int s;
			std::string from;
			cout << "Podaj numer PLU : ";
			cin >> s;
			cout << " Podaj Barkody rozdzielone |: ";
			cin >> from;
			// zamien | na \n
			std::string::size_type n;
			while ( (n=from.find("|")) != std::string::npos )
				from.replace(n,1,"\n");
			cout << endl << "-" << endl << from << endl << "-" << endl;
			
			
			
			if (status=POSS_BarcodeIns(hLocalDevice,&request,(unsigned short)s,from.c_str()))
			{
				cout << "Auto discnt ins failed: " << hex << status << dec << endl;
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
				
				
		}
		if (s=="5")
		{
			void *request;
			int status;
			if (status=POSS_CntxPLUInit(hLocalDevice,&request,0,0))
			{
				cout << "Cntx PluInit failed: " << hex << status << dec << endl;
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
				
				
		}
		if (s=="6")
		{
			void *request;
			
			int s;
			cout << "Podaj numer PLU : ";
			cin >> s;
			POSS_BarcodeRead(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					char buffer[1024];
					POSG_BarcodeRead(request,&num,buffer);
					cout << "Numer: " << num << " Kody:" << buffer << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="7")
		{
			void *request;
			
			int s;
			cout << "Podaj numer zestawu : ";
			cin >> s;
			POSS_SetRead(hLocalDevice,&request,(unsigned short)s);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					char buffer[1024],buffer1[2014],buffer2[1024];
					POSG_SetRead(request,&num,buffer,buffer1,buffer2);
					cout << "Numer: " << num << " Numery:" << buffer << " Ilosci: " << buffer1 << " Ceny: " << buffer2 << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="8")
		{
			void *request;
			int status;
			int s,flagaR,flagaP,ile,rN,rR,nad,nadnz;
			std::string from;
			cout << "Podaj numer rekordu : ";
			cin >> s;
			cin.ignore(65535,cin.widen('\n'));
			cout << "Podaj nazwe rabatu : ";
			cin >> from;
			cout << "Flaga Rabat-Narzut [1 0] : ";
			cin >> flagaR;
			cout << "Flaga Procentowy-Kwotowy [1 0] : ";
			cin >> flagaP;
			cout << "Ilosc progow [1..6] : ";
			cin >> ile;
			std::string progi,kwoty,tmp;
			for (int i=0;i<6;i++)
			{
			cout << "Wartosc dla progu "<< i<< " : ";
			cin >> tmp;
			if (i)
			kwoty+="\n"+tmp;
			else
			kwoty+=tmp;
			cout << "Kwota progu "<< i <<" : ";
			cin >> tmp;
			if (i)
			progi+="\n"+tmp;
			else
			progi+=tmp;
			}
			cout << "Czy z narzutami [0 1] : ";
			cin >> rN;
			cout << "Czy z rabatami [0 1] : ";
			cin >> rR;
			cout << "Czy nadpisac [0 1]: ";
			cin >> nad;
			cout << "Czy nadpisac niezerowe [0 1] : ";
			cin >> nadnz;
			
			if (status=POSS_ProgDiscntIns(hLocalDevice,&request,(unsigned short)s,from.c_str(),
				(unsigned char)flagaR, (unsigned char) flagaP, (unsigned char) ile,
				kwoty.c_str(),progi.c_str(),(unsigned char)rN,(unsigned char)rR,(unsigned char)nad,(unsigned char)nadnz	))
			{
				cout << "Auto discnt ins failed: " << hex << status << dec << endl;
			}
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}

		if (s=="9")
		{
			void *request;
			
			
			cout << "Odczyt tablicy MU kontekstowy ";
			
			//POSS_SetRead(hLocalDevice,&request,(unsigned short)s);
			POSS_CntxMUInit(hLocalDevice,&request,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					POSG_Default(request);
					//*
					while (1)
					{
						POSS_MURead(hLocalDevice,&request,0);
						if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
						{
							if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
							{
								cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
								break;
							}
							else
							{
								unsigned short nr;
								char ss[64],ss1[64];
								POSG_MURead(request,&nr,ss,ss1);
								cout << "MU: " << (int) nr << ", Nazwa: " << ss << ", Skrot: " << ss1 << endl;
							}
						}
					}
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="a")
		{
			void *request;

			int s1;
			char s[64];
			cout << "Podaj barkod : ";
			cin >> s;
			cout << "Czy z kodem kreskowym [0 1] : ";
			cin >> s1;
			POSS_PLUReadByBarcode(hLocalDevice,&request,s,s1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					
					unsigned char c,c1,c2,c3,c4,c5,c6,c7,c8;

					char rdb[64],cena[48],stan[48],nazwa[48],barcodes[64],barcode[16];

					POSG_PLUReadByBarcode(request,rdb,nazwa,barcode,cena,stan,&c,&c1,&c2,&c5, &c6,&c7,&c8,  &c3,&c4,barcodes);

					cout << "Kod wyszukujacy: " << rdb << "Nazwa: " << nazwa << " Kod podstawowy: " << barcode << " Cena: " << cena << " Stan: " << stan;
					cout << " Typ: "<< (int)c << " Nr.opak.: "<< (int)c1 << " MU: "<< (int)c2 << " Rabat: "<< (int)c3 << " Grupy: "<< (int)c4 << " PTU: " << (int)c5;
					cout << " Kody kreskowe: " << barcodes  << " Format ilosci: " << c6 << " Flaga ceny: " << c7 << " Flaga rabatow: " << c8 << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="b")
		{
			void *request;

			int numer,n,nn;

			cout << "Numer: "; cin  >> numer ; cin.ignore(65535,cin.widen('\n'));
			string nazwa,barcode,cena,ilosc_min;
			int cena_sztywna,czy_rabat;
			cout << "Nazwa: " ;getline(cin,nazwa);
			cout << "Barcode: " ;getline(cin,barcode);
			cout << "Cena: " ;getline(cin,cena);
			cout << "Ilosc minimalna: " ;getline(cin,ilosc_min);
			cout << "Cena sztywna: "; cin  >> cena_sztywna ; cin.ignore(65535,cin.widen('\n'));
			cout << "Czy rabat: "; cin  >> czy_rabat ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nadpisac: "; cin  >> n ; cin.ignore(65535,cin.widen('\n'));
			cout << "Nadpisac niezerowe: "; cin  >> nn ; cin.ignore(65535,cin.widen('\n'));

			POSS_PackIns(hLocalDevice,&request,
				(unsigned short)numer, //const unsigned short numer_rekordu,
				(const char*)nazwa.c_str(), //const char *nazwa,
				(const char*)barcode.c_str(), //const char *barcode, 
				(const char*)cena.c_str(), //const char *cena,
				(const char*)ilosc_min.c_str(), //const char *ilosc_min,
				(unsigned char)cena_sztywna,//const unsigned char cena_sztywna,
				(unsigned char)czy_rabat,//const unsigned char czy_rabat,
				(unsigned char)n,//const unsigned char czy_nadpisac,
				(unsigned char)nn);//const unsigned char czy_nadpisac_niezerowy,
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					POSG_Default(request);
					cout << "OK" << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="Q" || s=="q") return;
	} while(1);
}

void doLevel1B(POSNET_HANDLE hLocalDevice)
{
	do {
		cout << " TESTY - RAPORTY " << endl;
		cout << " A - VAT                    " << " B - Kasjerów " << endl;
		cout << " C - Fiskalny miesieczny    " << " D - Kasy" << endl;
		cout << " E - Serwisowy              " << " F -  " << endl;
		cout << " G - Konfig. we/wy          " << " H - Braków mag. opakowań" << endl;
		cout << " I - Braków mag. towarów    " << " J - Konfiguracji sprzedaży " << endl;
		cout << " K - Konfig. sprzętu        " << " L - Fiskalny (01-31)-10-2005" << endl;
		cout << " M - Fiskalny za numery 4-5 " << " N - Fiskalny dobowy na 2005-11-01 " << endl;
		cout << " O - Fiskalny dobowy        " << " P - Nieaktywne PLU na 2005-11-01 " << endl;
		cout << " R - PLU wg Rekordów        " << " S - Jednostki wg Rekordów " << endl;
		cout << " T - Klawisze szybkie       " << " U - Zestawy raportów " << endl;
		cout << " V - Opakowan               " << " W - Formaty kodów kresk. " << endl;
		cout << " X - Rabatów                " << " Y - Form płatnosci " << endl;
		cout << " Z - Grup towarowych        " << " 0 - Rabatów czasowych " << endl;
		cout << " 1 - Stat. grup w rozb.     " << " 2 - PLU by VAT (A) " << endl;
		cout << " 3 - PLU by Group (1)       " << " 4 - PLU by Range(1-100) " << endl;
		cout << " 5 - PLU By NAME (A-Z)      " << " 6 - UserStatRead " << endl;


		cout << " Q - Koniec " << endl;
		string s;
		cin >> s;
		if (s=="A")
		{
			void *request;
			
			POSS_RepPTU(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="B")
		{
			void *request;
			
			POSS_RepUser(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="C")
		{
			void *request;
			std::string data;
			unsigned long status;
			cout << "Data: "<<endl;
			cin >> data;

			// test
			//data="2005- 1- 1";

			status=POSS_RepFskMonthly(hLocalDevice,&request,data.c_str(),1);
			if (status!=POSNET_STATUS_OK)
			{
				cout << "Error: " << status << endl;
			}else
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="D")
		{
			void *request;
			POSS_RepCashReg(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="E")
		{
			void *request;
			POSS_RepService(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="G")
		{
			void *request;
			POSS_RepCfgComm(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="H")
		{
			void *request;
			POSS_RepStorePack(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="I")
		{
		/*	void *request;
			POSS_RepStorePLU(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;*/
		}
		if (s=="J")
		{
			void *request;
			POSS_RepCfgSale(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="K")
		{
			void *request;
			POSS_RepCfgHardware(hLocalDevice,&request);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="L")
		{
			void *request;
			POSS_RepFskPeriodByDate(hLocalDevice,&request,"2005-10-01","2005-10-31",1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="M")
		{
			void *request;
			POSS_RepFskPeriodByNum(hLocalDevice,&request,4,5,1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="N")
		{
			void *request;
			POSS_RepFskDaily(hLocalDevice,&request,1,"2005-11-01 14:44");
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="O")
		{
			void *request;
			POSS_RepFskDaily(hLocalDevice,&request,0,NULL);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="P")
		{
			void *request;
			POSS_RepInactivePLU(hLocalDevice,&request,"2005-11-01");
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="R")
		{
			void *request;
			POSS_RepPLUByRecNo(hLocalDevice,&request,1,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="S")
		{
			void *request;
			POSS_RepMU(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="T")
		{
			void *request;
			POSS_RepHotkey(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="U")
		{
			void *request;
			POSS_RepRepSet(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="V")
		{
			void *request;
			POSS_RepPack(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="W")
		{
			void *request;
			POSS_RepCodeFmt(hLocalDevice,&request,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="X")
		{
			void *request;
			POSS_RepDiscnt(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="Y")
		{
			void *request;
			POSS_RepPayForm(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="Z")
		{
			void *request;
			POSS_RepGroup(hLocalDevice,&request,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="0")
		{
			void *request;
			POSS_RepAutoDiscnt(hLocalDevice,&request,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="1")
		{
			void *request;
			POSS_RepGroupStat(hLocalDevice,&request,0,1,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="2")
		{
			void *request;
			POSS_RepPLUByVAT(hLocalDevice,&request,0,0,0,0);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="3")
		{
			void *request;
			POSS_RepPLUByGroup(hLocalDevice,&request,0,0,0,1);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="4")
		{
			void *request;
			POSS_RepPLUByRecNo(hLocalDevice,&request,0,0,0,1,100);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="5")
		{
			void *request;
			POSS_RepPLUByNameRange(hLocalDevice,&request,0,0,0,"A","Z");
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{

			}
			else
				cout << "TIMEOUT" << endl;
		}
		if (s=="6")
		{
			void *request;
			int numer,zer;
			cout << "Numer rekordu: ";
			cin >> numer;
			cout << "Czy zerowac [0 1]";
			cin >> zer;
			POSS_UserStatRead(hLocalDevice,&request,(unsigned short)numer,(unsigned char)zer);
			if (POS_WaitForRequestCompleted(request,1000)!=POSNET_STATUS_TIMEOUT)
			{
				if (POS_GetRequestStatus(request)!=POSNET_STATUS_OK)
				{
					cout << "Błąd: " << POS_GetRequestStatus(request) << endl;
				}
				else
				{
					unsigned short num;
					unsigned long a,b,c;
					char buffer[1024],buffer1[2014],buffer2[1024],buffer3[1024],buffer4[1024],buffer5[1024],buffer6[1024],buffer7[1024],buffer8[1024],buffer9[1024],buffer10[1024],buffer11[1024],buffer12[1024],buffer13[1024],buffer14[1024],buffer15[1024];
					POSG_UserStatRead(request,&num,buffer,buffer1,buffer2,buffer3,buffer4,buffer5,buffer6,buffer7,buffer8,buffer9,&a,&b,buffer10,&c,buffer11,buffer12,buffer13,buffer14,buffer15);
					cout << " Numer: " << num ;
					cout << " Rabaty z reki:" << buffer ;
					cout << " Narzuty z reki: " << buffer1 ;
					cout << " Ostatnie logowanie: " << buffer2 ;
					
					cout << " Ostatnie wylogowanie: " << buffer3 ;
					cout << " Czas pracy: " << buffer4 ;
					cout << " Opak. sprzed.: " << buffer5 ;
					cout << " Opak. zwr.: " << buffer6 ;
					cout << " Wplaty: " << buffer7 ;
					cout << " Wyplaty: " << buffer8 ;
					cout << " Sprzedaz: " << buffer9 ;
					cout << " Par.anul.: " << buffer10 ;
					cout << " Storna: " << buffer11 ;
					cout << " Paragony: " << a ;
					cout << " Paragony anul.: " << b ;
					cout << " Storna: " << c ;
					cout << " Numery form platnosci: " << buffer12;
					cout << " Kwoty form platnosci " << buffer13;
					cout << " Numery rabatow " << buffer14;
					cout << " Kwoty rabatow " << buffer15;
					cout << endl;
				}
			}
			else
				cout << "TIMEOUT" << endl;
		}


		if (s=="Q" || s=="q") return;
	} while(1);
}


void doLevel1D(POSNET_HANDLE hLocalDevice)
{
	do {
		cout << " TESTY - COMPLETE " << endl;
		cout << " A - Test0 Kolejka STD      " << " B - Test1 ErrorAnswer " << endl;
		cout << " C -                        " << " D - " << endl;

		cout << " Q - Koniec " << endl;
		string s;
		cin >> s;
		if (s=="A")
		{
			void *request;
			for (int i=0;i< 10;i++)			
			{
				//POSS_PLUNextFreeGet(hLocalDevice,&request,0,POSNET_REQMODE_AUTOCLEAR);
				POSS_TimeGet(hLocalDevice,&request,POSNET_REQMODE_SPOOL);
				cout << "Sent TOKEN: " << POS_GetRequestCommandSerial(request) << endl;
				//Sleep(100);
			}
			Sleep(500);
			for (int i=0;i< 10;i++)
			{
				if (request=POS_GetNextResponse(hLocalDevice))
				{
					cout << "Answer to: " << POS_GetRequestCommandSerial(request) << endl;
				}
				else
				{
					cout << " No answer waiting ...." << endl;
					Sleep(100);
				}

			}
		}
		if (s=="B")
		{
			void *request;
			POSS_RepMU(hLocalDevice,&request,0);
			POSS_FooterGet(hLocalDevice,&request);
			Sleep(500);
			for (int i=0;i< 10;i++)
			{
				if (request=POS_GetNextResponse(hLocalDevice))
				{
					cout << "Answer to: " << POS_GetRequestCommandSerial(request) << endl;
				}
				else
				{
					cout << " No answer waiting ...." << hex << POS_GetError(hLocalDevice) << dec << endl;

					Sleep(100);
				}

			}
		}

		if (s=="Q" || s=="q") return;
	} while(1);
}


int main(int argc, char *argv[])
{

#include "../setup.inc"

	while (1)
	{
		string s=menuLevel0();
		if (s=="") break;
		
		if (s=="A")
		{
			doLevel1A((POSNET_HANDLE)hLocalDevice);
		}
		if (s=="B")
		{
			doLevel1B((POSNET_HANDLE)hLocalDevice);
		}
		if (s=="C")
		{
			doLevel1C((POSNET_HANDLE)hLocalDevice);
		}
		if (s=="D")
		{
			doLevel1D((POSNET_HANDLE)hLocalDevice);
		}


	}


	POS_CloseDevice(hLocalDevice);
	POS_DestroyDeviceHandle(hDevice);
	return 0;
}
