Beispiel #1
0
        /// <summary>
        /// 获取加密狗中的支持的喷头类型
        /// </summary>
        /// <param name="infos"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        public static bool GetCateInfo(out byte[] infos, int index)
        {
            infos = null;
            try
            {
                IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
                IO_PACKAGE stDataPkgOut = new IO_PACKAGE();
                stDataPkgIn.tag  = (byte)SubFunction_ID.GetProductCat;
                stDataPkgIn.len  = IO_PACKAGE_BUFF_SIZE;
                stDataPkgIn.buff = new byte[IO_PACKAGE_BUFF_SIZE];

                stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
                stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

                BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut, index);
                if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
                {
                    //MessageBox.Show("GetCateInfo failed!");
                    return(false);
                }

                infos = new byte[stDataPkgOut.len];
                Buffer.BlockCopy(stDataPkgOut.buff, 0, infos, 0, infos.Length);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 取得当前的软件狗密码
        /// </summary>
        /// <returns>当前的软件狗密码</returns>
        public static BYHX_SL_RetValue GetPassWord(ref string strkey)
        {
            IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
            IO_PACKAGE stDataPkgOut = new IO_PACKAGE();

            stDataPkgIn.tag  = (byte)SubFunction_ID.GetPassWord;
            stDataPkgIn.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgIn.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut);

#if DEBUG
            if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
            {
                MessageBox.Show("Get ValidDate failed!");
            }
#endif
            byte[] dt = new byte[PASSWORDLEN];
            Buffer.BlockCopy(stDataPkgOut.buff, 0, dt, 0, dt.Length);
            strkey = Encoding.ASCII.GetString(dt);
            //for (int i = 0; i < dt.Length; i++)
            //{
            //    strkey += dt[i].ToString("X").PadLeft(2, '0');
            //}
            return(ret);
        }
Beispiel #3
0
        /// <summary>
        /// 打印时检查是否过期,并处理打印数据
        /// </summary>
        /// <param name="jobheader">加密后的值</param>
        /// <returns>true=调用成功/false=调用失败</returns>
        public static BYHX_SL_RetValue CheckValidDateWithData(byte[] jobheader, ref byte[] retValue)
        {
            byte[] inputbuff = new byte[jobheader.Length];
            Buffer.BlockCopy(jobheader, 0, inputbuff, 0, jobheader.Length);

            IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
            IO_PACKAGE stDataPkgOut = new IO_PACKAGE();

            stDataPkgIn.tag  = (byte)SubFunction_ID.ValidDateAndDataCheck;
            stDataPkgIn.len  = (byte)inputbuff.Length;
            stDataPkgIn.buff = inputbuff;

            stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut);

#if DEBUG
            if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
            {
                MessageBox.Show("CheckValidDateWithData Run failed!");
            }
#endif
            Buffer.BlockCopy(stDataPkgOut.buff, 0, retValue, 0, stDataPkgOut.len);
            return(ret);
        }
Beispiel #4
0
        public bool Start(IntPtr handle, bool bWrBd)
        {
            DEV_BROADCAST_DEVICEINTERFACE dbf = new DEV_BROADCAST_DEVICEINTERFACE();

            dbf.dbcc_size       = Marshal.SizeOf(dbf);
            dbf.dbcc_devicetype = Common.DBT_DEVTYP_DEVICEINTERFACE;
            dbf.dbcc_reserved   = 0;
            IntPtr hDevNotify1 = Common.RegisterDeviceNotification(handle, dbf, Common.DEVICE_NOTIFY_WINDOW_HANDLE | Common.DEVICE_NOTIFY_ALL_INTERFACE_CLASSES);
            int    lt          = 0;

            if (bWrBd)
            {
                BYHXSoftLock.CheckDongle_WrBd();
            }
            else
            {
                BYHXSoftLock.CheckDongle();
            }
#if ADD_HARDKEY
            BYHX_SL_RetValue ret = BYHXSoftLock.CheckValidDate(ref lt);

            switch (ret)
            {
            case BYHX_SL_RetValue.EXPIRED:
                m_bOutdated = true;
                MessageBox.Show(ResString.GetResString("EncryptDog_Expired"), ResString.GetProductName(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

            case BYHX_SL_RetValue.ILLEGALDOG:
                MessageBox.Show(ResString.GetResString("EncryptDog_Illegal"), ResString.GetProductName(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);

            case BYHX_SL_RetValue.NOFOUNDDOG:
                MessageBox.Show(ResString.GetResString("EncryptDog_NoFound"), ResString.GetProductName(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);

            case BYHX_SL_RetValue.WILLEXPIREDWORNING_100:
                MessageBox.Show(ResString.GetResString("EncryptDog_Warning"), ResString.GetProductName(), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                tCheckDog.Interval = (lt - 1) * 60 * 1000 + 1;
                tCheckDog.Tick    += new EventHandler(tCheckDog_Tick);
                tCheckDog.Start();
                break;

            default:
                break;
            }
            if (lt > 60 * 100 && lt - 100 * 60 <= int.MaxValue / 1000 / 60)
            {
                tCloseTimer.Interval = (lt - 100 * 60) * 60 * 1000;
                tCloseTimer.Tick    += new EventHandler(tCloseTimer_Tick);
                tCloseTimer.Start();
            }
#endif
            return(true);
        }
Beispiel #5
0
        public static void CheckDongle_WrBd()
        {
            try
            {
                // 枚举插入的所有狗
                bool             bfirst      = true;
                int              index       = -1;
                int              leftt       = 0;
                SENSE4_CONTEXT[] jobInfoList = Common.EnumAllS4();
                if (jobInfoList != null & jobInfoList.Length > 0)
                {
                    // 遍历识别主锁
                    for (int i = 0; i < jobInfoList.Length; i++)
                    {
                        byte ret1 = BYHXSoftLock.RecognizeMasterKey(i, UserPin);
                        if (ret1 == 1)
                        {
                            byte[]           infos = new byte[19];
                            BYHX_SL_RetValue ret   = BYHXSoftLock.GetDongleInfo(ref infos, i);
                            if (ret != BYHX_SL_RetValue.SUCSESS)
                            {
                                continue;
                            }
                            else
                            {
                                if (0xff != (infos[16]))
                                {
                                    continue;
                                }
                            }

                            if (bfirst)
                            {
                                index  = i;
                                bfirst = false;
                            }
                            int lefttM = 0;
                            FIRST_S4_INDEX = i;
                            if (CheckValidDate(ref lefttM) == BYHX_SL_RetValue.SUCSESS && lefttM > leftt)
                            {
                                leftt = lefttM;
                                index = i;
                                //								break;
                            }
                        }
                    }
                    FIRST_S4_INDEX = index;
                }
            }
            catch
            {
                return;
            }
        }
Beispiel #6
0
        /// <summary>
        /// 识别母狗 0:母狗 1:子狗 2:非法狗
        /// </summary>
        /// <param name="index"></param>
        /// <param name="UserPin"></param>
        /// <returns>0:母狗 1:子狗 2:非法狗</returns>
        public static byte RecognizeMasterKey(int index, byte[] UserPin)
        {
            try
            {
                IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
                IO_PACKAGE stDataPkgOut = new IO_PACKAGE();
                stDataPkgIn.tag  = (byte)SubFunction_ID.IsMasterDog;
                stDataPkgIn.len  = IO_PACKAGE_BUFF_SIZE;
                stDataPkgIn.buff = new byte[IO_PACKAGE_BUFF_SIZE];

                stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
                stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

                BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut, index);
                if (ret != BYHX_SL_RetValue.SUCSESS)
                {
                    return(2);
                }
                if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
                {
                    return(2);
                }
                //byte[] dt = new byte[Marshal.SizeOf(typeof(RTC_TIME_T))];
                //Buffer.BlockCopy(stDataPkgOut.buff, 0, dt, 0, dt.Length);
                //RTC_TIME_T rett = new RTC_TIME_T(dt);
                byte[] infos = new byte[stDataPkgOut.len];
                Buffer.BlockCopy(stDataPkgOut.buff, 0, infos, 0, infos.Length);
                if (infos.Length > 0)
                {
                    if (infos[0] == 1)
                    {
                        return(0);
                    }
                    else
                    {
                        return(1);
                    }
                }
                else
                {
                    return(2);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                MessageBox.Show(ex.Message);
#endif
                return(2);
            }
        }
Beispiel #7
0
        public void OnPrinterStatusChanged(JetStatusEnum status)
        {
            UpdateButtonStates(status);
            SetPrinterStatusChanged(status);
            if (status == JetStatusEnum.Error)
            {
                OnErrorCodeChanged(CoreInterface.GetBoardError());

                int        errorCode  = CoreInterface.GetBoardError();
                SErrorCode sErrorCode = new SErrorCode(errorCode);
                if (SErrorCode.IsOnlyPauseError(errorCode))
                {
                    string errorInfo = SErrorCode.GetInfoFromErrCode(errorCode);

                    if (
                        MessageBox.Show(errorInfo, ResString.GetProductName(), MessageBoxButtons.RetryCancel,
                                        MessageBoxIcon.Exclamation) == DialogResult.Retry)
                    {
                        CoreInterface.Printer_Resume();
                    }
                }
            }
            else
            {
                OnErrorCodeChanged(0);
            }
            if (status != JetStatusEnum.PowerOff && status != JetStatusEnum.Initializing && m_IsFATAL == false)
            {
                if (SPrinterProperty.IsGongZeng() || SPrinterProperty.IsDocanPrintMode() || SPrinterProperty.IsRuiZhi()) // 此功能按 厂商限定
                {
                    byte[]           infos = new byte[19];
                    BYHX_SL_RetValue ret   = BYHXSoftLock.GetDongleInfo(ref infos);
                    if (ret == BYHX_SL_RetValue.SUCSESS)
                    {
                        byte[] dtV = new byte[4];
                        Buffer.BlockCopy(infos, 4, dtV, 0, dtV.Length);
                        uint boardId = BitConverter.ToUInt32(dtV, 0);
                        if (CoreInterface.IsFatal(boardId))
                        {
                            m_IsFATAL = true;
                        }
                    }
                }
                else
                {
                    m_IsFATAL = true;
                }
            }
        }
Beispiel #8
0
        /// <summary>
        /// 获取加密狗内的特殊功能权限
        /// </summary>
        /// <param name="func"></param>
        /// <returns></returns>
        public static BYHX_SL_RetValue GetFunctionWords(ref int func)
        {
            //BIT31 = 1  表示支持波形调试
            byte[]           FeaByte = new byte[16];
            BYHX_SL_RetValue ret     = GetFeatureWords(ref FeaByte);

            {
                func = 0;
                func = (func << 8) + FeaByte[8];
                func = (func << 8) + FeaByte[9];
                func = (func << 8) + FeaByte[10];
                func = (func << 8) + FeaByte[11];
            }
            return(ret);
        }
Beispiel #9
0
        /// <summary>
        /// 检查是否过期
        /// </summary>
        /// <returns>false=已过期;true=未过期</returns>
        public static BYHX_SL_RetValue CheckValidDate(ref int leftT)
        {
            IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
            IO_PACKAGE stDataPkgOut = new IO_PACKAGE();

            stDataPkgIn.tag  = (byte)SubFunction_ID.ValidDateCheck;
            stDataPkgIn.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgIn.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];
            BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut);

            if (ret == BYHX_SL_RetValue.SUCSESS)
            {
                if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
                {
                    if (stDataPkgOut.tag == 0x86)                   //#define ErrorEnum_IllegalPWD 0x86
                    {
                        return(BYHX_SL_RetValue.EXPIRED);
                    }
                    else
                    {
                        return(BYHX_SL_RetValue.ILLEGALDOG);
                    }
                }
                else
                {
                    byte[] toint = new byte[stDataPkgOut.len];
                    Buffer.BlockCopy(stDataPkgOut.buff, 0, toint, 0, toint.Length);
                    leftT = BitConverter.ToInt32(toint, 0);
                }
                if (leftT <= 0)
                {
                    return(BYHX_SL_RetValue.EXPIRED);
                }
                else if (leftT < 100 * 60)
                {
                    return(BYHX_SL_RetValue.WILLEXPIREDWORNING_100);
                }
                else
                {
                    return(BYHX_SL_RetValue.SUCSESS);
                }
            }
            return(ret);
        }
Beispiel #10
0
        public bool LoadAndCheckDongleKey()
        {
            BYHXSoftLock.CheckDongle();
#if ADD_HARDKEY
            int lt = 0;
            BYHX_SL_RetValue ret = BYHXSoftLock.CheckValidDate(ref lt);
            m_bOutdated = false;
            switch (ret)
            {
            case BYHX_SL_RetValue.EXPIRED:
                m_bOutdated = true;
                break;

            case BYHX_SL_RetValue.ILLEGALDOG:
            case BYHX_SL_RetValue.NOFOUNDDOG:
                return(false);

            case BYHX_SL_RetValue.WILLEXPIREDWORNING_100:
                tCheckDog.Interval = (lt - 1) * 60 * 1000 + 1;
                tCheckDog.Tick    += new EventHandler(tCheckDog_Tick);
                tCheckDog.Start();
                break;

            default:
                break;
            }

            if (lt > 100 * 60 && lt - 100 * 60 <= int.MaxValue / 1000 / 60)
            {
                tCloseTimer.Interval = (lt - 100 * 60) * 60 * 1000;
                tCloseTimer.Tick    += new EventHandler(tCloseTimer_Tick);
                tCloseTimer.Start();
            }
            if (this.LoadAndCheckDongleKeyFinished != null)
            {
                this.LoadAndCheckDongleKeyFinished(null, new EventArgs());
            }
#endif
            return(true);
        }
Beispiel #11
0
        /// <summary>
        /// Fun_CMD_GetDongleInfo:DogId 4,  Left time 4 ,Dead time 4,vender 2,lang 1
        /// </summary>
        /// <returns>DogId 4,  Left time 4 ,Dead time 4,vender 2,lang 1</returns>
        public static BYHX_SL_RetValue GetDongleInfo(ref byte[] infos, int index)
        {
            IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
            IO_PACKAGE stDataPkgOut = new IO_PACKAGE();

            stDataPkgIn.tag  = (byte)SubFunction_ID.GetDongleInfo;
            stDataPkgIn.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgIn.buff = new byte[IO_PACKAGE_BUFF_SIZE];;

            stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut, index);

            if (ret == BYHX_SL_RetValue.SUCSESS)
            {
                if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
                {
#if DEBUG
                    MessageBox.Show("Get ValidDate failed!");
#endif
                    if (stDataPkgOut.tag == 0x86)                   //#define ErrorEnum_IllegalPWD 0x86
                    {
                        return(BYHX_SL_RetValue.EXPIRED);
                    }
                    else
                    {
                        return(BYHX_SL_RetValue.ILLEGALDOG);
                    }
                }

                //byte[] dt = new byte[Marshal.SizeOf(typeof(RTC_TIME_T))];
                //Buffer.BlockCopy(stDataPkgOut.buff, 0, dt, 0, dt.Length);
                //RTC_TIME_T rett = new RTC_TIME_T(dt);
                infos = new byte[stDataPkgOut.len];
                Buffer.BlockCopy(stDataPkgOut.buff, 0, infos, 0, infos.Length);
            }
            return(ret);
        }
Beispiel #12
0
        public static BYHX_SL_RetValue SetProductInfo(byte[] info, int size)
        {
            IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
            IO_PACKAGE stDataPkgOut = new IO_PACKAGE();

            stDataPkgIn.tag  = (byte)SubFunction_ID.SetProductInfo;
            stDataPkgIn.len  = (byte)size;
            stDataPkgIn.buff = info;

            stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut);

#if DEBUG
            if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
            {
                MessageBox.Show("Set ValidDate failed!");
            }
#endif
            return(ret);
        }
Beispiel #13
0
        /// <summary>
        /// 获取加密狗的系统时钟时间
        /// </summary>
        /// <returns></returns>
        public static DateTime GetDateTime()
        {
            // 格林尼治时间和北京时间相差8小时
            DateTime retdt = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Unspecified).AddHours(8);

            try
            {
                IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
                IO_PACKAGE stDataPkgOut = new IO_PACKAGE();
                stDataPkgIn.tag  = (byte)SubFunction_ID.GetDogTimer;
                stDataPkgIn.len  = IO_PACKAGE_BUFF_SIZE;
                stDataPkgIn.buff = new byte[IO_PACKAGE_BUFF_SIZE];

                stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
                stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

                BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut);
                if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
                {
                    //MessageBox.Show("GetCateInfo failed!");
                    LogWriter.SaveOptionLog("获取加密锁时钟失败!!使用系统时间替代");
                    return(DateTime.Now);// 获取失败则按系统时间
                }
                //加密狗返回的数据字节顺序和pc端是反向的,此处倒序处理
                byte[] buf = new byte[stDataPkgOut.len];
                for (int i = 0; i < buf.Length; i++)
                {
                    buf[i] = stDataPkgOut.buff[buf.Length - 1 - i];
                }
                retdt = retdt.AddSeconds(BitConverter.ToUInt32(buf, 0));
                return(retdt);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                LogWriter.SaveOptionLog("获取加密锁时钟失败!!使用系统时间替代:" + ex.Message);
                return(DateTime.Now);
            }
        }
Beispiel #14
0
        /// <summary>
        /// 设置新的有效期
        /// </summary>
        /// <param name="mValidDate">新的有效期</param>
        /// <returns>true=设置成功;false=设置失败</returns>
        public static BYHX_SL_RetValue SetFeatureWords(string keyword)
        {
            byte[] keys = Encoding.ASCII.GetBytes(keyword);            //DonglekeyWordToBuffer(keyword);

            IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
            IO_PACKAGE stDataPkgOut = new IO_PACKAGE();

            stDataPkgIn.tag  = (byte)SubFunction_ID.SetFeatureWords;
            stDataPkgIn.len  = (byte)keys.Length;
            stDataPkgIn.buff = keys;

            stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut);

#if DEBUG
            if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
            {
                MessageBox.Show("Set ValidDate failed!");
            }
#endif
            return(ret);
        }
Beispiel #15
0
        /// <summary>
        /// 设置新的加密数
        /// </summary>
        /// <param name="EncryptNum">新的加密数</param>
        /// <returns>true=设置成功;false=设置失败</returns>
        public static BYHX_SL_RetValue GetFeatureWords(ref byte[] fw)
        {
            IO_PACKAGE stDataPkgIn  = new IO_PACKAGE();
            IO_PACKAGE stDataPkgOut = new IO_PACKAGE();

            stDataPkgIn.tag  = (byte)SubFunction_ID.GetFeatureWords;
            stDataPkgIn.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgIn.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            stDataPkgOut.len  = IO_PACKAGE_BUFF_SIZE;
            stDataPkgOut.buff = new byte[IO_PACKAGE_BUFF_SIZE];

            BYHX_SL_RetValue ret = ExecuteExeById(stDataPkgIn, ref stDataPkgOut);

#if DEBUG
            if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
            {
                MessageBox.Show("write EncryptNum failed!");
            }
#endif
            fw = new byte[16];
            Buffer.BlockCopy(stDataPkgOut.buff, 0, fw, 0, fw.Length);
            return(ret);
        }
Beispiel #16
0
        public void SendPrintData()
        {
            int hPrinterPort = 0;

            try
            {
                bool isFirstRIP = false;
                _bSendExited = _bReadExited = false;
                bool bFileHeader = true;
                while (_cachList.Count < 2048 && !_bReadExited) //缓存一定数量才开始打印16M
                {
                    Thread.Sleep(100);
                }

                while ((hPrinterPort = CoreInterface.Printer_Open()) == 0)
                {
                    Thread.Sleep(100);
                }

                SPrinterSetting ssNew      = this.m_IPrinterChange.GetAllParam().PrinterSetting;
                SJobSetting     sjobseting = new SJobSetting();
                if (UIFunctionOnOff.SupportPrintMode)
                {
                    //todo
                }
                if (UIFunctionOnOff.SupportMediaMode)
                {
                    //todo
                }
                LayoutSetting curLayoutSetting = new LayoutSetting();

                int layoutIdx = 0;
                if (CoreInterface.LayoutIndex >= 0)
                {
                    layoutIdx = CoreInterface.LayoutIndex;
                }

                if (NewLayoutFun.GetLayoutSetting(layoutIdx, ref curLayoutSetting))
                {
                    ssNew.layoutSetting = curLayoutSetting;
                }
                if (ssNew.sExtensionSetting.AutoRunAfterPrint)
                {
                    ssNew.sBaseSetting.fYAddDistance = ssNew.sExtensionSetting.fRunDistanceAfterPrint;
                    ssNew.sExtensionSetting.bEnableAnotherUvLight = ssNew.sExtensionSetting.fRunDistanceAfterPrint > 0;
                    CoreInterface.SetPrinterSetting(ref ssNew, false); //打印结束后继续扫描一段距离生效
                }
                //打印前设置JobSetting
                sjobseting.bReversePrint = ssNew.sBaseSetting.bReversePrint;
                CoreInterface.SetSJobSetting(ref sjobseting);



                LogWriter.WriteLog(new string[] { "[RIP]Printer open" }, true);
                int cbBytesRead = 0;
                isFirstRIP = true;
                while (true)
                {
                    if (_cachList.Count > 0)
                    {
                        MyStruct data = new MyStruct();
                        if (!_cachList.TryDequeue(out data))
                        {
                            continue;
                        }
                        byte[] chRequest = data.buf;
                        cbBytesRead = data.buflen;
#if ADD_HARDKEY
                        {
                            int    subsize   = 32;
                            byte[] lastValue = chRequest;
                            if (bFileHeader)
                            {
                                bFileHeader = false;
                                lastValue   = new byte[BUFSIZE + 8];


                                byte[] mjobhead = new byte[subsize];
                                byte[] retValue = new byte[subsize + Marshal.SizeOf(typeof(int))];
                                for (int j = 0; j < BYHXSoftLock.JOBHEADERSIZE / subsize; j++)
                                {
                                    Buffer.BlockCopy(chRequest, j * mjobhead.Length, mjobhead, 0, mjobhead.Length);
                                    BYHX_SL_RetValue ret = BYHXSoftLock.CheckValidDateWithData(mjobhead, ref retValue);
                                    Buffer.BlockCopy(retValue, 0, lastValue, j * retValue.Length, retValue.Length);
                                }

                                Buffer.BlockCopy(chRequest, BYHXSoftLock.JOBHEADERSIZE, lastValue,
                                                 BYHXSoftLock.JOBHEADERSIZE + 8, chRequest.Length - BYHXSoftLock.JOBHEADERSIZE);
                                int sendBytes = CoreInterface.Printer_Send(hPrinterPort, lastValue, cbBytesRead + 8);
                                Debug.Assert(sendBytes == cbBytesRead + 8);
                            }
                            else
                            {
                                CoreInterface.Printer_Send(hPrinterPort, chRequest, cbBytesRead);
                            }
                        }
#else
                        {
                            if (isFirstRIP)
                            {
                                string strLog            = "";
                                int    nVersion          = 0;
                                byte   bReversePrint     = 0;
                                byte   nPrintLayerNum    = 0;
                                int    printmodePerLayer = 0;
                                isFirstRIP = false;

                                if (cbBytesRead >= 84)
                                {
                                    for (int i = 0; i < 84; i++)
                                    {
                                        strLog += Convert.ToString(chRequest[i], 2) + ",";
                                    }

                                    LogWriter.WriteLog(new string[] { "[RIP]" + strLog }, true);


                                    nVersion = BitConverter.ToInt32(chRequest, 4);
                                    if (nVersion == 4)
                                    {
                                        bReversePrint = chRequest[55];
                                        //nPrintLayerNum = chRequest[56];
                                        //printmodePerLayer = BitConverter.ToInt32(chRequest, 57);

                                        //PrinterSettingHelper.SetPropertyWhiteInkLayer(
                                        //    ref m_IPrinterChange.GetAllParam().PrinterSetting, bReversePrint,
                                        //    nPrintLayerNum,
                                        //    (uint) printmodePerLayer);
                                        CoreInterface.SetPrinterSetting(ref m_IPrinterChange.GetAllParam()
                                                                        .PrinterSetting);
                                        //isSetWhiteFormPrt = true;

                                        sjobseting = new SJobSetting();
                                        sjobseting.bReversePrint = bReversePrint == 1;
                                        CoreInterface.SetSJobSetting(ref sjobseting);
                                    }
                                    else if (nVersion == 6)
                                    {
                                        bReversePrint = chRequest[71];

                                        sjobseting = new SJobSetting();
                                        sjobseting.bReversePrint = bReversePrint == 1;
                                        CoreInterface.SetSJobSetting(ref sjobseting);
                                    }
                                }
                            }

                            //#else
                            CoreInterface.Printer_Send(hPrinterPort, chRequest, cbBytesRead);
                        }
#endif
                    }

                    if (_cachList.Count == 0 && _bReadExited)
                    {
                        LogWriter.WriteLog(
                            new string[]
                        {
                            string.Format("[SendPrintData]  CachList.Count = {0};bReadExited={1}", _cachList.Count,
                                          _bReadExited)
                        }, true);
                        break;
                    }

                    if (_cachList.Count == 0)
                    {
                        LogWriter.WriteLog(
                            new string[]
                        {
                            string.Format("[SendPrintData]  CachList.Count = {0};waittime={1}", _cachList.Count, 10)
                        }, true);
                        Thread.Sleep(10);
                    }
                }

                CoreInterface.Printer_Close(hPrinterPort);
                _bSendExited = true;
                SExtensionSetting extensionSetting = ssNew.sExtensionSetting;
                if (extensionSetting.fRunDistanceAfterPrint > 0 && extensionSetting.BackBeforePrint)
                {
                    while (true)
                    {
                        JetStatusEnum status = CoreInterface.GetBoardStatus();
                        if (status == JetStatusEnum.Ready)
                        {
                            int speed             = ssNew.sMoveSetting.nYMoveSpeed;
                            MoveDirectionEnum dir = MoveDirectionEnum.Up;
                            int len = Convert.ToInt32(extensionSetting.fRunDistanceAfterPrint * m_IPrinterChange.GetAllParam().PrinterProperty.fPulsePerInchY);
                            CoreInterface.MoveCmd((int)dir, len, speed);
                            break;
                        }
                        Thread.Sleep(100);
                    }
                }
            }
            catch (Exception e)
            {
                LogWriter.WriteLog(
                    new string[]
                {
                    string.Format("[SendPrintData]  CachList.Count = {0};Exception={1}", _cachList.Count, e.Message)
                }, true);
                if (hPrinterPort != 0)
                {
                    CoreInterface.Printer_Close(hPrinterPort);
                    _bSendExited = true;
                }
            }
        }
Beispiel #17
0
        public void FirstReadyShakeHand()
        {
#if ADD_HARDKEY
            ushort Vid, Pid;
            Vid = Pid = 0;

            bool   result = true;
            byte[] infos  = new byte[19];
            if (CoreInterface.GetProductID(ref Vid, ref Pid) == 0)
            {
                result = false;
            }
            else
            {
                BYHX_SL_RetValue ret = BYHXSoftLock.GetDongleInfo(ref infos, BYHXSoftLock.FIRST_S4_INDEX);
                if (ret != BYHX_SL_RetValue.SUCSESS)
                {
                    result = false;
                }
                else
                {
                    ConvertAToB(infos);
                    ushort dogVid = BitConverter.ToUInt16(infos, 16);
                    //if ((Vid&0x7F) != (infos[16] & 0x7f))//模糊检查
                    //if (Vid != (infos[16] & 0x7f)) //BUG
                    if (Vid != dogVid) //严格检查
                    {
                        result = false;
#if LIYUUSB
                        if (infos[16] == 7 && Vid == (ushort)VenderID.LOTUS)
                        {
                            result = true;
                        }
#endif
                        if ((Vid & 0x807F) == (dogVid & 0x807f))
                        {
                            //if ((Vid & 0x7F) == (ushort)VenderID.GONGZENG)
                            result = true;
                        }
                    }
                }
            }
            if (result != bMatchVender)
            {
                bMatchVender = result;
//				m_IPrinterChange.OnPrinterStatusChanged(JetStatusEnum.PowerOff);
            }
            if (result == false)
            {
                MessageBox.Show(ResString.GetResString("EncryptDog_VidNotMatch"), ResString.GetProductName(), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

#if false
            //This is for Dog Check Board
            byte[] info = new byte[64];
            info[0] = (byte)(Vid & 0xff);
            info[1] = (byte)((Vid >> 8) & 0xff);
            info[2] = (byte)(Pid & 0xff);
            info[3] = (byte)((Pid >> 8) & 0xff);
            ret     = BYHXSoftLock.SetProductInfo(info, 32);
            if (ret != BYHX_SL_RetValue.SUCSESS)
            {
#if DEBUG
                //if (stDataPkgOut.tag != S4_API.S4_SUCCESS)
                {
                    MessageBox.Show("SetProductInfo Run failed!");
                }
#endif
            }
#endif
            //infos[16] = (byte)(Vid & 0xff);
            CoreInterface.SetDspPwmInfo(infos, infos.Length);
#endif
        }