Пример #1
0
        private void getStatus()
        {
            string[] args = new string[] { "-n", datacard.getName() };

            CommandLineOptions commandLineOptions = new CommandLineOptions();

            CommandLine.Utility.Arguments arguments = new CommandLine.Utility.Arguments(args);

            if (string.IsNullOrEmpty(arguments["n"]))
            {
                Console.WriteLine("Some information");
            }
            bool boolVal = false;

            if (Boolean.TryParse(arguments["n"], out boolVal))
            {
                Console.WriteLine("Some information");
            }
            commandLineOptions.printerName = arguments["n"];

            if (!string.IsNullOrEmpty(arguments["j"]))
            {
                commandLineOptions.jobStatus = true;
            }

            BidiSplWrap bidiSpl = null;

            try
            {
                bidiSpl = new BidiSplWrap();
                bidiSpl.BindDevice(commandLineOptions.printerName);

                string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION);
                //Console.WriteLine(Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine);

                string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2);
                PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML);
                DisplayPrinterOptionsValues(printerOptionsValues);

                string printerCardCountXML = bidiSpl.GetPrinterData(strings.COUNTER_STATUS2);
                PrinterCounterStatus printerCounterStatusValues = Util.ParsePrinterCounterStatusXML(printerCardCountXML);
                DisplayPrinterCounterValues(printerCounterStatusValues);

                string         suppliesXML    = bidiSpl.GetPrinterData(strings.SUPPLIES_STATUS3);
                SuppliesValues suppliesValues = Util.ParseSuppliesXML(suppliesXML);
                DisplaySuppliesValues(suppliesValues);

                //string printerStatusXML = bidiSpl.GetPrinterData(strings.PRINTER_MESSAGES);
                //PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML);
                //DisplayPrinterStatusValues(printerStatusValues);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                bidiSpl.UnbindDevice();
            }
        }
Пример #2
0
        private void readBtn_Click(object sender, EventArgs e)
        {
            String printerName = comboBox1.Text;

            GetPrinterProperties(printerName);

            ///printing is activated here

            BidiSplWrap bidiSpl      = null;
            int         printerJobID = 0;

            try
            {
                bidiSpl = new BidiSplWrap();
                String BindResponse = bidiSpl.BindDevice(printerName);
                textBox4.Text += Environment.NewLine + BindResponse;
                string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION);
                textBox4.Text += Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine;

                string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2);
                PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML);


                if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus)
                {
                    throw new Exception(printerName + " is not ready. status: " + printerOptionsValues._printerStatus);
                }
                else
                {
                    string hopperID = string.Empty;

                    printerJobID = Util.StartJob(
                        bidiSpl,
                        false,
                        hopperID);

                    Application.DoEvents();

                    String[] returnedArray = Util.ReadMagstripe(bidiSpl, false);


                    Application.DoEvents();

                    textBox1.Text += returnedArray[0];
                    textBox2.Text += returnedArray[1];
                    textBox3.Text += returnedArray[2];


                    textBox4.Text += "Magstripe data read successfully; printer job id: " + printerOptionsValues._printerStatus;
                }
            }
            catch (Exception ee) { }
        }
Пример #3
0
        private void GetPrinterProperties(String printerName)
        {
            BidiSplWrap bidiSpl      = null;
            int         printerJobID = 0;

            try
            {
                bidiSpl = new BidiSplWrap();
                String BindResponse = bidiSpl.BindDevice(printerName);
                textBox4.Text += Environment.NewLine + BindResponse;
                string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION);
                textBox4.Text += Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine;

                string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2);
                PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML);


                if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus)
                {
                    throw new Exception(printerName + " is not ready. status: " + printerOptionsValues._printerStatus);
                }
                else
                {
                    string         printerOptionsXMLSupply    = bidiSpl.GetPrinterData(strings.SUPPLIES_STATUS3);
                    SuppliesValues printerOptionsSupplyValues = Util.ParseSuppliesXML(printerOptionsXMLSupply);

                    textBox4.Text += Environment.NewLine + "Printer Status: " + printerOptionsValues._printerStatus;
                    textBox4.Text += Environment.NewLine + "Ribbon Type: " + printerOptionsSupplyValues._printRibbonType;
                    textBox4.Text += Environment.NewLine + "Ribbon Serial Number: " + printerOptionsSupplyValues._printRibbonSerialNumber;
                    textBox4.Text += Environment.NewLine + "Ribbon Level: " + printerOptionsSupplyValues._ribbonRemaining + "%";
                }
            }
            catch (BidiException e)
            {
                textBox4.Text += Environment.NewLine + e.Message;
                Util.CancelJob(bidiSpl, e.PrinterJobID, e.ErrorCode);
            }
            catch (Exception e)
            {
                textBox4.Text += Environment.NewLine + e.Message;

                if (0 != printerJobID)
                {
                    Util.CancelJob(bidiSpl, printerJobID, 0);
                }
            }
            finally
            {
                bidiSpl.UnbindDevice();
            }
        }
Пример #4
0
        private void writeBtn_Click(object sender, EventArgs e)
        {
            String printerName = comboBox1.Text;

            GetPrinterProperties(printerName);

            ///printing is activated here

            BidiSplWrap bidiSpl      = null;
            int         printerJobID = 0;

            try
            {
                bidiSpl = new BidiSplWrap();
                String BindResponse = bidiSpl.BindDevice(printerName);
                textBox4.Text += Environment.NewLine + BindResponse;
                string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION);
                textBox4.Text += Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine;

                string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2);
                PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML);


                if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus)
                {
                    throw new Exception(printerName + " is not ready. status: " + printerOptionsValues._printerStatus);
                }
                else
                {
                    string hopperID = string.Empty;

                    printerJobID = Util.StartJob(
                        bidiSpl,
                        false,
                        hopperID);

                    Application.DoEvents();

                    Util.EncodeMagstripe(bidiSpl, false, textBox1.Text, textBox2.Text, textBox3.Text);

                    //   tried to cancel job;
                    //  if ()
                    //  {
                    //      Util.CancelJob(bidiSpl,printerJobID,0);
                    //  }
                }
            }
            catch (Exception ee) { }
        }
Пример #5
0
    private static void CardJobWithStatus(
        BidiSplWrap bidiSpl,
        CommandLineOptions commandLineOptions,
        PrinterOptionsValues printerOptionsValues)
    {
        if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus)
        {
            throw new Exception(
                      commandLineOptions.printerName + " is not ready. status: " + printerOptionsValues._printerStatus);
        }

        int printerJobID = Util.StartJob(
            bidiSpl,
            string.Empty);  // hopperID

        string printerStatusXML = bidiSpl.GetPrinterData(strings.PRINTER_MESSAGES);
        PrinterStatusValues printerStatusValues = Util.ParsePrinterStatusXML(printerStatusXML);

        DisplayPrinterStatusValues(printerStatusValues);

        bidiSpl.SetPrinterData(strings.ENDJOB);

        Util.PollForJobCompletion(bidiSpl, printerJobID);
    }
Пример #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            String printerName = comboBox1.Text;

            GetPrinterProperties(printerName);

            ///printing is activated here

            BidiSplWrap bidiSpl      = null;
            int         printerJobID = 0;

            try
            {
                bidiSpl = new BidiSplWrap();
                String BindResponse = bidiSpl.BindDevice(printerName);
                textBox2.Text += Environment.NewLine + BindResponse;
                string driverVersionXml = bidiSpl.GetPrinterData(strings.SDK_VERSION);
                textBox2.Text += Environment.NewLine + "driver version: " + Util.ParseDriverVersionXML(driverVersionXml) + Environment.NewLine;

                string printerOptionsXML = bidiSpl.GetPrinterData(strings.PRINTER_OPTIONS2);
                PrinterOptionsValues printerOptionsValues = Util.ParsePrinterOptionsXML(printerOptionsXML);


                if ("Ready" != printerOptionsValues._printerStatus && "Busy" != printerOptionsValues._printerStatus)
                {
                    throw new Exception(printerName + " is not ready. status: " + printerOptionsValues._printerStatus);
                }
                else
                {
                    string hopperID = string.Empty;

                    printerJobID = Util.StartJob(
                        bidiSpl,
                        false,
                        hopperID);

                    Application.DoEvents();

                    Util.PrintTextAndGraphics(bidiSpl, printerName, textBox1.Text);
                    Application.DoEvents();
                    if (0 != printerJobID)
                    {
                        // wait for the print spooling to finish and then issue an EndJob():
                        Util.WaitForWindowsJobID(bidiSpl, printerName);
                        bidiSpl.SetPrinterData(strings.ENDJOB);
                    }

                    Application.DoEvents();
                    Util.PollForJobCompletion(bidiSpl, printerJobID);
                }
            }
            catch (BidiException ee)
            {
                textBox2.Text += Environment.NewLine + ee.Message;
                Util.CancelJob(bidiSpl, ee.PrinterJobID, ee.ErrorCode);
            }
            catch (Exception ee)
            {
                textBox2.Text += Environment.NewLine + ee.Message;

                if (0 != printerJobID)
                {
                    Util.CancelJob(bidiSpl, printerJobID, 0);
                }
            }
            finally
            {
                bidiSpl.UnbindDevice();
            }
        }