Ejemplo n.º 1
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // m e t r i c s S a v e                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Save the current settings.                                         //
        //                                                                    //
        //--------------------------------------------------------------------//

        public void metricsSave()
        {
            TargetCore.metricsSaveNetPrinter(_printerAddress,
                                             _printerPort,
                                             _timeoutSend,
                                             _timeoutReceive);
        }
Ejemplo n.º 2
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // b t n S a v e R e p o r t _ C l i c k                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Called when the 'Save Report' button is clicked.                   //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void btnSaveReport_Click(object sender, RoutedEventArgs e)
        {
            Boolean flagOffsetHex,
                    flagOptRptWrap = false;

            ReportCore.eRptFileFmt  rptFileFmt  = ReportCore.eRptFileFmt.NA;
            ReportCore.eRptChkMarks rptChkMarks = ReportCore.eRptChkMarks.NA;

            if (_options.IndxGenOffsetFormat ==
                PrnParseConstants.eOptOffsetFormats.Decimal)
            {
                flagOffsetHex = false;
            }
            else
            {
                flagOffsetHex = true;
            }

            TargetCore.metricsReturnFileRpt(ToolCommonData.eToolIds.PrnAnalyse,
                                            ref rptFileFmt,
                                            ref rptChkMarks,
                                            ref flagOptRptWrap);

            if (tabCtrl.SelectedItem == tabStatistics)
            {
                ToolPrnAnalyseReport.generate(eInfoType.Statistics,
                                              rptFileFmt,
                                              _tableStatistics,
                                              _prnFilename,
                                              _fileSize,
                                              flagOffsetHex,
                                              _options);
            }
            else if (tabCtrl.SelectedItem == tabContent)
            {
                ToolPrnAnalyseReport.generate(eInfoType.Content,
                                              rptFileFmt,
                                              _tableContent,
                                              _prnFilename,
                                              _fileSize,
                                              flagOffsetHex,
                                              _options);
            }
            else
            {
                ToolPrnAnalyseReport.generate(eInfoType.Analysis,
                                              rptFileFmt,
                                              _tableAnalysis,
                                              _prnFilename,
                                              _fileSize,
                                              flagOffsetHex,
                                              _options);
            }
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // s e n d R e q u e s t                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Send previously generated request data to target.                  //
        //                                                                    //
        //--------------------------------------------------------------------//

        public static void sendRequest(PJLCommands.eCmdIndex cmdIndx)
        {
            PJLCommands.eRequestType reqType =
                PJLCommands.getType(cmdIndx);

            if ((reqType == PJLCommands.eRequestType.FSDirList) ||
                (reqType == PJLCommands.eRequestType.FSQuery))
            {
                //------------------------------------------------------------//
                //                                                            //
                // PJL FileSystem query; request types:                       //
                //  -   FSDIRLIST                                             //
                //  -   FSQUERY                                               //
                // Response from printer expected.                            //
                //                                                            //
                //------------------------------------------------------------//

                TargetCore.requestStreamWrite(true);
            }
            else if (reqType == PJLCommands.eRequestType.FSUpload)
            {
                //------------------------------------------------------------//
                //                                                            //
                // PJL FileSystem upload to host workstation; request types:  //
                //  -   FSUPLOAD                                              //
                // Response from printer expected - write this direct to the  //
                // target file (it could be (much) larger than standard reply //
                // buffer.                                                    //
                //                                                            //
                //------------------------------------------------------------//

                TargetCore.requestStreamWrite(true);
            }
            else
            {
                //------------------------------------------------------------//
                //                                                            //
                // PJL FileSystem action; request types:                      //
                //  -   FSAPPEND                                              //
                //  -   FSDELETE                                              //
                //  -   FSDOWNLOAD                                            //
                //  -   FSINIT                                                //
                //  -   FSMDKIR                                               //
                // Response from printer not expected.                        //
                //                                                            //
                //------------------------------------------------------------//

                TargetCore.requestStreamWrite(false);
            }
        }
Ejemplo n.º 4
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // b t n G e n e r a t e _ C l i c k                                  //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Called when the 'Generate' button is clicked.                      //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void btnGenerate_Click(object sender, RoutedEventArgs e)
        {
            BinaryWriter binWriter = null;

            TargetCore.requestStreamOpen(
                ref binWriter,
                ToolCommonData.eToolIds.PrnPrint,
                ToolCommonData.eToolSubIds.None,
                ToolCommonData.ePrintLang.Unknown);

            copyPrnFile(_prnFilename, binWriter);

            TargetCore.requestStreamWrite(false);
        }
Ejemplo n.º 5
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // i n i t i a l i s e                                                //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Initialise 'target' data.                                          //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void initialise()
        {
            TargetCore.metricsLoadNetPrinter(ref _printerAddress,
                                             ref _printerPort,
                                             ref _timeoutSend,
                                             ref _timeoutReceive);

            txtPrinterAddress.Text = _printerAddress;
            txtPrinterPort.Text    = _printerPort.ToString();

            txtTimeoutSend.Text    = _timeoutSend.ToString();
            txtTimeoutReceive.Text = _timeoutReceive.ToString();

            //----------------------------------------------------------------//
            //                                                                //
            // Set the (hidden) slider object to the passed-in scale value.   //
            // The slider is used as the source binding for a scale           //
            // transform in the (child) Options dialogue window, so that all  //
            // windows use the same scaling mechanism as the main window.     //
            //                                                                //
            // NOTE: it would be better to bind the transform directly to the //
            //       scale value (set and stored in the Main window), but (so //
            //       far) I've failed to find a way to bind directly to a     //
            //       class object Property value.                             //
            //                                                                //
            //----------------------------------------------------------------//

            Double windowScale = MainFormData.WindowScale;

            zoomSlider.Value = windowScale;

            //----------------------------------------------------------------//
            //                                                                //
            // Setting sizes to the resizeable DockPanel element doesn't work!//
            //                                                                //
            //----------------------------------------------------------------//

            this.Height = 280 * windowScale;
            this.Width  = 440 * windowScale;

            // Double h = resizeable.Height;
            // Double w = resizeable.Width;

            // this.Height = h;
            // this.Width = w;
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // b t n S a v e R e p o r t _ C l i c k                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Called when the 'Save report' button is clicked.                   //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void btnSaveReport_Click(object sender, RoutedEventArgs e)
        {
            Boolean flagOffsetHex,
                    flagOptRptWrap = false;

            ReportCore.eRptFileFmt  rptFileFmt  = ReportCore.eRptFileFmt.NA;
            ReportCore.eRptChkMarks rptChkMarks = ReportCore.eRptChkMarks.NA;

            if (_options.IndxGenOffsetFormat ==
                PrnParseConstants.eOptOffsetFormats.Decimal)
            {
                flagOffsetHex = false;
            }
            else
            {
                flagOffsetHex = true;
            }

            TargetCore.metricsReturnFileRpt(ToolCommonData.eToolIds.MakeOverlay,
                                            ref rptFileFmt,
                                            ref rptChkMarks,
                                            ref flagOptRptWrap);

            if (_crntPDL == ToolCommonData.ePrintLang.PCL)
            {
                ToolMakeOverlayReport.generate(rptFileFmt,
                                               _tableProgress,
                                               _prnFilename,
                                               _ovlFilenamePCL,
                                               flagOffsetHex,
                                               _options);
            }
            else
            {
                ToolMakeOverlayReport.generate(rptFileFmt,
                                               _tableProgress,
                                               _prnFilename,
                                               _ovlFilenamePCLXL,
                                               flagOffsetHex,
                                               _options);
            }

            btnSaveReport.Visibility = Visibility.Visible;
        }
Ejemplo n.º 7
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // r e s e t T a r g e t                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Reset the text on the 'Generate' button.                           //
        //                                                                    //
        //--------------------------------------------------------------------//

        public void resetTarget()
        {
            TargetCore.eTarget targetType = TargetCore.getType();

            if (targetType == TargetCore.eTarget.File)
            {
                btnGenerate.Content = "Copy PRN file contents to file";
            }
            else if (targetType == TargetCore.eTarget.NetPrinter)
            {
                String netPrnAddress = "";
                Int32  netPrnPort    = 0;

                Int32 netTimeoutSend    = 0;
                Int32 netTimeoutReceive = 0;

                TargetCore.metricsLoadNetPrinter(ref netPrnAddress,
                                                 ref netPrnPort,
                                                 ref netTimeoutSend,
                                                 ref netTimeoutReceive);

                btnGenerate.Content = "Send PRN file contents to " +
                                      "\r\n" +
                                      netPrnAddress + " : " +
                                      netPrnPort.ToString();
            }
            else if (targetType == TargetCore.eTarget.WinPrinter)
            {
                String winPrintername = "";

                TargetCore.metricsLoadWinPrinter(ref winPrintername);

                btnGenerate.Content = "Send PRN file contents to printer " +
                                      "\r\n" +
                                      winPrintername;
            }
        }
Ejemplo n.º 8
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // m e t r i c s S a v e                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Save the current settings.                                         //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void metricsSave()
        {
            TargetCore.metricsSaveFileCapt(_crntToolId, _crntSubId, _crntPDL,
                                           _saveFilename);
        }
Ejemplo n.º 9
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // i n i t i a l i s e                                                //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Initialise 'target' data.                                          //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void initialise()
        {
            btnOK.Visibility = Visibility.Hidden;

            //----------------------------------------------------------------//
            //                                                                //
            // Tool and PDL identifiers.                                      //
            //                                                                //
            //----------------------------------------------------------------//

            if (_crntSubId == ToolCommonData.eToolSubIds.None)
            {
                txtCrntTool.Text =
                    Enum.GetName(typeof(ToolCommonData.eToolIds),
                                 _crntToolId);
            }
            else
            {
                txtCrntTool.Text =
                    Enum.GetName(typeof(ToolCommonData.eToolIds),
                                 _crntToolId) +
                    "|" +
                    Enum.GetName(typeof(ToolCommonData.eToolSubIds),
                                 _crntSubId);
            }

            txtCrntPDL.Text = _crntPDL.ToString();

            //----------------------------------------------------------------//
            //                                                                //
            // Output file data.                                              //
            //                                                                //
            //----------------------------------------------------------------//

            if ((_crntToolId == ToolCommonData.eToolIds.FontSample)
                ||
                (_crntToolId == ToolCommonData.eToolIds.FormSample)
                ||
                (_crntToolId == ToolCommonData.eToolIds.ImageBitmap)
                ||
                (_crntToolId == ToolCommonData.eToolIds.MiscSamples)
                ||
                (_crntToolId == ToolCommonData.eToolIds.PrintArea)
                ||
                (_crntToolId == ToolCommonData.eToolIds.PrnPrint)
                ||
                (_crntToolId == ToolCommonData.eToolIds.StatusReadback)
                ||
                (_crntToolId == ToolCommonData.eToolIds.TrayMap))
            {
                grpOpFile.Visibility = Visibility.Visible;
                lbFileNA.Visibility  = Visibility.Hidden;
                btnOK.Visibility     = Visibility.Visible;

                TargetCore.metricsReturnFileCapt(_crntToolId,
                                                 _crntSubId,
                                                 _crntPDL,
                                                 ref _saveFilename);

                txtOpFilename.Text = _saveFilename;
            }
            else
            {
                grpOpFile.Visibility = Visibility.Hidden;
                lbFileNA.Visibility  = Visibility.Visible;
            }

            //----------------------------------------------------------------//
            //                                                                //
            // Set the (hidden) slider object to the passed-in scale value.   //
            // The slider is used as the source binding for a scale           //
            // transform in the (child) Options dialogue window, so that all  //
            // windows use the same scaling mechanism as the main window.     //
            //                                                                //
            // NOTE: it would be better to bind the transform directly to the //
            //       scale value (set and stored in the Main window), but (so //
            //       far) I've failed to find a way to bind directly to a     //
            //       class object Property value.                             //
            //                                                                //
            //----------------------------------------------------------------//

            Double windowScale = MainFormData.WindowScale;

            zoomSlider.Value = windowScale;

            //----------------------------------------------------------------//
            //                                                                //
            // Setting sizes to the resizeable DockPanel element doesn't work!//
            //                                                                //
            //----------------------------------------------------------------//

            this.Height = 300 * windowScale;
            this.Width  = 730 * windowScale;
        }
Ejemplo n.º 10
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // m e t r i c s S a v e                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Save the current settings.                                         //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void metricsSave()
        {
            TargetCore.metricsSaveFileRpt(_crntToolId, _rptFileFmt,
                                          _rptChkMarks, _flagOptRptWrap);
        }
Ejemplo n.º 11
0
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // i n i t i a l i s e                                                //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Initialise 'target' data.                                          //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void initialise()
        {
            btnOK.Visibility = Visibility.Hidden;

            //----------------------------------------------------------------//
            //                                                                //
            // Tool and PDL identifiers.                                      //
            //                                                                //
            //----------------------------------------------------------------//

            if (_crntSubId == ToolCommonData.eToolSubIds.None)
            {
                txtCrntTool.Text =
                    Enum.GetName(typeof(ToolCommonData.eToolIds),
                                 _crntToolId);
            }
            else
            {
                txtCrntTool.Text =
                    Enum.GetName(typeof(ToolCommonData.eToolIds),
                                 _crntToolId) +
                    "|" +
                    Enum.GetName(typeof(ToolCommonData.eToolSubIds),
                                 _crntSubId);
            }

            txtCrntPDL.Text = _crntPDL.ToString();

            //----------------------------------------------------------------//
            //                                                                //
            // Report file data.                                              //
            //                                                                //
            //----------------------------------------------------------------//

            if ((_crntToolId == ToolCommonData.eToolIds.MakeOverlay)
                ||
                (_crntToolId == ToolCommonData.eToolIds.PrintLang)
                ||
                (_crntToolId == ToolCommonData.eToolIds.PrnAnalyse)
                ||
                (_crntToolId == ToolCommonData.eToolIds.SoftFontGenerate)
                ||
                (_crntToolId == ToolCommonData.eToolIds.StatusReadback)
                ||
                (_crntToolId == ToolCommonData.eToolIds.SymbolSetGenerate))
            {
                grpRptFile.Visibility = Visibility.Visible;
                lbFileNA.Visibility   = Visibility.Hidden;
                btnOK.Visibility      = Visibility.Visible;

                TargetCore.metricsReturnFileRpt(_crntToolId,
                                                ref _rptFileFmt,
                                                ref _rptChkMarks,
                                                ref _flagOptRptWrap);

                if (_rptFileFmt == ReportCore.eRptFileFmt.html)
                {
                    rbRptFmtHtml.IsChecked = true;
                }
                else if (_rptFileFmt == ReportCore.eRptFileFmt.xml)
                {
                    rbRptFmtXml.IsChecked = true;
                }
                else
                {
                    rbRptFmtText.IsChecked = true;
                }

                grpRptChkMarks.Visibility = Visibility.Hidden;
                grpRptOpt.Visibility      = Visibility.Hidden;

                if (_crntToolId == ToolCommonData.eToolIds.PrintLang)
                {
                    grpRptChkMarks.Visibility = Visibility.Visible;
                    grpRptOpt.Visibility      = Visibility.Visible;

                    if (_rptChkMarks >= ReportCore.eRptChkMarks.NA)
                    {
                        _rptChkMarks = ReportCore.eRptChkMarks.text;
                    }

                    if (_rptChkMarks == ReportCore.eRptChkMarks.boxsym)
                    {
                        rbRptChkMarksBoxSym.IsChecked = true;
                    }
                    else if (_rptChkMarks == ReportCore.eRptChkMarks.txtsym)
                    {
                        rbRptChkMarksTxtSym.IsChecked = true;
                    }
                    else
                    {
                        rbRptChkMarksText.IsChecked = true;
                    }

                    if (_flagOptRptWrap)
                    {
                        chkRptOptWrap.IsChecked = true;
                    }
                    else
                    {
                        chkRptOptWrap.IsChecked = false;
                    }
                }
                else if (_crntToolId == ToolCommonData.eToolIds.SoftFontGenerate)
                {
                    grpRptChkMarks.Visibility = Visibility.Visible;

                    if (_rptChkMarks >= ReportCore.eRptChkMarks.NA)
                    {
                        _rptChkMarks = ReportCore.eRptChkMarks.text;
                    }

                    if (_rptChkMarks == ReportCore.eRptChkMarks.boxsym)
                    {
                        rbRptChkMarksBoxSym.IsChecked = true;
                    }
                    else if (_rptChkMarks == ReportCore.eRptChkMarks.txtsym)
                    {
                        rbRptChkMarksTxtSym.IsChecked = true;
                    }
                    else
                    {
                        rbRptChkMarksText.IsChecked = true;
                    }
                }
            }
            else
            {
                grpRptFile.Visibility = Visibility.Hidden;
                lbFileNA.Visibility   = Visibility.Visible;
            }

            //----------------------------------------------------------------//
            //                                                                //
            // Set the (hidden) slider object to the passed-in scale value.   //
            // The slider is used as the source binding for a scale           //
            // transform in the (child) Options dialogue window, so that all  //
            // windows use the same scaling mechanism as the main window.     //
            //                                                                //
            // NOTE: it would be better to bind the transform directly to the //
            //       scale value (set and stored in the Main window), but (so //
            //       far) I've failed to find a way to bind directly to a     //
            //       class object Property value.                             //
            //                                                                //
            //----------------------------------------------------------------//

            Double windowScale = MainFormData.WindowScale;

            zoomSlider.Value = windowScale;

            //----------------------------------------------------------------//
            //                                                                //
            // Setting sizes to the resizeable DockPanel element doesn't work!//
            //                                                                //
            //----------------------------------------------------------------//

            this.Height = 350 * windowScale;
            this.Width  = 730 * windowScale;
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // r e a d R e s p o n s e                                            //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Read response from target.                                         //
        //                                                                    //
        // There should be TWO FormFeeds in the returned data:                //
        //  - first one after return of ECHO data;                            //
        //  - second one after end of response data;                          //
        //                                                                    //
        // With some printers, a minimum of two 'reads' are necessary with    //
        // PJL Status Readback, because:                                      //
        //  - the first read reads the ECHO (identifying) data (terminated    //
        //    with a Form Feed byte).                                         //
        //  - the second read reads the actual response data (also terminated //
        //    with a FormFeed byte).                                          //
        //                                                                    //
        // With other printers, the response data is concatenated with the    //
        // echo data, so a single read may be all that is necessary.          //
        //                                                                    //
        // In each case, multiple reads may be required if the length of the  //
        // returned data exceeds the read 'chunk' size.                       //
        //                                                                    //
        // And some printers may respond with bits of data less than the      //
        // 'chunk' size, if there is a lot to return, but it is still         //
        // necessary to carry on reading until the terminating <FF> byte is   //
        // found.                                                             //
        //                                                                    //
        //--------------------------------------------------------------------//

        public static String readResponse()
        {
            const Int32 replyBufLen = 32768;

            Byte[] replyData = new Byte[replyBufLen];

            Int32 replyLen = 0;

            Boolean readFF_A      = false;       // two <FF>s expected //
            Boolean OK            = false;
            Boolean replyComplete = false;

            Int32 offset    = 0;
            Int32 endOffset = 0;
            Int32 bufRem    = replyBufLen;
            Int32 blockLen  = 0;

            while (!replyComplete)
            {
                OK = TargetCore.responseReadBlock(offset,
                                                  bufRem,
                                                  ref replyData,
                                                  ref blockLen);

                endOffset = offset + blockLen;

                if (!OK)
                {
                    replyComplete = true;
                }
                else if (!readFF_A)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Not yet found any <FF> bytes.                          //
                    // Search buffer to see if first, or both first and       //
                    // second <FF> (as applicable) are present.               //
                    //                                                        //
                    // This branch is expected to be entered since we include //
                    // a PJL ECHO commmand in the job header.                 //
                    //                                                        //
                    //--------------------------------------------------------//

                    for (Int32 i = offset; i < endOffset; i++)
                    {
                        if (replyData[i] == 0x0c)
                        {
                            if ((readFF_A) && (replyData[endOffset - 1] == 0x0c))
                            {
                                replyComplete = true;
                            }
                            else
                            {
                                readFF_A = true;
                            }
                        }
                    }
                }
                else
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // <FF> at end of ECHO text is either not expected, or    //
                    // has been read in a previous read action.               //
                    //                                                        //
                    //--------------------------------------------------------//

                    if (replyData[endOffset - 1] == 0x0c)
                    {
                        //----------------------------------------------------//
                        //                                                    //
                        // Terminating <FF> found (as last byte of data       //
                        // returned by current read action).                  //
                        //                                                    //
                        //----------------------------------------------------//

                        replyComplete = true;
                    }
                }

                offset += blockLen;
                bufRem -= blockLen;

                if (bufRem <= 0)
                {
                    replyComplete = true;
                }
            }

            replyLen = endOffset;

            TargetCore.responseCloseConnection();

            return(System.Text.Encoding.ASCII.GetString(replyData,
                                                        0,
                                                        replyLen));
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // b t n G e n e r a t e _ C l i c k                                  //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Called when the 'Generate' button is clicked.                      //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void btnGenerate_Click(object sender, RoutedEventArgs e)
        {
            Int32 result = 0;

            Boolean bitmapOpen = false;

            //----------------------------------------------------------------//
            //                                                                //
            // Get current test metrics.                                      //
            // Note that the relevant (PDL-specific) stored option values     //
            // SHOULD already be up-to-date, since the fields all have        //
            // associated 'OnChange' actions. ***** Not with WPF ????? *****  //
            // But we'll save them all anyway, to make sure.                  //
            //                                                                //
            //----------------------------------------------------------------//

            _indxPDL = cbPDL.SelectedIndex;
            _crntPDL = (ToolCommonData.ePrintLang)_subsetPDLs[_indxPDL];

            pdlOptionsStore();

            //----------------------------------------------------------------//
            //                                                                //
            // Generate test print file.                                      //
            //                                                                //
            //----------------------------------------------------------------//

            bitmapOpen = ToolImageBitmapCore.bitmapOpen(_bitmapFilename);

            if (!bitmapOpen)
            {
                result = -1;
            }

            if (result == 0)
            {
                result = ToolImageBitmapCore.readBmpFileHeader();
            }

            if (result == 0)
            {
                result = ToolImageBitmapCore.readBmpInfoHeader();
            }

            if (result == 0)
            {
                result = ToolImageBitmapCore.readBmpPalette();
            }

            if (result == 0)
            {
                BinaryWriter binWriter = null;

                TargetCore.requestStreamOpen(
                    ref binWriter,
                    ToolCommonData.eToolIds.ImageBitmap,
                    ToolCommonData.eToolSubIds.None,
                    _crntPDL);

                if (result == 0)
                {
                    //--------------------------------------------------------//
                    //                                                        //
                    // Write test data to output file.                        //
                    //                                                        //
                    //--------------------------------------------------------//

                    if (_crntPDL == ToolCommonData.ePrintLang.PCL)
                    {
                        ToolImageBitmapPCL.generateJob(
                            binWriter,
                            _subsetPaperSizes[_indxPaperSizePCL],
                            _subsetPaperTypes[_indxPaperTypePCL],
                            _subsetOrientations[_indxOrientationPCL],
                            _destPosX,
                            _destPosY,
                            _destScalePercentX,
                            _destScalePercentY,
                            _indxRasterResolutionPCL);
                    }
                    else    // if (_crntPDL == (Int32)ToolCommonData.ePrintLang.PCLXL)
                    {
                        ToolImageBitmapPCLXL.generateJob(
                            binWriter,
                            _subsetPaperSizes[_indxPaperSizePCLXL],
                            _subsetPaperTypes[_indxPaperTypePCLXL],
                            _subsetOrientations[_indxOrientationPCLXL],
                            _destPosX,
                            _destPosY,
                            _destScalePercentX,
                            _destScalePercentY);
                    }
                }

                if (result == 0)
                {
                    TargetCore.requestStreamWrite(false);
                }
            }

            if (bitmapOpen)
            {
                ToolImageBitmapCore.bitmapClose();
            }
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // m e t r i c s S a v e                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Save the current settings.                                         //
        //                                                                    //
        //--------------------------------------------------------------------//

        public void metricsSave()
        {
            TargetCore.metricsSaveWinPrinter(_printerName);
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // i n i t i a l i s e                                                //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Initialise 'target' data.                                          //
        //                                                                    //
        //--------------------------------------------------------------------//

        private void initialise()
        {
            Int32 indxPrinter = 0;
            Int32 ctPrinters  = 0;

            String printerName;

            //----------------------------------------------------------------//
            //                                                                //
            // Populate form.                                                 //
            //                                                                //
            //----------------------------------------------------------------//

            TargetCore.metricsLoadWinPrinter(ref _printerName);

            cbPrinters.Items.Clear();

            ctPrinters = PrinterSettings.InstalledPrinters.Count;

            for (Int32 i = 0; i < ctPrinters; i++)
            {
                printerName = PrinterSettings.InstalledPrinters[i];

                cbPrinters.Items.Add(printerName);

                if (printerName == _printerName)
                {
                    indxPrinter = i;
                }
            }

            //----------------------------------------------------------------//

            if ((indxPrinter < 0) || (indxPrinter >= ctPrinters))
            {
                indxPrinter = 0;
            }

            cbPrinters.SelectedIndex = indxPrinter;
            _printerName             = cbPrinters.Text;

            //----------------------------------------------------------------//
            //                                                                //
            // Set the (hidden) slider object to the passed-in scale value.   //
            // The slider is used as the source binding for a scale           //
            // transform in the (child) Options dialogue window, so that all  //
            // windows use the same scaling mechanism as the main window.     //
            //                                                                //
            // NOTE: it would be better to bind the transform directly to the //
            //       scale value (set and stored in the Main window), but (so //
            //       far) I've failed to find a way to bind directly to a     //
            //       class object Property value.                             //
            //                                                                //
            //----------------------------------------------------------------//

            Double windowScale = MainFormData.WindowScale;

            zoomSlider.Value = windowScale;

            //----------------------------------------------------------------//
            //                                                                //
            // Setting sizes to the resizeable DockPanel element doesn't work!//
            //                                                                //
            //----------------------------------------------------------------//

            this.Height = 240 * windowScale;
            this.Width  = 440 * windowScale;

            // Double h = resizeable.Height;
            // Double w = resizeable.Width;

            // this.Height = h;
            // this.Width = w;
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // s e n d R e q u e s t                                              //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Send generated status readback request data to target.             //
        //                                                                    //
        //--------------------------------------------------------------------//

        public static void sendRequest()
        {
            TargetCore.requestStreamWrite(true);
        }
        //--------------------------------------------------------------------//
        //                                                        M e t h o d //
        // r e a d R e s p o n s e U p l o a d                                //
        //--------------------------------------------------------------------//
        //                                                                    //
        // Read standard response from PJL FileSystem query; request types:   //
        //  -   FSUPLOAD                                                      //
        //                                                                    //
        // Response from printer expected - write this direct to the target   //
        // file (it could be (much) larger than the standard reply buffer.    //
        //                                                                    //
        // The response terminates with a FormFeed byte, but the binary data  //
        // returned may also include FormFeed bytes, so have to ignore those  //
        // ones.                                                              //
        //                                                                    //
        // Also, at least one printer (LaserJet M553x) appears to return      //
        // extra bytes (sometimes hundreds or more) between the end of the    //
        // upload (of a size determined by the SIZE parameter returned at the //
        // start of the response) and the terminating <FF>.                   //
        // This is presumably a firmware bug?                                 //
        //                                                                    //
        //--------------------------------------------------------------------//

        private static String readResponseUpload(String binTgtFilename)
        {
            const Int32 replyBufLen = 32768;

            String reply = "";

            Boolean binFileOpen = false;

            binFileOpen = binTgtFileOpen(binTgtFilename);

            if (!binFileOpen)
            {
                reply = "Failed to open target binary file:\r\n\r\n" +
                        binTgtFilename;
            }
            else
            {
                Int32  binSize    = -1;
                Byte[] replyBlock = new Byte[replyBufLen];

                //   Boolean readFF_A = true;    // only one <FF> expected //
                Boolean OK             = true;
                Boolean replyComplete  = false;
                Boolean firstBlock     = true;
                Boolean supDataWritten = false;

                Int32 offset    = 0;
                Int32 endOffset = 0;
                Int32 bufRem    = replyBufLen;
                Int32 blockLen  = 0;
                Int32 binLen    = 0;
                Int32 binTot    = 0;
                Int32 binRem    = 0;
                Int32 supLen    = 0;

                while (OK && !replyComplete)
                {
                    OK = TargetCore.responseReadBlock(offset,
                                                      bufRem,
                                                      ref replyBlock,
                                                      ref blockLen);

                    endOffset = offset + blockLen;

                    if (!OK)
                    {
                        replyComplete = true;
                    }

                    /*else if (!readFF_A)
                     * {
                     *  //--------------------------------------------------------//
                     *  //                                                        //
                     *  // Not yet found any <FF> bytes.                          //
                     *  // Search buffer to see if first, or both first and       //
                     *  // second <FF> (as applicable) are present.               //
                     *  //                                                        //
                     *  // This branch will never be entered unless we include a  //
                     *  // PJL ECHO commmand in the job header; included in case  //
                     *  // we ever do this.                                       //
                     *  //                                                        //
                     *  //--------------------------------------------------------//
                     *
                     *  for (Int32 i = offset; i < endOffset; i++)
                     *  {
                     *      if (replyData[i] == 0x0c)
                     *      {
                     *          if ((readFF_A) && (replyData[endOffset - 1] == 0x0c))
                     *              replyComplete = true;
                     *          else
                     *              readFF_A = true;
                     *      }
                     *  }
                     * }*/
                    else
                    {
                        //--------------------------------------------------------//
                        //                                                        //
                        // <FF> at end of ECHO text is either not expected, or    //
                        // has been read in a previous read action.               //
                        //                                                        //
                        //--------------------------------------------------------//

                        if (replyBlock[endOffset - 1] == 0x0c)
                        {
                            //----------------------------------------------------//
                            //                                                    //
                            // Terminating <FF> found (as last byte of data       //
                            // returned by current read action).                  //
                            //                                                    //
                            //----------------------------------------------------//

                            replyComplete = true;
                        }
                    }

                    if (firstBlock)
                    {
                        //--------------------------------------------------------//
                        //                                                        //
                        // Assume that the first block of the response data will  //
                        // contain (at least) the complete PJL FSUPLOAD command   //
                        // with its parameters.                                   //
                        //                                                        //
                        //--------------------------------------------------------//

                        Int32 cmdLen;

                        firstBlock = false;

                        cmdLen = Array.IndexOf(replyBlock,
                                               PrnParseConstants.asciiLF,
                                               0, blockLen);

                        if (cmdLen != -1)
                        {
                            //----------------------------------------------------//
                            //                                                    //
                            // Terminating <LF> byte of PJL command found.        //
                            // Search for the value associated with the SIZE      //
                            // parameter.                                         //
                            //                                                    //
                            //----------------------------------------------------//

                            cmdLen += 1;    // account for <LF> byte //

                            binSize = readResponseUploadSize(replyBlock, cmdLen);

                            reply = Encoding.ASCII.GetString(replyBlock,
                                                             0,
                                                             cmdLen) +
                                    "\r\n" +
                                    binSize + " bytes will be written to the" +
                                    " target file:" + "\r\n\r\n" +
                                    binTgtFilename;

                            binLen = blockLen - cmdLen;

                            if (replyComplete)
                            {
                                // terminating <FF> found; ignore this in count
                                binLen -= 1;
                            }

                            binRem = binSize;

                            if (binRem > binLen)
                            {
                                supLen = 0;
                                binRem = binRem - binLen;
                            }
                            else if (binRem < binLen)
                            {
                                supLen = binLen - binRem;
                                binLen = binRem;
                                binRem = 0;
                            }
                            else
                            {
                                supLen = 0;
                                binRem = 0;
                            }

                            binTot = binLen;

                            binTgtFileWrite(replyBlock, cmdLen, binLen);
                        }
                        else
                        {
                            //----------------------------------------------------//
                            //                                                    //
                            // Terminating <LF> byte of PJL command NOT found.    //
                            // Send response blocks to the binary file for        //
                            // diagnostic purposes.                               //
                            //                                                    //
                            //----------------------------------------------------//

                            reply = "SIZE data not found at start of response" +
                                    "\r\n\r\n" +
                                    "All response data will be written to the" +
                                    " target file:" + "\r\n\r\n" +
                                    binTgtFilename;

                            binSize = -1;
                            binRem  = 0;

                            binTgtFileWrite(replyBlock, 0, blockLen);
                        }
                    }
                    else
                    {
                        //--------------------------------------------------------//
                        //                                                        //
                        // Not the first response block.                          //
                        //                                                        //
                        //--------------------------------------------------------//

                        if (binSize == -1)
                        {
                            // write everything to target file //
                            binLen = blockLen;
                        }
                        else
                        {
                            binLen = blockLen;

                            if (replyComplete)
                            {
                                // terminating <FF> found; ignore this in count
                                binLen -= 1;
                            }

                            if (binRem > binLen)
                            {
                                binRem = binRem - binLen;
                            }
                            else if (binRem < binLen)
                            {
                                supLen += (binLen - binRem);
                                binLen  = binRem;
                                binRem  = 0;
                            }
                            else
                            {
                                binRem = 0;
                            }
                        }

                        binTot += binLen;

                        binTgtFileWrite(replyBlock, 0, binLen);
                    }

                    if ((supLen != 0) && (!supDataWritten))
                    {
                        supDataWritten = true;

                        reply += "\r\n\r\n" +
                                 "Response from device contains extra" +
                                 " bytes after the binary data of size " +
                                 binSize + " bytes.\r\n" +
                                 "Here are the first " + supLen +
                                 " such bytes:\r\n\r\n" +
                                 ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" +
                                 "\r\n" +
                                 Encoding.ASCII.GetString(replyBlock,
                                                          binLen,
                                                          supLen) +
                                 "\r\n" +
                                 "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<";
                    }
                }

                //--------------------------------------------------------//
                //                                                        //
                // Response complete.                                     //
                // Close connection and output binary file.               //
                //                                                        //
                //--------------------------------------------------------//

                TargetCore.responseCloseConnection();

                binTgtFileClose();

                //--------------------------------------------------------//
                //                                                        //
                // Supplement reply data with details of any              //
                // inconsistencies.                                       //
                //                                                        //
                //--------------------------------------------------------//

                if (binTot < binSize)
                {
                    reply += "\r\n\r\n" +
                             "Response contains only " + binTot +
                             " bytes of binary data, but " + binSize +
                             " bytes were expected!";
                }

                if (supLen != 0)
                {
                    reply += "\r\n\r\n" +
                             "Response from device contains an extra " +
                             supLen + " bytes after the binary data!";
                }
            }

            return(reply);
        }