Beispiel #1
0
        public CDM1Unit SendCommand(CmdUnit unit)
        {
            string ret = string.Empty;

            CDM1Unit m1unit = (CDM1Unit)unit;

            switch (m1unit.DeviceCmdType)
            {
            case EDeviceCmdType.CDM1_OpenDeviceCMD:
                if (!Intial())
                {
                    m1unit.Flag    = CmdUnit.Error;
                    m1unit.RetInfo = "打开设备失败,请重试!";
                    break;
                }

                m1unit.RetInfo = CmdUnit.Success;
                break;

            case EDeviceCmdType.CDM2_getCardIDCMD:

                if (!Intial())
                {
                    m1unit.Flag    = CmdUnit.Error;
                    m1unit.RetInfo = "打开设备失败,请重试!";
                    break;
                }

                string carId = getCarID();
                if (carId != string.Empty)
                {
                    m1unit.RetInfo = getCarID();
                }
                else
                {
                    m1unit.RetInfo = "获取卡ID失败,请重试!";
                }
                break;

            case EDeviceCmdType.CDM3_closeCMD:

                if (!Intial())
                {
                    m1unit.Flag    = CmdUnit.Error;
                    m1unit.RetInfo = "关闭设备失败,请重试!";
                    break;
                }


                m1unit.RetInfo = CmdUnit.Success;

                break;

            default:
                break;
            }


            return(m1unit);
        }
Beispiel #2
0
        public static CmdUnit CreateDeviceUnit(string data)
        {
            try
            {
                string header = data.Substring(0, 5);

                if (header != "ECARD")
                {
                    return(null);
                }


                string deviceType = data.Substring(5, 5);

                //处理头文件
                switch (deviceType)
                {
                case CPU_DCH10:
                    D10CMDUnit unit = new D10CMDUnit();
                    //unit unit.Buffer = data;
                    unit.BSTR = data.Substring(5, data.Length - 5);

                    if (unit.PaseDataString(unit.BSTR))
                    {
                        return(unit);
                    }
                    break;

                case CD_M1:
                    CDM1Unit cduit = new CDM1Unit();
                    //unit unit.Buffer = data;
                    cduit.BSTR = data.Substring(5, data.Length - 5);

                    if (cduit.PaseDataString(cduit.BSTR))
                    {
                        return(cduit);
                    }
                    break;


                    break;

                default:

                    break;
                }

                return(null);
            }
            catch
            {
                throw;
            }
        }