Пример #1
0
        public void Close()
        {
            switch (PrnModel)
            {
            case Model.T400:
                t400.Close();
                break;

            case Model.ICT:
                ict.Close();
                break;

            case Model.VKP80:
                vkp.Close();
                break;

            case Model.AV268:
                av.Close();
                break;

            case Model.CITIZEN:
                cit.Close();
                break;

            case Model.TUP900:
                tup.Close();
                break;
            }
        }
Пример #2
0
        public void Initialize()
        {
            List <string> cmports = new List <string>();

            try
            {
                RegistryKey comdevices = Registry.LocalMachine.OpenSubKey("HARDWARE").OpenSubKey("DEVICEMAP").OpenSubKey("SERIALCOMM");
                string[]    devices    = comdevices.GetValueNames();

                foreach (string s in devices)
                {
                    Match m = Regex.Match(s, @"QCUSB_COM", RegexOptions.IgnoreCase);

                    if (m.Success)
                    {
                        Object o1 = comdevices.GetValue(s);
                        cmports.Add(o1.ToString());
                    }
                }
            }
            catch
            {
            }

            string[] availableCom = System.IO.Ports.SerialPort.GetPortNames();

            for (int i = 0; i < availableCom.Length; i++)
            {
                if (cmports.Count > 0)
                {
                    string s = cmports.Find(p => p == availableCom[i]);

                    if (!String.IsNullOrEmpty(s))
                    {
                        continue;
                    }
                }

                try
                {
                    t400 = new T400(availableCom[i]);
                    System.Threading.Thread.Sleep(100);
                    if (t400.Test())
                    {
                        PrnModel = Model.T400;
                        port     = availableCom[i];
                        break;
                    }
                    if (t400 != null)
                    {
                        if (t400.IsOpen())
                        {
                            t400.Close();
                        }
                    }
                }
                catch
                {
                    if (t400 != null)
                    {
                        if (t400.IsOpen())
                        {
                            t400.Close();
                        }
                    }
                }
                try
                {
                    ict = new ICT(availableCom[i]);

                    if (ict.Test())
                    {
                        port     = availableCom[i];
                        PrnModel = Model.ICT;
                        break;
                    }
                    if (ict != null)
                    {
                        if (ict.IsOpen())
                        {
                            ict.Close();
                        }
                    }
                }
                catch
                {
                    if (ict != null)
                    {
                        if (ict.IsOpen())
                        {
                            ict.Close();
                        }
                    }
                }
                System.Threading.Thread.Sleep(100);
                try
                {
                    vkp = new VKP80(availableCom[i]);
                    System.Threading.Thread.Sleep(100);
                    if (vkp.GetVersion() == "VKP80")
                    {
                        PrnModel = Model.VKP80;
                        port     = availableCom[i];
                        break;
                    }
                    if (vkp != null)
                    {
                        if (vkp.IsOpen())
                        {
                            vkp.Close();
                        }
                    }
                }
                catch
                {
                    if (vkp != null)
                    {
                        if (vkp.IsOpen())
                        {
                            vkp.Close();
                        }
                    }
                }
                try
                {
                    av = new AV286(availableCom[i]);
                    System.Threading.Thread.Sleep(100);
                    if (av.Version.IndexOf("AV") != -1)
                    {
                        PrnModel = Model.AV268;
                        port     = availableCom[i];
                        break;
                    }
                    if (av != null)
                    {
                        if (av.IsOpen())
                        {
                            av.Close();
                        }
                    }
                }
                catch
                {
                    if (av != null)
                    {
                        if (av.IsOpen())
                        {
                            av.Close();
                        }
                    }
                }
                try
                {
                    cit = new Citizen(availableCom[i]);
                    System.Threading.Thread.Sleep(100);
                    cit.Test();
                    if (cit.Version.IndexOf("1000") != -1 || cit.Version.IndexOf("700") != -1 || cit.Version.IndexOf("2000") != -1)
                    {
                        PrnModel = Model.CITIZEN;
                        port     = availableCom[i];
                        break;
                    }
                    if (cit != null)
                    {
                        if (cit.IsOpen())
                        {
                            cit.Close();
                        }
                    }
                }
                catch
                {
                    if (cit != null)
                    {
                        if (cit.IsOpen())
                        {
                            cit.Close();
                        }
                    }
                }
                try
                {
                    tup = new Tup900(availableCom[i]);
                    //System.Threading.Thread.Sleep(100);
                    if (tup.Test())
                    {
                        PrnModel = Model.TUP900;
                        port     = availableCom[i];
                        break;
                    }
                    if (tup != null)
                    {
                        tup.Close();
                    }
                }
                catch
                {
                    if (tup != null)
                    {
                        tup.Close();
                    }
                }
            }
        }
Пример #3
0
        public Printer(string parameter)
        {
            Initialize(parameter);

            switch (PrnModel)
            {
            case Model.T400:
                if (t400 != null)
                {
                    if (t400.IsOpen())
                    {
                        t400.Close();
                    }
                }
                break;

            case Model.ICT:
                if (ict == null)
                {
                    if (this.port != null)
                    {
                        ict.Close();
                    }
                }
                break;

            case Model.VKP80:
                if (vkp == null)
                {
                    if (this.port != null)
                    {
                        vkp.Close();
                    }
                }
                break;

            case Model.AV268:
                if (av == null)
                {
                    if (this.port != null)
                    {
                        av.Close();
                    }
                }
                break;

            case Model.CITIZEN:
                if (cit == null)
                {
                    if (this.port != null)
                    {
                        cit.Close();
                    }
                }
                break;

            case Model.TUP900:
                if (tup == null)
                {
                    if (this.port != null)
                    {
                        tup.Close();
                    }
                }
                break;
            }
        }