<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><category>pcsoft.fr.windev</category><copyright>Copyright 2026, PC SOFT</copyright><lastBuildDate>2 Oct 2012 12:04:23 Z</lastBuildDate><pubDate>28 Sep 2012 16:44:13 Z</pubDate><description>Bonjour,&#13;
J'ai ce long code en C++, depuis les années que je suis dans Windev,, j'ai un peu perdu la main en C++. Essayons de le traduire en Wlangage. il y a un fichier .h en cas de besoin. Comme c'est long je vous le colle en dessous.&#13;
A bientôt pour ceux qui s'y mettront.&#13;
&#13;
#include &lt;conio.h&gt; /* required only for function declarations */&#13;
#include "stdafx.h"&#13;
#include "stdio.h"&#13;
#include "stdlib.h"&#13;
#include &lt;stdio.h&gt;&#13;
#include &lt;windows.h&gt;&#13;
#include &lt;ctype.h&gt;&#13;
#include &lt;string.h&gt;&#13;
#include &lt;time.h&gt;&#13;
#include &lt;io.h&gt;&#13;
#include "usb_vc.h"&#13;
&#13;
/**************************************************************************************&#13;
 * Prototype Definitions of local routines&#13;
 **************************************************************************************/&#13;
void Choose_USB();&#13;
void Init_USB();	//Initialize USB port&#13;
void Display_Buffer(unsigned int size);&#13;
void Port_Read();&#13;
void Port_Write();&#13;
void USB_Read();&#13;
void USB_Write();&#13;
void Clear_Buffer();&#13;
void fgl_test_ticket();&#13;
void hp_test_ticket();&#13;
void Write();&#13;
void Perform_Test();&#13;
void Clear_Comm();&#13;
void history();			//Check/Establish history&#13;
void establish_history();&#13;
void record_history();&#13;
void Send_Dual();&#13;
void dual_test_ticket();&#13;
void Find_USB_Printers();&#13;
void Close_USB(int i);		//Close USB port based on index into printer_table&#13;
void dual_test();&#13;
&#13;
/**************************************************************************************&#13;
 * Global variables&#13;
 **************************************************************************************/&#13;
	int ascii_value;			// Ascii value for printer&#13;
	char Buffer[PACKET_SIZE+1];	// char string buffer&#13;
	PVOID pBuffer;				// pointer to buffer&#13;
	FILE *fin, *fout;			// Input/Output files&#13;
	int port;					// Choice of ports as listed below&#13;
	char port_name[5];			// 4 char name + 1 for null&#13;
	int rw_function;			// read=1 &amp; write=2&#13;
	int w_function;				// FGL Command=1  &amp; Test Ticket=2&#13;
	DWORD error_code;			// Error code&#13;
	int i,k;&#13;
	DWORD dwSize;&#13;
	unsigned int Bytes_Transferred;&#13;
	int pipe;&#13;
	USB_HANDLE hUSB = NULL;		//Used to point to the current Boca USB printer&#13;
	HANDLE hWD;&#13;
	HINSTANCE hinstLib;&#13;
	char ichar;&#13;
	HANDLE hPort = NULL;		// Serial Port file pointer&#13;
	BOOL     Port_Ready;&#13;
	DCB      dcb;&#13;
	COMMTIMEOUTS CommTimeouts;&#13;
	BOOL     Write_Com;&#13;
	BOOL     Read_Com;&#13;
	DWORD Bytes_Written;&#13;
	DWORD Bytes_Read;&#13;
	int ix,start,size;&#13;
	int Last_Port_Num = 0;		//Used to track last com port used.&#13;
	char port_function[1];&#13;
	DWORD status;&#13;
&#13;
	//New additions to support the use of multiple printers&#13;
	USB_PRINTER Printer_Table[USB_PRINTER_MAX];	// table used to support multiple printers&#13;
	USB_PRINTER *pTable;						// pointer used to support multiple printers&#13;
	int USB_printer_count=0;					// used to support multiple printers&#13;
	DWORD P1=0,P2=0;&#13;
	bool found1=false,found2=false;&#13;
	USB_HANDLE P1_ptr = NULL;&#13;
	USB_HANDLE P2_ptr = NULL;&#13;
	USB_HANDLE P3_ptr = NULL;&#13;
	int Index=0,printer=0;&#13;
	char		Name[64];&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: main&#13;
 * &#13;
 * Description&#13;
 * This routine demonstrates a technique for reading and writing from a Boca Systems&#13;
 * USB printers.  The user will be prompted for several options beginning with whether to&#13;
 * read from the printer buffer or write to the printer. The user can issue individual&#13;
 * commands to the printer or print an FGL test ticket.  The user will have a selection&#13;
 * of up to eight ports to use. This of course depends on the configuration of the PC &#13;
 * and the Boca Systems USB printers.&#13;
 **************************************************************************************/&#13;
int main(int argc, char* argv[])&#13;
{&#13;
	int temp;&#13;
	char setupPacket[8];&#13;
&#13;
	//Initialize DLL &amp; pick default USB printer, if at least one Boca USB printer found.&#13;
	//Make sure this line of code runs before any attempt to access a Boca USB printer.&#13;
	//This is a must....&#13;
	Init_USB();&#13;
	&#13;
	if (USB_printer_count &gt; 0)			//At least one Boca USB printer found&#13;
		port=USB;						//Port name/flag&#13;
	else&#13;
		port=0;&#13;
&#13;
	while (port != 0)&#13;
	{&#13;
&#13;
		/* Clear Buffer &amp; reset write function between uses */&#13;
		Clear_Buffer();&#13;
		w_function=1;&#13;
&#13;
		/* What Does the user want to do to the currently selected printer? */&#13;
		printf("\n\nCurrent Boca USB Printer Serial Number: %d\n",Printer_Table[Index].Serial_Number);&#13;
		printf("===============================================\n");&#13;
		printf(" 1. Read from printer.\n");&#13;
		printf(" 2. Write to printer.\n");&#13;
		printf(" 3. Change current Boca USB Printer.\n");&#13;
		printf(" 4. Change USB Read/Write Timeout periods.\n");&#13;
		printf(" 5. Read USB Interface Status.\n");&#13;
		printf(" 6. Read Factory Serial Number from printer.\n");&#13;
		printf(" 7. Scan For Boca USB Printers Again.\n");&#13;
		//printf(" 8. Test Dual Path Send Routines.\n");		//experimental test code...&#13;
		printf("99. Exit\n");&#13;
		printf("\nChoose function: ");&#13;
		scanf("%d",&amp;rw_function);&#13;
		&#13;
		/* Verify within range, else exit then exit. */&#13;
		if(rw_function &gt;= 1 &amp;&amp; rw_function &lt;= 8)&#13;
		{&#13;
&#13;
			/* If read/write is write then prompt for what to write. */&#13;
			if (rw_function==2)&#13;
			{&#13;
				printf("\n\nChoose Write Function\n");&#13;
				printf("==========================\n");&#13;
				printf(" 1. Send Text\n");&#13;
				printf(" 2. Send ASCII value\n");&#13;
				printf(" 3. Print FGL Test Ticket\n");&#13;
				printf(" 4. Print HP Test Ticket\n");&#13;
				printf("99. Exit\n");&#13;
				printf("\nChoose function: ");&#13;
				scanf("%d",&amp;w_function);	//w_function variable used in perform_test()&#13;
				gets(Buffer);				//Terminates last scanf into dummy buffer&#13;
&#13;
				if (w_function==1)&#13;
				{&#13;
					Clear_Buffer();&#13;
					printf("\n\nEnter Text: ");&#13;
					gets(Buffer);&#13;
				}&#13;
&#13;
				if (w_function==2)&#13;
				{&#13;
					Clear_Buffer();&#13;
					printf("\n\nEnter Decimal ASCII Value: ");&#13;
					scanf("%d",&amp;ascii_value);&#13;
					Buffer[0] = ascii_value;&#13;
				}&#13;
				if ((w_function&lt;1) || (w_function&gt;4)) rw_function=0; //exit&#13;
			}&#13;
&#13;
			switch (rw_function)		//Are we to perform a read, write or exit?&#13;
			{&#13;
			case 1:						//Read from port&#13;
&#13;
&#13;
					strcpy(port_name,USB_S);&#13;
					//if Boca Printer not previously located, then try now.&#13;
					if (!hUSB)&#13;
					{&#13;
						Choose_USB();	//Pick a Boca USB printer&#13;
					}&#13;
					if (hUSB)&#13;
					{&#13;
						status = USB_Status(hUSB);&#13;
						if(status==0xffffffff)&#13;
							status = USB_Status(hUSB);&#13;
						switch(status)&#13;
						{&#13;
							case 0xffffffff:		//no response&#13;
								printf("\nNo Response from Printer\n");&#13;
							break;&#13;
&#13;
							case 0x18:				//ready response&#13;
								Port_Read();&#13;
							break;&#13;
&#13;
							case 0x20:				//paper out&#13;
								printf("\nPrinter Out of Paper\n");&#13;
							break;&#13;
&#13;
							case 0x10:				//paper jam&#13;
								printf("\nPrinter Paper Jammed\n");&#13;
							break;&#13;
&#13;
							default:&#13;
								printf("\nStatus = %d\n",status);&#13;
							break;&#13;
						}&#13;
&#13;
					}&#13;
					else&#13;
						printf("Printer not found on port %s\n",port_name);&#13;
&#13;
			break;&#13;
&#13;
			case 2:							//Write to port&#13;
&#13;
					strcpy(port_name,USB_S);&#13;
					//if Boca Printer not previously located, then try now.&#13;
					if (!hUSB)&#13;
						Choose_USB();	//Pick a Boca USB printer&#13;
					if (hUSB)&#13;
					{&#13;
						status = USB_Status(hUSB);&#13;
						if(status==0xffffffff)&#13;
							status = USB_Status(hUSB);&#13;
						switch(status)&#13;
						{&#13;
							case 0xffffffff:		//no response&#13;
								printf("\nNo Response from Printer\n");&#13;
							break;&#13;
&#13;
							case 0x18:				//ready response&#13;
								Perform_Test();		//based on value of w_function&#13;
							break;&#13;
&#13;
							case 0x20:				//paper out&#13;
								printf("\nPrinter Out of Paper\n");&#13;
							break;&#13;
&#13;
							case 0x10:				//paper jam&#13;
								printf("\nPrinter Paper Jammed\n");&#13;
							break;&#13;
&#13;
							default:&#13;
								printf("\nStatus = %d\n",status);&#13;
							break;&#13;
						}&#13;
&#13;
					}&#13;
					else&#13;
						printf("Printer not found on port %s\n",port_name);&#13;
				&#13;
			break;&#13;
			case 3:&#13;
&#13;
				Choose_USB();				//Pick a Boca USB printer&#13;
				if (!hUSB)&#13;
					printf("Unable to open printer # %s\n",Printer_Table[Index].Serial_Number);&#13;
				&#13;
			break;&#13;
&#13;
			case 4:							//Set RW timeout periods&#13;
&#13;
					if (!hUSB)				//If not already chosen, &#13;
						Choose_USB();		//Pick a Boca USB printer&#13;
					if (hUSB)&#13;
					{&#13;
&#13;
						// 1000 milliseconds = 1 second&#13;
 &#13;
						printf("\n\nEnter Read Timeout in Milliseconds: ");&#13;
						scanf("%d",&amp;temp);&#13;
&#13;
						//For Read timeout = 1/2 second, use temp=500;&#13;
						port_function[0] = SET_READ_TIMEOUT;		//setup port function&#13;
						Timeout_Port(&amp;port_function,temp);			//execute function&#13;
&#13;
						printf("\n\nEnter Write Timeout in Milliseconds: ");&#13;
						scanf("%d",&amp;temp);&#13;
&#13;
						//Write timeout = 3 seconds, use temp=3000;&#13;
						port_function[0] = SET_WRITE_TIMEOUT;		//setup port function&#13;
						Timeout_Port(&amp;port_function,temp);			//execute function&#13;
					}&#13;
					else printf("Printer not found on port %s\n",port_name);&#13;
				&#13;
			break;&#13;
&#13;
			case 5:							//Read USB Interface Status&#13;
&#13;
					if (!hUSB)				//If not already chosen, &#13;
						Choose_USB();		//Pick a Boca USB printer&#13;
					if (hUSB)&#13;
					{&#13;
						status = USB_Status(hUSB);&#13;
						if(status==0xffffffff)&#13;
							status = USB_Status(hUSB);&#13;
						switch(status)&#13;
						{&#13;
							case 0xffffffff:		//no response&#13;
								printf("\nNo Response from Printer\n");&#13;
							break;&#13;
&#13;
							case 0x18:				//ready response&#13;
								printf("\nPrinter Ready\n");&#13;
							break;&#13;
&#13;
							case 0x20:				//paper out&#13;
								printf("\nPrinter Out of Paper\n");&#13;
							break;&#13;
&#13;
							case 0x10:				//paper jam&#13;
								printf("\nPrinter Paper Jammed\n");&#13;
							break;&#13;
&#13;
							default:&#13;
								printf("\nStatus = %d\n",status);&#13;
							break;&#13;
						}&#13;
&#13;
					}&#13;
					else&#13;
						printf("Printer not found on port %s\n",port_name);&#13;
		&#13;
			break;&#13;
&#13;
			case 6:		//Read USB Devices Serial Number through the control pipe&#13;
&#13;
				pBuffer = &amp;Buffer;				//buffer for return data&#13;
				dwSize = 0x16;					//amount of data requested - never greater than 0xff&#13;
&#13;
				setupPacket[0] = (char)0x80;	//bmRequestType - Interface to Host&#13;
				setupPacket[1] = 0x06;			//bRequest - GET_Descriptor&#13;
				setupPacket[2] = 0x03;			//wValueL - descritor type - STRING = 3&#13;
				setupPacket[3] = 0x03;			//wValueH - which string? index = 3&#13;
				setupPacket[4] = 0x00;			//wIndexL&#13;
				setupPacket[5] = 0x00;			//wIndexH&#13;
				setupPacket[6] = 0x16;			//wLengthL - # of data bytes to transfer, plus control chars&#13;
				setupPacket[7] = 0x00;			//wLengthH&#13;
&#13;
				//USB_Control will return 0xffffffff for an error, if one exists or the data if OK&#13;
				//On a USB control pipe transfer returning a string, the data comes &#13;
				//back in a specific format&#13;
				//    buffer[0] contains length of the rest of the field&#13;
				//    buffer[1] contains the string type in this case a 3 for serial number&#13;
				//    buffer[2]...buffer[n] actual string data&#13;
				error_code = USB_Control(hUSB, pBuffer, dwSize, setupPacket);&#13;
&#13;
				if (error_code == 0xffffffff)&#13;
					printf ("\nNothing was read from port %s\n",port_name);&#13;
				else		//no error&#13;
				{&#13;
					printf ("\nSerial Number = ");&#13;
					Bytes_Transferred = Buffer[0];		//# of bytes read&#13;
					for (i = 2; i &lt; (int)Bytes_Transferred; i++)&#13;
					{&#13;
						// Display only printable characters between 0 &amp; 9.&#13;
						if ((Buffer[i] &gt;= 0x30) &amp;&amp; (Buffer[i] &lt;= 0x39))&#13;
							printf ("%c", Buffer[i]);&#13;
					}&#13;
					printf ("\n");&#13;
				}&#13;
&#13;
&#13;
			break;&#13;
&#13;
			case 7:		//Scan for printers again.  Perhaps something new was plugged in.&#13;
&#13;
				//populate Printer_Table array&#13;
				//Close any potentially open ports&#13;
				for (i = 0; i &lt; USB_printer_count; i++)		//For all ports&#13;
					Close_USB(i);							//close it.&#13;
&#13;
				Find_USB_Printers();		//Fill Printer table for all Boca USB printers&#13;
			    hUSB = NULL;				//still haven't choosen one yet, just found them&#13;
				if (USB_printer_count&gt;0)	//Was at least one printer found?&#13;
				{&#13;
					printf ("\nDevice # \tSerial # \tProduct ID \tProduct Name\n");&#13;
					printf ("======== \t======== \t========== \t============\n");&#13;
&#13;
					for (i = 0; i &lt; USB_printer_count; i++)&#13;
					{&#13;
						if (Printer_Table[i].Product_ID==0x0001)&#13;
							sprintf(Name,"Model 42 - FGL/PCL4");&#13;
						else&#13;
						{&#13;
							if (Printer_Table[i].Product_ID==0x0101)&#13;
								sprintf(Name,"Model 44 - FGL");&#13;
							else&#13;
							{&#13;
								if (Printer_Table[i].Product_ID==0x0102)&#13;
									sprintf(Name,"Model 44 - PCL4");&#13;
								else&#13;
									sprintf(Name," ");&#13;
							}&#13;
						}&#13;
						printf ("  %d \t\t%d \t\t0x%04x \t\t%s\n",i,Printer_Table[i].Serial_Number,Printer_Table[i].Product_ID,Name);&#13;
					}&#13;
&#13;
					Index=0;&#13;
					hUSB = Locate_Device(TRUE,Index);		//choose the first one as default&#13;
					if (hUSB)								//if successful&#13;
					{&#13;
						Printer_Table[Index].hUSB = hUSB;	//store pointer to structure in table&#13;
						//printf ("\nOpened default Boca USB printer Serial Number: %d.\n",Printer_Table[Index].Serial_Number);&#13;
					}&#13;
				}&#13;
				if(!hUSB)				//if unable to find any Boca USB printers&#13;
				{&#13;
					printf ("\nUnable to locate a Boca USB printer....\n");&#13;
				}&#13;
&#13;
			break;&#13;
&#13;
			case 8:&#13;
&#13;
				// This option is not standard communication and is not needed.&#13;
				// Should you want to experiment with simulating a dual path printer&#13;
				// with two USB printers uncomment this and rebuild.&#13;
				/*&#13;
				dual_test();&#13;
			&#13;
				printf("\n\nDual Path Test over, so chose a default printer again.\n");&#13;
&#13;
				Choose_USB();&#13;
				*/&#13;
&#13;
			break;&#13;
&#13;
&#13;
			default:&#13;
				// Used to exit cleanly&#13;
				port = 0;&#13;
			break;&#13;
			}&#13;
		}&#13;
		else port=0;&#13;
	};&#13;
&#13;
	//Close any potentially open ports&#13;
	for (i = 0; i &lt; USB_printer_count; i++)		//For all potentially open ports&#13;
		Close_USB(i);							//close it.&#13;
&#13;
	//Unload library&#13;
	if(hinstLib) FreeLibrary(hinstLib);			//If USB Library is loaded, unload it.&#13;
&#13;
	hUSB=NULL;									//reset pointer to NULL&#13;
&#13;
	//Pause placed here to allow user to see any last messages on exit, when running the program&#13;
	//outside the debugger.  &#13;
	//When using the debugger comment out these 2 lines of code.  They are redundant&#13;
	printf("\nPress Enter Key to continue...\n");	&#13;
	gets(Buffer);&#13;
&#13;
	return 0;									//We are done.&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: Choose_USB&#13;
 * &#13;
 * Description&#13;
 * This routine sets the pointer hUSB.  This pointer is set to point to the active &#13;
 * printer or NULL.&#13;
 **************************************************************************************/&#13;
void Choose_USB()&#13;
{&#13;
	int i;&#13;
&#13;
	//Close any potentially open ports&#13;
	for (i = 0; i &lt; USB_printer_count; i++)		//For all potentially open ports&#13;
		Close_USB(i);							//close it.&#13;
&#13;
	hUSB = NULL;	//reset to NULL&#13;
	Index=0;		//Default to first Boca USB printer found&#13;
&#13;
	// Calls to "hUSB = Locate_Device(FALSE,Index)"			//Pick current active Boca USB printer&#13;
	//If there is more than one Boca USB printer then the choice is a follows: &#13;
	//If the boolean is TRUE then one will be automatically selected.&#13;
	//If the boolean is FALSE then the one choosen is based on the Index.&#13;
&#13;
	//USB_printer_count established when Find_USB_Printers() is called.&#13;
	if(USB_printer_count==0)		//if no Boca USB printers found&#13;
	{&#13;
		//If unable to locate Boca USB printer&#13;
		printf ("Unable to locate Boca USB printer....\n");&#13;
	}&#13;
	else&#13;
	{&#13;
&#13;
		if(USB_printer_count==1)		//if there is only one printer, pick it.&#13;
		{&#13;
			if (Printer_Table[Index].hUSB)				//if port already open&#13;
				Close_Port(Printer_Table[Index].hUSB);	//close it.&#13;
			hUSB = Locate_Device(TRUE,Index);			//Attempt to reopen port&#13;
		}&#13;
		else		//multiple choices found, control by Index&#13;
		{&#13;
			printf ("\nDevice # \tSerial # \tProduct ID \tProduct Name\n");&#13;
			printf ("\n======== \t======== \t========== \t============\n");&#13;
&#13;
			for (i = 0; i &lt; USB_printer_count; i++)&#13;
			{&#13;
				if (Printer_Table[i].Product_ID==0x0001)&#13;
					sprintf(Name,"Model 42 - FGL/PCL4");&#13;
				else&#13;
				{&#13;
					if (Printer_Table[i].Product_ID==0x0101)&#13;
						sprintf(Name,"Model 44 - FGL");&#13;
					else&#13;
					{&#13;
						if (Printer_Table[i].Product_ID==0x0102)&#13;
							sprintf(Name,"Model 44 - PCL4");&#13;
						else&#13;
							sprintf(Name," ");&#13;
					}&#13;
				}&#13;
				printf ("  %d \t\t%d \t\t0x%04x \t\t%s\n",i,Printer_Table[i].Serial_Number,Printer_Table[i].Product_ID,Name);&#13;
			}&#13;
&#13;
			printf("\nEnter Device # to choose a Printer: ");&#13;
			scanf("%d",&amp;printer);&#13;
			gets(Buffer);			//Terminates last scanf into dummy buffer&#13;
&#13;
			//if an invalid number entered here Index = 0 will be used.&#13;
			if((printer&gt;=0) &amp;&amp; (printer&lt;USB_printer_count))&#13;
			{&#13;
				Index = printer;&#13;
			}&#13;
&#13;
			//check to see if port already open.&#13;
			if (Printer_Table[Index].hUSB)				//if port already open&#13;
				Close_Port(Printer_Table[Index].hUSB);	//close it.&#13;
			hUSB = Locate_Device(FALSE,Index);			//Pick current active Boca USB printer&#13;
		}&#13;
&#13;
		//Verify the open was successful.  At this point, hUSB points to the current &#13;
		//device and it's information is updated and stored in printer table.&#13;
		if (hUSB)								//if successful hUSB != NULL&#13;
			Printer_Table[Index].hUSB = hUSB;	//store pointer to structure in table&#13;
		else									//else, unsuccesful&#13;
			Printer_Table[Index].hUSB = NULL;	//set pointer in table to NULL&#13;
	}&#13;
	return;&#13;
}&#13;
/**************************************************************************************&#13;
 * Routine Name: Init_USB&#13;
 * &#13;
 * Description&#13;
 * This routine loads the dll, performs verification and searches for Boca USB printers&#13;
 **************************************************************************************/&#13;
void Init_USB()&#13;
{&#13;
	/* Load Dynamic Link Library for BOCA Printers */&#13;
	hinstLib=LoadLibrary("boca.dll");&#13;
	if(hinstLib)&#13;
	{&#13;
		// Perform initialization and registration&#13;
		if (proc_address(hinstLib) == 0)  //All is good&#13;
		{&#13;
			if (Get_Handle(&amp;hWD))&#13;
			{&#13;
				Find_USB_Printers();		//Fill Printer table for all Boca USB printers&#13;
			    hUSB = NULL;				//still haven't choosen one yet, just found them&#13;
				if (USB_printer_count&gt;0)	//Was at least one printer found?&#13;
				{&#13;
					printf ("\nDevice # \tSerial # \tProduct ID \tProduct Name\n");&#13;
					printf ("======== \t======== \t========== \t============\n");&#13;
&#13;
					for (i = 0; i &lt; USB_printer_count; i++)&#13;
					{&#13;
						if (Printer_Table[i].Product_ID==0x0001)&#13;
							sprintf(Name,"Model 42 - FGL/PCL4");&#13;
						else&#13;
						{&#13;
							if (Printer_Table[i].Product_ID==0x0101)&#13;
								sprintf(Name,"Model 44 - FGL");&#13;
							else&#13;
							{&#13;
								if (Printer_Table[i].Product_ID==0x0102)&#13;
									sprintf(Name,"Model 44 - PCL4");&#13;
								else&#13;
									sprintf(Name," ");&#13;
							}&#13;
						}&#13;
&#13;
						printf ("  %d \t\t%d \t\t0x%04x \t\t%s\n",i,Printer_Table[i].Serial_Number,Printer_Table[i].Product_ID,Name);&#13;
					}&#13;
					Index=0;&#13;
					hUSB = Locate_Device(TRUE,Index);		//choose the first one as default&#13;
					if (hUSB)								//if successful&#13;
					{&#13;
						Printer_Table[Index].hUSB = hUSB;	//store pointer to structure in table&#13;
						//printf ("\nOpened default Boca USB printer Serial Number: %d.\n",Printer_Table[Index].Serial_Number);&#13;
					}&#13;
				}&#13;
				if(!hUSB)				//if unable to find any Boca USB printers&#13;
				{&#13;
					printf ("\nUnable to locate a Boca USB printer....\n");&#13;
				}&#13;
&#13;
			}&#13;
			else&#13;
			{&#13;
				error_code = GetLastError();&#13;
				printf ("Unable to Get Handle.... Error = %d\n",error_code);&#13;
			}&#13;
		}&#13;
		else printf ("Unable to Initialize/Register DLL routines....\n");&#13;
	}&#13;
	else&#13;
	{&#13;
		error_code = GetLastError();&#13;
		printf ("Unable to Open Library.... Error = %d\n",error_code);&#13;
	}&#13;
	return;&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: Display_Buffer&#13;
 * &#13;
 * Description&#13;
 * Display whatever is in the buffer two ways Hexadecimal and characters.  The character&#13;
 * response prints only printable text.  The Hexadecimal dump will display everything read.&#13;
 *&#13;
 * Once it is assumed the incoming data is status data it will represent:&#13;
 *&#13;
 *                        0x02 = "Start of Text"&#13;
 *                        0x03 = "End of Text"&#13;
 *                        0x04 = "End of Transmission"&#13;
 *                        0x05 = "Test Button Ticket ACK"&#13;
 *                        0x06 = "Ticket ACK"&#13;
 *                        0x10 = "Out of Tickets"&#13;
 *                        0x11 = "X-On"&#13;
 *                        0x12 = "Power On"&#13;
 *                        0x13 = "X-Off"&#13;
 *                        0x15 = "Ticket NAK"&#13;
 *                        0x16 = "Ribbon Low"&#13;
 *                        0x17 = "Ribbon Out"&#13;
 *                        0x18 = "Ticket Jam"&#13;
 *                        0x19 = "Illegal Data"&#13;
 *                        0x1A = "Power Up Problem"&#13;
 *                        0x1C = "Incomplete Logo Stored in FLASH"&#13;
 **************************************************************************************/&#13;
void Display_Buffer(unsigned int size)&#13;
{&#13;
	unsigned int i;&#13;
  &#13;
	printf ("\n\nThe buffer contains %d Byte(s) of Data.",strlen(Buffer)-1);&#13;
&#13;
	// Display as Ascii characters&#13;
	printf ("\n\nCharacter Response   = ");&#13;
	for (i = 1; i &lt; size; i++)&#13;
	{&#13;
		// Display only printable characters. Display a space for the rest.&#13;
		if ((Buffer[i] &gt;= SPACE) &amp;&amp; (Buffer[i] &lt;= TILDE))&#13;
			printf ("%c", Buffer[i]);&#13;
		else&#13;
			printf("%c",SPACE);&#13;
	}&#13;
&#13;
	// Display as Ascii Hexadecimal&#13;
	printf ("\n\nHexadecimal Response = ");&#13;
	for (i = 1; i &lt; size; i++)&#13;
		printf ("%x ", Buffer[i]);&#13;
	printf (" \n");&#13;
&#13;
&#13;
	return;&#13;
}&#13;
&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: Port_Read&#13;
 * &#13;
 * Description&#13;
 * Read from currently selected USB, parallel or serial port and display Buffer.&#13;
 **************************************************************************************/&#13;
void Port_Read()&#13;
{&#13;
&#13;
	Bytes_Transferred = 0;&#13;
&#13;
	// USB Port&#13;
	USB_Read();&#13;
&#13;
	if (Bytes_Transferred == 0)&#13;
		printf ("\nNothing was read from port %s\n",port_name);&#13;
	else&#13;
		Display_Buffer(Bytes_Transferred);&#13;
&#13;
	return;&#13;
}&#13;
&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: Port_Write&#13;
 * &#13;
 * Description&#13;
 * Port_Write was originally written to output data to the currently selected port&#13;
 * be that USB, parallel or serial port.  This version has been simplified for just USB.&#13;
 * This routine could be eliminated and calls directly made to USB_Write.  This is maintained&#13;
 * to allow for backwards compatability to anyone already making calls to Port_Write().&#13;
 **************************************************************************************/&#13;
void Port_Write()&#13;
{&#13;
&#13;
	// USB Port&#13;
	USB_Write();&#13;
&#13;
&#13;
	return;&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: USB_Read&#13;
 * &#13;
 * Description&#13;
 * Read data from currently selected USB port into Buffer.&#13;
 **************************************************************************************/&#13;
void USB_Read()&#13;
{&#13;
	pBuffer = &amp;Buffer;&#13;
	dwSize = USB_PACKET_SIZE;&#13;
&#13;
	error_code = Read_Data(hUSB, pBuffer, dwSize,READ_PIPE);	//DLL call&#13;
&#13;
	if (error_code == 0xffffffff)&#13;
		printf ("Read Error from USB port...... \n");&#13;
	else&#13;
		Bytes_Transferred = error_code;	//# of bytes read&#13;
	return;&#13;
}&#13;
&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: USB_Write&#13;
 * &#13;
 * Description&#13;
 * Write Buffer data out to the currently selected USB port&#13;
 **************************************************************************************/&#13;
void USB_Write()&#13;
{&#13;
	pBuffer = &amp;Buffer;&#13;
	dwSize = strlen(Buffer);&#13;
&#13;
	error_code = Write_Data(hUSB, pBuffer, dwSize, WRITE_PIPE);	//DLL call&#13;
&#13;
	if (error_code == 0xffffffff)&#13;
		printf ("Error on write to USB port......\n");&#13;
&#13;
	return;&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: Clear_Buffer()&#13;
 * &#13;
 * Description&#13;
 * Clear Buffer between uses by padding string with nulls.&#13;
 **************************************************************************************/&#13;
void Clear_Buffer()&#13;
{&#13;
	pBuffer = &amp;Buffer;&#13;
	memset (pBuffer,0,PACKET_SIZE+1);&#13;
	return;&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: fgl_test_ticket()&#13;
 *&#13;
 * This routine will generate an FGL test ticket and send it to the currently&#13;
 * selected port.&#13;
 **************************************************************************************/&#13;
void fgl_test_ticket()&#13;
{&#13;
&#13;
	strcpy(Buffer,"&lt;RL&gt;&lt;RC300,20&gt;&lt;F12&gt;BOCA");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC300,110&gt;&lt;RL&gt;&lt;F6&gt;&lt;HW1,1&gt;&lt;VA7&gt;");	//	codename/version&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC300,160&gt;&lt;RL&gt;&lt;F6&gt;&lt;HW1,1&gt;&lt;VA9&gt;");	//	common code.&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC370,740&gt;&lt;RU&gt;GHOSTWRITER");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC48,880&gt;&lt;RR&gt;&lt;F2&gt;FRIENDLY GHOST LANGUAGE");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC52,862&gt;PLACE LETTERS ANYWHERE");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC80,1170&gt;&lt;F6&gt;&lt;RR&gt;VOID");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC15,1100&gt;&lt;F3&gt;TEST TICKET ONLY");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC8,1010&gt;&lt;X2&gt;&lt;NXL10&gt;*GHOST 123*");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RR&gt;&lt;RC78,915&gt;  CODE 39  ");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RU&gt;&lt;RC320,740&gt;&lt;BS17,30&gt;TICKET &amp; LABEL PRINTER");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;NR&gt;&lt;F3&gt;&lt;RC0,300&gt;300 DPI PRINT QUALITY");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;NR&gt;&lt;RC30,300&gt; Print any bar code");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC70,300&gt;&lt;X2&gt;&lt;OL6&gt;^CODE 128^");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC90,250&gt;&lt;RR&gt;CODE 128");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC96,340&gt;&lt;X3&gt;&lt;NXP10&gt;*MONKEY*");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC206,340&gt;&lt;X2&gt;&lt;NP6&gt;*MONKEY*&lt;F2&gt;&lt;HW1,1&gt;");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;NR&gt;&lt;F1&gt;&lt;SP180,640&gt;&lt;LO1&gt;");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC371,385&gt;&lt;F2&gt;&lt;NR&gt;SW1=          SW2=          SW3=");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC371,824&gt;LEFT = 1  RIGHT = 0");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC385,150&gt;&lt;F11&gt;Script printing is now standard.");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC430,150&gt;&lt;F9&gt;High density printing is clear and readable");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC450,150&gt;&lt;F2&gt;High density printing is clear and readable");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;RC470,150&gt;&lt;F1&gt;Legal size printing");&#13;
	Port_Write();&#13;
	strcpy(Buffer,"&lt;p&gt;");	//	Form Feed.&#13;
	Port_Write();&#13;
}&#13;
&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: Perform_Test&#13;
 *&#13;
 * This routine performs the write tests.&#13;
 **************************************************************************************/&#13;
void Perform_Test()&#13;
{&#13;
	switch (w_function)&#13;
	{&#13;
		case 1:&#13;
			Port_Write();			//write an individual command to printer.&#13;
		break;&#13;
&#13;
		case 2:&#13;
			Port_Write();			//write an ASCII value/command to printer.&#13;
		break;&#13;
		&#13;
		case 3:&#13;
			fgl_test_ticket();		//send an entire FGL test ticket to printer.&#13;
		break;&#13;
&#13;
		case 4:&#13;
			hp_test_ticket();		//send an entire HP test ticket to printer.&#13;
		break;&#13;
&#13;
		default:&#13;
		break;&#13;
	}&#13;
	return;&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: hp_test_ticket()&#13;
 *&#13;
 * This routine will generate an HP test ticket by reading the file hp_id.prn.&#13;
 **************************************************************************************/&#13;
void hp_test_ticket()&#13;
{&#13;
	FILE *fp;&#13;
	long filesize;&#13;
&#13;
&#13;
	Clear_Buffer();&#13;
	&#13;
	fp = fopen("hp_id.prn","rb");&#13;
	if(fp == NULL)&#13;
		printf("\nUnable to find hp_id.prn");&#13;
	else&#13;
	{&#13;
		filesize = filelength(fileno(fp));&#13;
		while(filesize &gt; 0)&#13;
		{&#13;
			if(filesize &gt; SER_PACKET_SIZE)&#13;
				i = SER_PACKET_SIZE;&#13;
			else&#13;
				i = filesize;&#13;
			fread(pBuffer, sizeof( char ), i, fp);&#13;
			if (i &gt; 0)&#13;
				error_code = Write_Data(hUSB, pBuffer, i, WRITE_PIPE);&#13;
			filesize = filesize - i;&#13;
		}&#13;
&#13;
		fclose(fp);&#13;
	}&#13;
&#13;
}&#13;
&#13;
&#13;
//Initialization code, that searches for Boca USB printers&#13;
void Find_USB_Printers()&#13;
{&#13;
	int i;&#13;
	USB_printer_count=0;				&#13;
	for (i = 0; i &lt; USB_PRINTER_MAX; i++)	//clear table&#13;
	{&#13;
		Printer_Table[i].Serial_Number=0;	//zero&#13;
		Printer_Table[i].Product_ID=0;		//zero&#13;
		Printer_Table[i].hUSB=NULL;			//null pointer&#13;
	}&#13;
	found1 = false;							//initialize logical for printer A&#13;
	found2 = false;							//initialize logical for printer B&#13;
	pTable = &amp;Printer_Table[0];				//establish pointer to start of table&#13;
	USB_printer_count = USB_Find(pTable);	//Populate table, Count &amp; identify USB printers&#13;
	return;&#13;
}&#13;
&#13;
void Close_USB(int i)&#13;
{&#13;
	if(Printer_Table[i].hUSB) Close_Port(Printer_Table[i].hUSB);			//If a USB port is open, close it.&#13;
	Printer_Table[i].hUSB=NULL;			//null pointer&#13;
&#13;
	return;&#13;
}&#13;
&#13;
&#13;
&#13;
/**************************************************************************************&#13;
 * Below is a collection of routines that allow a user to use 2 Boca USB FGL printers as &#13;
 * if they were one Boca Dual FGL printer.  A Boca dual printer can be commanded to &#13;
 * change between paths A &amp; B with the use of the FGL commands &lt;P1&gt; and &lt;P2&gt;.&#13;
 * To exercise these routines from the code, look at the main menu code options above &#13;
 * and uncomment the line of code to print menu option 7, rebuild and run again.  Also&#13;
 * look at the Case 7 in the switch statement in the main routine. It drives this.&#13;
 * These routines (and case 7) need not be a part of the standard USB communication code &#13;
 * and can be excluded if you choose If you are using just one printer or simply don't &#13;
 * need to simulate a dual path printer with 2 Boca USB printers, then eliminate these routines&#13;
 * to simplify it.&#13;
 * At the time Dual path printer were/are not made with one of the paths being a &#13;
 * magnetic printer and this is a solution to simulate that.&#13;
 * Once these routines had been written to prove the functionality, it seemed a waste not&#13;
 * to share it with anyone who might want to use two Boca USB printers as one Dual Path &#13;
 * printer. The same FGL command procedures already written for an existing dual path system&#13;
 * would work with the 2 USB printers.  &#13;
 **************************************************************************************/&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: history()&#13;
 * &#13;
 * Description&#13;
 * This routine uses a file named usb_history.dat to maintain the current selections&#13;
 * of Printer A &amp; B when printing with 2 printer simulating one dual printer.  This&#13;
 * data is maintained so that even after power outages, the printers assignment will &#13;
 * be maintained for the next use.&#13;
 **************************************************************************************/&#13;
void history()&#13;
{&#13;
	FILE *history_fp;				//File pointer for USB history data file&#13;
	int i;&#13;
&#13;
	&#13;
	history_fp = fopen("usb_history.dat","r");&#13;
	if(history_fp == NULL)		//No history recorded, so lets establish one&#13;
	{&#13;
		if(USB_printer_count&gt;0)&#13;
		{&#13;
			establish_history();&#13;
			record_history();&#13;
		}&#13;
   	}&#13;
	else		//read history file, &amp; verify printer currently plugged in&#13;
	{&#13;
		fscanf(history_fp,"%d",&amp;P1);&#13;
		fscanf(history_fp,"%d",&amp;P2);&#13;
		fclose(history_fp);&#13;
&#13;
		//verify P1 &amp; P2 in table of found printers&#13;
		found1=false;&#13;
		i=0;&#13;
		do&#13;
		{&#13;
			if (P1==Printer_Table[i].Serial_Number) found1 = true;&#13;
			i++;&#13;
		}&#13;
		while ((i &lt; USB_printer_count) &amp;&amp; (!found1));&#13;
&#13;
		found2=false;&#13;
		i=0;&#13;
		do&#13;
		{&#13;
			if (P2==Printer_Table[i].Serial_Number) found2 = true;&#13;
			i++;&#13;
		}&#13;
		while ((i &lt; USB_printer_count) &amp;&amp; (!found2));&#13;
&#13;
	}&#13;
}&#13;
&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: establish_history()&#13;
 * &#13;
 * Description&#13;
 * This rouinte will collect the serial numbers needed for printers P1 &amp; P2 and then&#13;
 * call record_history().&#13;
 **************************************************************************************/&#13;
void establish_history()&#13;
{&#13;
	int printer,i;&#13;
&#13;
	printf("\nNo multiple printer history exists or history out of date. ");&#13;
	printf("\nWe need to setup A &amp; B.  Enter the device number for each selection.");&#13;
	printf ("\nDevice # \tSerial # \tProduct ID \tProduct Name\n");&#13;
	printf ("\n======== \t======== \t========== \t============\n");&#13;
&#13;
	for (i = 0; i &lt; USB_printer_count; i++)&#13;
	{&#13;
		if (Printer_Table[i].Product_ID==0x0001)&#13;
			sprintf(Name,"Model 42 - FGL/PCL4");&#13;
		else&#13;
		{&#13;
			if (Printer_Table[i].Product_ID==0x0101)&#13;
				sprintf(Name,"Model 44 - FGL");&#13;
			else&#13;
			{&#13;
				if (Printer_Table[i].Product_ID==0x0102)&#13;
					sprintf(Name,"Model 44 - PCL4");&#13;
				else&#13;
					sprintf(Name," ");&#13;
			}&#13;
		}&#13;
		printf ("  %d \t\t%d \t\t0x%04x \t\t%s\n",i,Printer_Table[i].Serial_Number,Printer_Table[i].Product_ID,Name);&#13;
	}&#13;
&#13;
	printf("\nChoose Primary Printer A: ");&#13;
	scanf("%d",&amp;printer);&#13;
	gets(Buffer);			//Terminates last scanf into dummy buffer&#13;
	if((printer&gt;=0) &amp;&amp; (printer&lt;USB_printer_count))&#13;
	{&#13;
		P1 = Printer_Table[printer].Serial_Number;&#13;
		found1 = true;&#13;
	}&#13;
&#13;
			&#13;
	printf("\nChoose Secondary Printer B: ");&#13;
	scanf("%d",&amp;printer);&#13;
	gets(Buffer);			//Terminates last scanf into dummy buffer&#13;
	if((printer&gt;=0) &amp;&amp; (printer&lt;USB_printer_count)) &#13;
	{&#13;
		P2 = Printer_Table[printer].Serial_Number;&#13;
		found2 = true;&#13;
	}&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: record_history()&#13;
 * &#13;
 * Description&#13;
 * This rouinte will write the serial numbers selected for printers P1 &amp; P2 &#13;
 * to the history file usb_history.dat&#13;
 **************************************************************************************/&#13;
void record_history()&#13;
{&#13;
	FILE *history_fp;				//File pointer for USB history data file&#13;
&#13;
	//record new history, destroy any old data&#13;
	history_fp = fopen("usb_history.dat","w");		&#13;
	fprintf(history_fp, "%d\n", P1 );&#13;
	fprintf(history_fp, "%d\n", P2 );&#13;
	fclose(history_fp);&#13;
}&#13;
void dual_test()&#13;
{&#13;
					// For this test make sure any open port is closed from some previous &#13;
				// efforts above.  Close any port open in the table&#13;
				for (Index = 0; Index &lt; USB_printer_count; Index++)&#13;
				{&#13;
					if (Printer_Table[Index].hUSB)&#13;
					{&#13;
						Close_Port(Printer_Table[Index].hUSB);&#13;
						Printer_Table[Index].hUSB = NULL;&#13;
					}&#13;
				}&#13;
&#13;
				//Place this call anywhere needed for potential hot swapping of USB printers&#13;
				Find_USB_Printers();&#13;
&#13;
				//Check Global veriable to determine number of printer found.&#13;
				if (USB_printer_count == 0)				//No printers found, error condition&#13;
				{&#13;
					printf("\nNo Boca Systems USB printers found.");&#13;
				}&#13;
				else if (USB_printer_count == 1)		//Only one printer found, so set all pointers to it&#13;
				{&#13;
					P1=Printer_Table[0].Serial_Number;	//Make sure they point to the same place.&#13;
					P2=Printer_Table[0].Serial_Number;	//This one print may be a dual path printer&#13;
					found1 = true;						//that needs to act normal.&#13;
					found2 = true;&#13;
				}&#13;
				else if (USB_printer_count &gt; 1)			//More than one printer found&#13;
				{&#13;
					//Associate:&#13;
					//&#13;
					//		Printer A (also known as P1) with FGL command &lt;P1&gt;&#13;
					//		Printer B (also known as P2) with FGL command &lt;P2&gt;&#13;
					//&#13;
					//Setting Printer A as P1 and Printer B as P2 will help simulate&#13;
					//a dual feed printer for two Boca Systems USB printers.&#13;
					//We will check on prior printer history, or establish a new one. &#13;
					//Next, be aware of special communication with Printers P1 &amp; P2 &#13;
					//will happen through calls to Send_Dual() instead of calling &#13;
					//the usual routine Send() directly.&#13;
					//Send_Dual() will scan the ASCII strings headed to the USB port&#13;
					//for the FGL commands &lt;P1&gt; and &lt;P2&gt;.  A printer pointer will be establish&#13;
					//and then a call to Send() will be performed from within Send_Dual()&#13;
&#13;
					//Lets check on and/or establish printer history&#13;
					history();	&#13;
&#13;
					//To have arrived here, multiple printers must have been found on your system .&#13;
					//The possible options at this point are:&#13;
					// 1. None of these printer match up to your old setup, or you have &#13;
					//    no history (first time).  usb_history.dat does not exist, yet.&#13;
					// 2. Printer A &lt;P1&gt; was found but not printer B &lt;P2&gt;&#13;
					// 3. Printer B &lt;P2&gt; was found but not printer A &lt;P1&gt;&#13;
					// 4. Both printers A &amp; B found.  All is good.&#13;
					//&#13;
					//In the cases (2 &amp; 3) where only one printer is found then a substitue&#13;
					//be used in its place, if one is found.&#13;
					//&#13;
					//The variables found1 &amp; found2 are logical flags used to indicate &#13;
					//whether P1 and/or P2 have been found&#13;
&#13;
					//Neither A nor B were found (or yet exist), so let's establish &#13;
					//the choices for printer A (P1) &amp; B (P2)&#13;
					if ((!found1) &amp;&amp; (!found2))		&#13;
					{&#13;
						//re-establish history...&#13;
						printf("\nFound Neither A %d nor B %d",P1,P2);&#13;
						establish_history();&#13;
						record_history();&#13;
					}&#13;
					else&#13;
					{&#13;
						if (!found1)				//A was not found but B was&#13;
						{&#13;
							//reassign P1...&#13;
							printf("\nFound B %d but not A %d",P2,P1);&#13;
							i=0;&#13;
&#13;
							//Look for a substitute printer on the system&#13;
							while ((i &lt; USB_printer_count) &amp;&amp; (!found1))&#13;
							{	//don't let P1 &amp; P2 be the same printer just yet, since there &#13;
								//is at least one other.&#13;
								if (Printer_Table[i].Serial_Number!=P2)		&#13;
								{&#13;
									P1=Printer_Table[i].Serial_Number;&#13;
									found1 = true;&#13;
								}&#13;
								else i++;&#13;
							}&#13;
							if(found1)		//if a substitue printer was found and assigned&#13;
							{&#13;
								printf("\nreassigned A as %d",P1);&#13;
								record_history();	//update the history file usb_history.dat&#13;
							}&#13;
							else	//if not then this is a error condition. You should never arrive here&#13;
							{&#13;
								printf("\nunable to reassign A");&#13;
								//Error condition needs to be dealt with so Printer A (P1) &#13;
								//and Printer B (P2) will become the same.  No history update will &#13;
								//be performed at this point.  We just need a graceful exit&#13;
								P1=P2;&#13;
								found1 = true;&#13;
							}&#13;
						}&#13;
						else &#13;
						{&#13;
							if (!found2)				//B was not found but A was&#13;
							{&#13;
								//reassign P2...&#13;
								printf("\nFound A %d but not B %d",P1,P2);&#13;
								i=0;&#13;
								while ((i &lt; USB_printer_count) &amp;&amp; (!found2))&#13;
								{	//don't let P1 &amp; P2 be the same printer just yet, since there &#13;
									//is at least one other.&#13;
									if (Printer_Table[i].Serial_Number!=P1)&#13;
									{&#13;
										P2=Printer_Table[i].Serial_Number;&#13;
										found2 = true;&#13;
									}&#13;
									else i++;&#13;
								}&#13;
								if(found2)		//if a substitue printer was found and assigned&#13;
								{&#13;
									printf("\nreassigned B as %d",P2);&#13;
									record_history();	//update the history file usb_history.dat&#13;
								}&#13;
								else	//if not then this is a error condition. You should never arrive here&#13;
								{&#13;
									printf("\nunable to reassign B");&#13;
									//Error condition needs to be dealt with so Printer B (P2) &#13;
									//and Printer A (P1) will become the same.  No history update will &#13;
									//be performed at this point.  We just need a graceful exit&#13;
									P2=P1;&#13;
									found2 = true;&#13;
								}&#13;
							}&#13;
							else&#13;
							{&#13;
								printf("\nFound Both A %d and B %d",P1,P2);	//All is good&#13;
&#13;
							}&#13;
						}&#13;
					}&#13;
					//if both paths established then, print test tickets&#13;
					if ((found1) &amp;&amp; (found2))&#13;
					{&#13;
						//Test Code&#13;
						//set up dual pointers for Global hUSB &#13;
						for (Index = 0; Index &lt; USB_printer_count; Index++)	//clear table&#13;
						{&#13;
&#13;
							//check to see if port has already been opened.&#13;
							if (Printer_Table[Index].hUSB)				//if port already open&#13;
									Close_USB(Index);							//close it.&#13;
								//Close_Port(Printer_Table[Index].hUSB);	//If Printer port is open, close it.&#13;
							hUSB = Locate_Device(FALSE,Index);			//Pick current active Boca USB printer&#13;
							if (hUSB)&#13;
							{&#13;
								if (Printer_Table[Index].Serial_Number==P1)		//if this happens to be P1 save a copy of the pointer&#13;
								{&#13;
									P1_ptr = hUSB;&#13;
									Printer_Table[Index].hUSB = hUSB;&#13;
								}&#13;
								if (Printer_Table[Index].Serial_Number==P2)		//if this happens to be P2 save a copy of the pointer&#13;
								{&#13;
									P2_ptr = hUSB;&#13;
									Printer_Table[Index].hUSB = hUSB;&#13;
								}&#13;
							}&#13;
							hUSB = NULL;&#13;
						}&#13;
&#13;
						//call test print routines to exercise system&#13;
						hUSB = P1_ptr;					//Establish Printer "A" as the default&#13;
						dual_test_ticket();&#13;
&#13;
						for (i = 0; i &lt; USB_printer_count; i++)		//For all ports&#13;
							Close_USB(i);							//close it.&#13;
						hUSB = NULL;&#13;
&#13;
					}&#13;
				}&#13;
	return;&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: dual_test_ticket()&#13;
 * &#13;
 * Description&#13;
 * This rouinte will exercise both selected FGL printers P1 &amp; P2, by printing a text &#13;
 * file containing a series of FGL commands&#13;
 **************************************************************************************/&#13;
void dual_test_ticket()&#13;
{&#13;
	FILE *fp;&#13;
	long filesize;&#13;
	int i;&#13;
&#13;
	//open the file, read it and send it to the open USB port&#13;
&#13;
	Clear_Buffer();&#13;
	&#13;
	fp = fopen("fgl_config.txt","rb");&#13;
	if(fp == NULL)&#13;
		printf("\nUnable to find fgl_config.txt");&#13;
	else&#13;
	{&#13;
		filesize = filelength(fileno(fp));&#13;
		while(filesize &gt; 0)						//Read the whole file &#13;
		{		&#13;
			if(filesize &gt; USB_PACKET_SIZE)		//if the file is larger than the packet size&#13;
				i = USB_PACKET_SIZE;			//send it one packet at a time&#13;
			else								//if the file is smaller than one packet&#13;
				i = filesize;					//send just whats needed&#13;
&#13;
			fread(pBuffer, sizeof( char ), i, fp);	//read file data into BUFFER[]&#13;
			if (i &gt; 0)&#13;
			{&#13;
				dwSize = i;&#13;
				Send_Dual();					//if read successful then call special Send &#13;
			}&#13;
			filesize = filesize - i;			//decrement amount left to read and send&#13;
		}&#13;
&#13;
		fclose(fp);&#13;
	}&#13;
&#13;
	return;&#13;
}&#13;
&#13;
/**************************************************************************************&#13;
 * Routine Name: Send_Dual()&#13;
 * &#13;
 * Description&#13;
 * This routine monitors all outgoing traffic for the FGL commands &lt;P1&gt; and &lt;P2&gt;.  When&#13;
 * one of these commands is found the device pointer is changed back and forth.&#13;
 **************************************************************************************/&#13;
void Send_Dual()&#13;
{&#13;
	int i,size1,size2;&#13;
	bool split=false;&#13;
	USB_HANDLE hUSB_Change = NULL;&#13;
	PVOID pBuffer2;				// pointer to buffer&#13;
&#13;
	//Buffer contains outgoing data&#13;
	for (i = 0; i &lt; (int)dwSize; i++)						//search string for FGL &lt;P1&gt; &lt;P2&gt;&#13;
	{&#13;
		if(Buffer[i] == OPEN_DELIMETER)					//"&lt;" Found an FGL command&#13;
		{&#13;
			if(Buffer[i+1] == 80)						//"P" Found an FGL P command&#13;
			{&#13;
				if(Buffer[i+2] == 49)					//"1" Found an FGL P1 command &#13;
				{&#13;
					hUSB_Change = P1_ptr;&#13;
					if(i&gt;=0)&#13;
						size1=i;						//size from index 0 to i-1&#13;
					else&#13;
						size1=0;&#13;
					size2=dwSize-i;&#13;
					split = true;&#13;
				}&#13;
				else&#13;
				{&#13;
					if(Buffer[i+2] == 50)					//"2" Found an FGL P2 command &#13;
					{&#13;
						hUSB_Change = P2_ptr;&#13;
						if(i&gt;=0)&#13;
							size1=i;						//size from index 0 to i-1&#13;
						else&#13;
							size1=0;&#13;
						size2=dwSize-i;&#13;
						split = true;&#13;
					}&#13;
				}&#13;
			}&#13;
		}&#13;
	}&#13;
	&#13;
&#13;
	//When you find the &lt;P1&gt;'s and &lt;P2&gt;'s, they are typically embedded &#13;
	//inside a long string of data.  The data then needs to be split so that the first&#13;
	//part goes to the current printer and then the second part of the string can be &#13;
	//redirected to the other printer after the USB_Change takes place.&#13;
	if (split)&#13;
	{&#13;
		if (size1&gt;0) error_code = Write_Data(hUSB, pBuffer, size1, WRITE_PIPE);	//send it the the USB port&#13;
		hUSB = hUSB_Change;&#13;
		pBuffer2=&amp;Buffer[size1];&#13;
		if (size2&gt;0) error_code = Write_Data(hUSB, pBuffer2, size2, WRITE_PIPE); //send it the the USB port&#13;
	}&#13;
	else&#13;
		error_code = Write_Data(hUSB, pBuffer, dwSize, WRITE_PIPE);	//send it the the USB port&#13;
&#13;
	return;&#13;
}</description><ttl>30</ttl><generator>WEBDEV</generator><language>fr_FR</language><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp</link><title>[WD17] Conversion du Code C++ en Wlangage</title><managingEditor>moderateur@pcsoft.fr (Le modérateur)</managingEditor><webMaster>webmaster@pcsoft.fr (Le Webmaster)</webMaster><item><author>igc_i</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153529/read.awp</comments><pubDate>2 Oct 2012 12:04:23 Z</pubDate><description>C Tout cela que je cherche les gars.&#13;
Je vais maintenant molo molo. C complexe</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153529/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153529/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item><item><author>frederic.boyer</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153522/read.awp</comments><pubDate>2 Oct 2012 10:51:43 Z</pubDate><description>Daniel a écrit dans le message de news &lt;5069a2d3$1@news.pcsoft.fr&gt; :&#13;
&gt; Windev ne sait pas interpréter du C ou C++ mais est capa…</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153522/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153522/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item><item><author>igc_i</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153516/read.awp</comments><pubDate>2 Oct 2012 00:44:24 Z</pubDate><description>Je retourne aux bord voir</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153516/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153516/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item><item><author>nospam</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153507/read.awp</comments><pubDate>1 Oct 2012 18:14:11 Z</pubDate><description>Bonjour,&#13;
Le 01/10/2012 13:06, FredB a écrit :&#13;
&gt; Ralph a écrit dans le message de news &lt;4cf085189df3948ded02ef981764fbfb@news.p…</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153507/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153507/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item><item><author>frederic.boyer</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153493/read.awp</comments><pubDate>1 Oct 2012 13:55:35 Z</pubDate><description>Ralph a écrit dans le message de news &lt;4cf085189df3948ded02ef981764fbfb@news.pcsoft&gt; :&#13;
&gt; C compliqué tout ça.&#13;
&#13;
Je dirais même…</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153493/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153493/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item><item><author>igc_i</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153485/read.awp</comments><pubDate>1 Oct 2012 11:56:33 Z</pubDate><description>C compliqué tout ça.</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153485/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153485/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item><item><author>mactoutim</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153442/read.awp</comments><pubDate>28 Sep 2012 19:05:30 Z</pubDate><description>il est malin, moi je vais déposer des CDC sous forme de jeux gratuits ;-)&#13;
&#13;
&#13;
--&#13;
Mac Toutim</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153442/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153442/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item><item><author>=JBO=</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153437/read.awp</comments><pubDate>28 Sep 2012 18:06:09 Z</pubDate><description>Bonjour Ralph,&#13;
&#13;
Avant de commencer la traduction en WLangage, voici la traduction en euros:&#13;
&#13;
300 euros&#13;
&#13;
&#13;
PS. désolé, la t…</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153437/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153437/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item><item><author>igc_i</author><category>pcsoft.fr.windev</category><comments>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153436/read.awp</comments><pubDate>28 Sep 2012 17:46:18 Z</pubDate><description>Veuillez trouver ci-dessous le fichier entête cpp. WDAPI ne sert à rien dans ce cas.&#13;
// The following ifdef block is the standa…</description><guid isPermaLink="true">https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153436/read.awp</guid><link>https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangagefichier-153436/read.awp</link><source url="https://forum.pcsoft.fr/fr-FR/pcsoft.fr.windev/153431-wd17-conversion-code-wlangage/read.awp">[WD17] Conversion du Code C++ en Wlangage</source><title>Re: [WD17] Conversion du Code C++ en Wlangage(fichier .h)</title></item></channel></rss>
