/*
 * File:		  demo.cpp
 * Purpose:	  Serial port class demo program
 * Author:	  George Tasker
 * Created:	  30-05-1997
 */

/*
// SYNOPSIS START



	Update History:
	--------------
	??-06-97

		Initial release

// SYNOPSIS STOP
*/

/* static const char sccsid[] = "%W% %G%"; */

#ifdef __GNUG__
#pragma implementation
#pragma interface
#endif


// For compilers that support precompilation, includes "wx.h".
#include "wx_prec.h"

#ifdef __BORLANDC__
#  pragma hdrstop
#endif

#ifndef WX_PRECOMP
#  include "wx.h"
#endif

#include "wxstring.h"
#include "wxserial.h"

#include "demo.h"

wxString moveTelegram = "01B001020201 110+000001   00000TESTPART58";

int	OffsetY	=  75;
int	panelW	= 450;
int	panelH	= 355;
int	debugH	= 150;

// A macro needed for some compilers (AIX) that need 'main' to be defined
// in the application itself.
IMPLEMENT_WXWIN_MAIN

// This statement initializes the whole application and calls OnInit
myApp			 DemoApp;
wxMenuBar	*Main_MenuBar;


wxFont	   *itemFont;
wxFont		*itemBoldFont;
wxFont		*textWindowFont;

wxMenu *FileMenu()
{
	wxMenu *file_menu = new wxMenu;

	file_menu->Append(FILE_EXIT, "e&Xit","Exit from program");

	return file_menu;

}  // FileMenu


wxMenu *PortMenu()
{
	wxMenu *port_menu = new wxMenu;

	port_menu->Append(PORT_ADD,	"&Add",	"Define a new port and its settings");
	port_menu->Append(PORT_EDIT,	"&Edit",	"Modify port settings");
	port_menu->Append(PORT_OPEN,	"&Open",	"Opens the currently selected port");
	port_menu->Append(PORT_CLOSE,	"&Close","Close the currently selected port");

	return port_menu;
}

wxMenu *ActionMenu()
{
	wxMenu *action_menu = new wxMenu;

	action_menu->Append(ACTION_SEND,	"&Send",			"Writes data to an open port");
	action_menu->Append(ACTION_READ,	"&Receive",		"Reads any data waiting in buffer");
	action_menu->AppendSeparator();
	action_menu->Append(ACTION_FLUSH,	"&Flush",		"Clears both the send and receive buffers");

	return action_menu;
}

wxMenu *HelpMenu()
{
	wxMenu *help_menu = new wxMenu;

	wxString s;
	s.sprintf("About %s ",PROGRAM_TITLE);
	help_menu->Append(HELP_ABOUT,	"&About",s.GetData());

	return help_menu;

}  // HelpMenu




wxMenuBar *MainMenu(wxMenuBar *t)
{
	//
	// Build the menu structures to be used if there is an
	// unsuccessful login attempt, or no login yet
	//
	t = new wxMenuBar;
	t->Append(FileMenu(),"&File");
	t->Append(PortMenu(),"&Ports");
	t->Append(ActionMenu(),"&Action");
	t->Append(HelpMenu(),"&Help");

	return t;

}  // MainMenu



void myApp::DebugMsg(char *msg,char *lf)
{
	if (DebugWindow)
		*(DebugWindow) << msg << lf;
};  // myApp::DebugMsg



// `Main program' equivalent, creating windows and returning main app frame
wxFrame *myApp::OnInit(void)
{
	wxBeginBusyCursor();

	// Create the main frame window
	wxString S = "Serial port test program";

	Frame = new myFrame(NULL, S.GetData(), 5, 5, panelW, panelH+45+OffsetY+debugH);

	if (!Frame) return 0;

/*
	// Give frame an icon
#ifdef wx_msw
	Frame->SetIcon(new wxIcon("aiai_icn"));
#endif
#ifdef wx_x
	Frame->SetIcon(new wxIcon("aiai.xbm"));
#endif
*/
	// Make a menubar
	Frame->SetMenuBar(MainMenu(Main_MenuBar));

	Frame->BuildPanel();
	Frame->CreateStatusLine(1);
	Frame->SetStatusText("", 0);

	// Show the frame
	Frame->Show(TRUE);
//	Frame->LoadAccelerators("menus_accel") ;	

	Frame->SaveBtn->SetDefault();
	Frame->SaveBtn->Show(FALSE);
	wxEndBusyCursor();

	// Return the main frame window
	return Frame;
	
} // myApp::OnInit


// My frame constructor
myFrame::myFrame(wxFrame *Frame, char *title, int x, int y, int w, int h):
	wxFrame(Frame, title, x, y, w, h)
{
	exiting = FALSE;
}  // myFrame::constructor


Bool myFrame::OnClose(void)
{
	// Close any open serial ports
	for (int i;i<MAX_SERIAL_PORTS;i++)
	{
		if (SerialPort[i])
		{
			delete SerialPort[i];
		}
	}

	// Hide the frame and return
	Show(FALSE);
	return (TRUE);
	
}  // myFrame::OnClose	


// Intercept menu commands
void myFrame::OnMenuCommand(int id)
{
	switch (id)
	{
		case FILE_EXIT:
		{
			Close();
			break;
		}

		case PORT_ADD:
		{
			AddingPort = TRUE;

			AddBtn->Show(FALSE);
			SaveBtn->Show(TRUE);

			PortChoice->Enable(FALSE);
			PortChoice->Show(FALSE);
			PortNameTxt->Enable(TRUE);
			PortNameTxt->Show(TRUE);
			PortNameTxt->SetFocus();
			StatusMsg->SetLabel("Not ready");

			break;
		}

		case PORT_EDIT:
		{
		}

		case PORT_OPEN:
		{
			if (SerialPort[SelectedPort]->Open(wx9600,wxNONE,8,2))
			{
				DemoApp.DebugMsg("Serial port has been opened\n\n");
				ShowPortStatus();
			}
			SerialPort[SelectedPort]->Enable();
			break;
		}


		case PORT_CLOSE:
		{
			if (SerialPort[SelectedPort])
			{
				if (SerialPort[SelectedPort]->Close())
					DemoApp.DebugMsg("Serial port has been closed\n\n");
				ShowPortStatus();
			}
			break;
		}


		case ACTION_SEND:
		{
			SendMessage();
			break;
		}


		case ACTION_READ:
		{
			ReceiveResponse();
			break;
		}


		case ACTION_FLUSH:
		{
			wxMessageBox("Not implemented yet","DEBUG");
			break;
		}


		case HELP_ABOUT:
		{
			wxString aboutMsg;
			aboutMsg = PROGRAM_TITLE;
			aboutMsg += "\nWritten by: George Tasker\n\n\n ";
			aboutMsg += PROGRAM_VERSION;
			wxMessageBox(aboutMsg.GetData(),"Help|About...",wxOK|wxCENTRE|wxICON_INFORMATION);
			break;
		}
	}
}  // myFrame::OnMenuCommand



void myFrame::OnSize(int w, int h)
{
	if (DemoApp.Frame->Panel)
		DemoApp.Frame->Panel->OnSize(w,h-70);

	if (DemoApp.DebugWindow)
  		DemoApp.DebugWindow->SetSize(-1,-1,panelW-30,debugH,wxSIZE_USE_EXISTING);

	wxFrame::OnSize(w,h);
}  // myFrame::OnSize



void myFrame::OnCommand(wxWindow& win, wxCommandEvent& event)
{

	wxString widgetName;
	
	widgetName = win.GetName();

	if (AddingPort)
	{
		if (widgetName == "SaveBtn")
		{
			SaveBtn->Show(FALSE);
			AddBtn->Show(TRUE);

			wxString name;
			name = PortNameTxt->GetValue();

			if (name != "")
			{
				SerialPort[DefinedPorts] = new wxSerial(name.GetData());

				if (!SerialPort[DefinedPorts])
				{
					DemoApp.DebugMsg("Unable to create a new wxSerial port instance\n\n");
				}
				else
				{
					PortNameTxt->Enable(FALSE);
					PortNameTxt->Show(FALSE);
					SelectedPort = DefinedPorts;
					DefinedPorts++;
					PortChoice->Enable(TRUE);
					PortChoice->Show(TRUE);
					PortChoice->Append(PortNameTxt->GetValue());
					PortChoice->SetSelection(SelectedPort);

					if (SerialPort[SelectedPort]->Open(wx9600,wxNONE,8,2))
					{
						ShowPortStatus();
						ShowPortSettings();
						SerialPort[SelectedPort]->ToggleRTS(TRUE);
					}
					else wxMessageBox("Unable to open new port","DEBUG");
					AddingPort = FALSE;
				}
			}
			else 
				AddingPort = FALSE;

			exiting = FALSE;
			return;
		}
		else
		{
			if (!exiting)
			{
				// when adding port, only the "Save" button can be pressed
				if (event.eventType == wxEVENT_TYPE_KILL_FOCUS)
					exiting = TRUE;
			}
			else
			{
 				wxBell();
				PortNameTxt->SetFocus();
				exiting = FALSE;
			}
			return;
		}
	}
	else
	{
		if (widgetName == "AddBtn")
		{
			AddingPort = TRUE;

			AddBtn->Show(FALSE);
			SaveBtn->Show(TRUE);

			PortChoice->Enable(FALSE);
			PortChoice->Show(FALSE);
			PortNameTxt->Enable(TRUE);
			PortNameTxt->Show(TRUE);
			PortNameTxt->SetFocus();
			StatusMsg->SetLabel("Not ready");
			return;
		}

		if (widgetName == "EditBtn")
		{
			return;
		}
	}


	if (widgetName == "PortChoice")
	{
		SelectedPort = PortChoice->GetSelection();
		ShowPortStatus();
		ShowPortSettings();
		return;
	}

	if (widgetName == "SendBtn")
	{
		SendMessage();
		return;
	}

	if (widgetName == "ReceiveBtn")
	{
		ReceiveResponse();
		return;
	}
}  // myFrame::OnCommand



/*
 *	=======================================================================
 *
 *								Communication function calls
 *
 * =======================================================================
 */


Bool myFrame::SendMessage()
{
	wxString message;

	// Make sure there is a valid port selected, and that it has been opened
	// for read/write usage
	if ((SelectedPort != -1) && (SerialPort[SelectedPort]->IsOpen()))
	{
		int start,stop;
		wxString s;

		// Determine if framing characters are specified
		start = stop = 0;
		s = FramingStartTxt->GetValue();
		if (s.IsNumber())
		{
			start = atoi(s.GetData());
			s = FramingStopTxt->GetValue();
			if (s.IsNumber())
			{
				stop = atoi(s.GetData());
			}
			else wxMessageBox("Invalid framing stop character.  Must be 0 - 255.\n\nNot using any framing characters","Invalid input");
		}
		else wxMessageBox("Invalid framing start character.  Must be 0 - 255.\n\nNot using any framing characters","Invalid input");

		// Build the message to be sent, either with or without framing chars
		if ((start != 0) && (stop != 0))
			message.sprintf("%c%s%c",start,SendTxt->GetValue(),stop);
		else
			message.sprintf("%s",SendTxt->GetValue());
/*
SerialPort[SelectedPort]->RTS(TRUE);
Sleep(10);
*/
		// Write the message to the selected serial port
		if (SerialPort[SelectedPort]->Write(message.Length(),message.GetData()))
		{
/*			
			SerialPort[SelectedPort]->RTS(FALSE);
*/
			// Clear the received text so it is not misleading the viewer
			// in to thinking this is the response from the written message
			ReceiveTxt->SetValue("");
			DemoApp.DebugMsg("Message has been sent\n\n");
			return TRUE;
		}
		return FALSE;
	}
	else wxMessageBox ("Port has either not been defined or has not been opened.\n\nCannot send message till this has been done.","DEBUG");

	return FALSE;

}  // myFrame::SendMessage()



Bool myFrame::ReceiveResponse()
{
	// Make sure there is a valid port selected, and that it has been opened
	// for read/write usage
	if ((SelectedPort != -1) && (SerialPort[SelectedPort]->IsOpen()))
	{
		int Terminator, MaxLen;

		// Clear any garbage out of the buffer
		char response[200];
		for (int j=0;j<200;j++) response[j] = 0;

		// Determine the terminator character and/or maximum length of the response message
		wxString s;
		s = TerminatorTxt->GetValue();
		if (s.IsNumber())
		{
			Terminator = atoi(s.GetData());
			if ((Terminator < -1) || (Terminator > 255))
			{
				wxMessageBox("Invalid terminator specified.  Must be -1(no terminator) through 255.\n\nNot using a terminator to determine end of receive data","Invalid input");
				MaxLen = -1;
			}
			s = MaxLenTxt->GetValue();
			if (s.IsNumber())
			{
				MaxLen = atoi(s.GetData());
				if ((MaxLen < -1) || (MaxLen > 255))
				{
					wxMessageBox("Invalid maximum length for received data specified.  Must be 1 - 255.\n\nUsing maximum length of 255","Invalid input");
					MaxLen = -1;
				}
			}
			else
			{
				wxMessageBox("Invalid maximum length for received data specified.  Must be 1 - 255.\n\nUsing maximum length of 255","Invalid input");
				MaxLen = -1;
			}
		}
		else
		{
			wxMessageBox("Invalid terminator specified.  Must be -1(no terminator) through 255.\n\nNot using a terminator to determine end of receive data","Invalid input");
			MaxLen = 255;
		}

		// Read the response from the selected serial port
		if (SerialPort[SelectedPort]->Read(response,MaxLen))
		{
			ReceiveTxt->SetValue(response);
			ShowResponseInASCII(response);
			return TRUE;
		}
		else
		{
			if (strlen(response) == 0)
				DemoApp.DebugMsg("No response detected\n");
			else 
			{
				wxString msg;
				DemoApp.DebugMsg("Timeout exceeded while reading response\n");
				msg.sprintf("%d characters of the expected %d were read\n\n",strlen(response),MaxLen);
				DemoApp.DebugMsg(msg.GetData());
			}
			return FALSE;
		}
	}
	else wxMessageBox ("Port has not been assigned/opened.\n\nCannot read telegram till this has been done.","DEBUG");

	return FALSE;

} // myFrame::ReceiveResponse()


/*
 *	=======================================================================
 *
 *						User interface functions for the panel
 *
 * =======================================================================
 */


void myFrame::BuildPanel()
{
	// Make a panel
	Panel = new wxPanel(this, 0, 0, panelW, panelH);
	Panel->SetLabelPosition(wxVERTICAL);

	itemFont			= new wxFont(12, wxSWISS, wxNORMAL, wxNORMAL);
	itemBoldFont	= new wxFont(12, wxSWISS, wxNORMAL,	wxBOLD);
	textWindowFont = new wxFont(12, wxROMAN, wxNORMAL, wxNORMAL);

	Panel->SetLabelPosition(wxVERTICAL);

	// Create some panel items
	Panel->SetLabelFont(itemFont);
	Panel->SetButtonFont(itemFont);
	SendGrp				= new wxGroupBox	(Panel, "Send parameters", 5, 35+OffsetY, 430, 90, 0, "SendGrp");
	SendTxt				= new wxText		(Panel, (wxFunction)NULL, "", "", 95, 58+OffsetY, 325, 25, 0, "SendTxt");
	Panel->SetLabelPosition(wxHORIZONTAL);
	Panel->SetButtonFont(itemBoldFont);
	FramingStartTxt	= new wxText		(Panel, (wxFunction)NULL, "Framing start byte", "2", 108, 93+OffsetY, 150, 23, 0, "FramingStartTxt");
	FramingStopTxt		= new wxText		(Panel, (wxFunction)NULL, "Framing stop byte", "3", 270, 93+OffsetY, 149, 23, 0, "FramingStopTxt");
	Panel->SetButtonFont(itemBoldFont);
	SendBtn				= new wxButton		(Panel, (wxFunction)NULL, "&Send",30,60+OffsetY,60,23,0,"SendBtn");

	Panel->SetButtonFont(itemFont);
	ReceiveGrp			= new wxGroupBox	(Panel, "Receive parameters", 5, 150+OffsetY, 430, 90, 0, "ReceiveGrp");
	Panel->SetLabelPosition(wxVERTICAL);
	ReceiveTxt			= new wxText		(Panel, (wxFunction)NULL, "", "", 95, 173+OffsetY, 325, 25, 0, "ReceiveTxt");
	Panel->SetLabelPosition(wxHORIZONTAL);
	TerminatorTxt		= new wxText		(Panel, (wxFunction)NULL, "Terminator:", "", 137, 205+OffsetY, 120, 23, 0, "TerminatorTxt");
	MaxLenTxt			= new wxText		(Panel, (wxFunction)NULL, "Maximum length:", "255", 266, 205+OffsetY, 155, 23, 0, "MaxLenTxt");
	Panel->SetButtonFont(itemBoldFont);
	ReceiveBtn			= new wxButton		(Panel, (wxFunction)NULL, "&Receive",30,175+OffsetY,60,23,0,"ReceiveBtn");

	Panel->SetButtonFont(itemBoldFont);
	StatusMsg			= new wxMessage	(Panel,"",335,23,100,23,0,"StatusMsg");
	Panel->SetLabelPosition(wxVERTICAL);
	PortNameTxt			= new wxText		(Panel,(wxFunction)NULL,"Port name","",115,3,215,40,0,"PortNameTxt");
	PortChoice			= new wxChoice		(Panel,(wxFunction)NULL,"Defined ports",115,1,215,43,0,0,0,"PortChoice");
	AddBtn				= new wxButton		(Panel, (wxFunction)NULL, "&Add",30,20,60,23,0,"AddBtn");
	SaveBtn				= new wxButton		(Panel, (wxFunction)NULL, "&Save",30,19,60,23,0,"SaveBtn");
	EditBtn				= new wxButton		(Panel, (wxFunction)NULL, "&Edit",30,69,60,23,0,"EditBtn");
//	SettingsMsg			= new wxMessage	(Panel,"",85,45,200,23,0,"SettingsMsg");

	BaudMsg				= new wxMessage	(Panel,"Baud Rate",115,52,75,25,0,"BaudMsg");
	ParityMsg			= new wxMessage	(Panel,"Parity",200,52,100,25,0,"ParityMsg");
	WordLenMsg			= new wxMessage	(Panel,"Word",310,52,50,25,0,"WordLenMsg");
	StopBitsMsg			= new wxMessage	(Panel,"StopBits",370,52,125,25,0,"StopBitsMsg");

	BaudTxt				= new wxText		(Panel,(wxFunction)NULL,"","",115,67,75,25,0,"BaudTxt");
	ParityTxt			= new wxText		(Panel,(wxFunction)NULL,"","",200,67,100,25,0,"ParityTxt");
	WordLenTxt			= new wxText		(Panel,(wxFunction)NULL,"","",310,67,50,25,0,"WordLenTxt");
	StopBitsTxt			= new wxText		(Panel,(wxFunction)NULL,"","",370,67,50,25,0,"StopBitsTxt");

/*
	BaudMsg				= new wxMessage	(Panel,"Baud Rate",85,52,75,25,0,"BaudMsg");
	ParityMsg			= new wxMessage	(Panel,"Parity",170,52,100,25,0,"ParityMsg");
	WordLenMsg			= new wxMessage	(Panel,"Word",280,52,50,25,0,"WordLenMsg");
	StopBitsMsg			= new wxMessage	(Panel,"StopBits",340,52,125,25,0,"StopBitsMsg");

	BaudTxt				= new wxText		(Panel,(wxFunction)NULL,"","",85,67,75,25,0,"BaudTxt");
	ParityTxt			= new wxText		(Panel,(wxFunction)NULL,"","",170,67,100,25,0,"ParityTxt");
	WordLenTxt			= new wxText		(Panel,(wxFunction)NULL,"","",280,67,50,25,0,"WordLenTxt");
	StopBitsTxt			= new wxText		(Panel,(wxFunction)NULL,"","",340,67,50,25,0,"StopBitsTxt");
*/
	// Set some initial values
	SendTxt->SetValue(moveTelegram.GetData());
	FramingStartTxt->SetValue("2");
	FramingStopTxt->SetValue("3");
	TerminatorTxt->SetValue("-1");
	MaxLenTxt->SetValue("255");

	ShowPortStatus(SelectedPort);

	ReceiveTxt->SetEditable(FALSE);  // this is a display field only

	// This widget is only enabled when adding/editing a port defintion
	PortNameTxt->Enable(FALSE);
	PortNameTxt->Show(FALSE);

	BaudTxt->Enable(FALSE);
	ParityTxt->Enable(FALSE);
	WordLenTxt->Enable(FALSE);
	StopBitsTxt->Enable(FALSE);

	AddingPort = FALSE;

	wxMessage *DebugMsg = new wxMessage(Panel, "Debugging window for displaying output text", 7, 280+OffsetY);
  	DemoApp.DebugWindow = new wxTextWindow(Panel, 7, 300+OffsetY,panelW-30,debugH,wxNATIVE_IMPL);
  	DemoApp.DebugWindow->SetEditable(TRUE);
}  // myFrame::BuildPanel()



//
// Displays the currect status of port 'p' in the window.  A result
// of 'READY' means the port is able to be read from and written to.
// A value of 'Not ready' means that either the port is undefined
// or not open
//
void myFrame::ShowPortStatus(int p)
{
	if (SerialPort[p] && SerialPort[p]->IsOpen())
		StatusMsg->SetLabel("READY");
	else StatusMsg->SetLabel("Not ready");
}  // myFrame::ShowPortStatus()



//
// Displays the current Baud, Parity, WordLength and StopBit settings
// for port 'p'
//
void myFrame::ShowPortSettings(int p)
{
	if (SerialPort[p]->IsOpen())
	{
		CommSettings cs;
		SerialPort[p]->GetSettings(&cs);

		wxString baudStr;
		switch (cs.baudRate)
		{
			case wx150:
				{
					baudStr = "150";
					break;
				}
			case wx300:
				{
					baudStr = "300";
					break;
				}
			case wx600:
				{
					baudStr = "600";
					break;
				}
			case wx1200:
				{
					baudStr = "1200";
					break;
				}
			case wx2400:
				{
					baudStr = "2400";
					break;
				}
			case wx4800:
				{
					baudStr = "4800";
					break;
				}
			case wx9600:
				{
					baudStr = "9600";
					break;
				}
		}

		wxString parityStr;
		switch (cs.parity)
		{
			case wxNONE:
				{
					parityStr = "None";
					break;
				}
			case wxODD:
				{
					parityStr = "Odd";
					break;
				}
			case wxEVEN:
				{
					parityStr = "Even";
					break;
				}
			case wxMARK:
				{
					parityStr = "Mark";
					break;
				}
			case wxSPACE:
				{
					parityStr = "Space";
					break;
				}
		}

		wxString wordLenStr;
		wordLenStr.sprintf("%d",cs.wordLen);

		// Note: Win32 allows three different stop bit values - ONESTOPBIT (0),
		//			ONE5STOPBITS(1), and TWOSTOPBITS(2) - where ONE5STOPBITS is 1.5
		//			stop bits (gotta love MicroSloth).  Don't get confused when using
		//       one stop bit, and the DCB shows it as 0 stop bits.
		wxString sbStr;
		if (cs.stopBits == ONESTOPBIT)
			sbStr = "1";
		else 	if (cs.stopBits == ONE5STOPBITS)
			sbStr = "1.5";
		else if (cs.stopBits == TWOSTOPBITS)
			sbStr = "2";

		BaudTxt->SetValue(baudStr.GetData());
		ParityTxt->SetValue(parityStr.GetData());
		WordLenTxt->SetValue(wordLenStr.GetData());
		StopBitsTxt->SetValue(sbStr.GetData());
	}
	else
	{
		BaudTxt->SetValue("");
		ParityTxt->SetValue("");
		WordLenTxt->SetValue("");
		StopBitsTxt->SetValue("");
	}
/*
	if (SerialPort[p]->IsOpen())
	{
		CommSettings cs;
		SerialPort[p]->GetSettings(&cs);

		// Note: Win32 allows three different stop bit values - ONESTOPBIT (0),
		//			ONE5STOPBITS(1), and TWOSTOPBITS(2) - where ONE5STOPBITS is 1.5
		//			stop bits (gotta love MicroSloth).  Don't get confused when using
		//       one stop bit, and the DCB shows it as 0 stop bits.
		wxString sb;
		if (cs.stopBits == ONESTOPBIT)
			sb = "1";
		else 	if (cs.stopBits == ONE5STOPBITS)
			sb = "1.5";
		else if (cs.stopBits == TWOSTOPBITS)
			sb = "2";

		wxString parity;
		switch (cs.parity)
		{
			case wxNONE:
				{
					parity = "None";
					break;
				}
			case wxODD:
				{
					parity = "Odd";
					break;
				}
			case wxEVEN:
				{
					parity = "Even";
					break;
				}
			case wxMARK:
				{
					parity = "Mark";
					break;
				}
			case wxSPACE:
				{
					parity = "Space";
					break;
				}
		}

		wxString msg;
		msg.sprintf("%d %s %d %s",cs.baudRate,parity.GetData(),cs.wordLen,sb.GetData());
		SettingsMsg->SetLabel(msg.GetData());
	}
	else
		SettingsMsg->SetLabel("");
*/
}  // myFrame::ShowPortSettings()



// Show ASCII representation of 'response' in debug window so that if 
// there are unprintable chars in 'response', we can see them
void myFrame::ShowResponseInASCII(char *response)
{
	DemoApp.DebugMsg("Response has been received : ");
	wxString rxStr;
	for (unsigned int i=0;i<strlen(response);i++)
	{
		rxStr.sprintf("%d ",(int)response[i]);
		DemoApp.DebugMsg(rxStr.GetData());
	}
	DemoApp.DebugMsg("\n\n");
}  // myFrame::ShowResponseInASCII()

