Exemplo n.º 1
0
        /*
         * /// <summary>
         * /// 根据EPC获取GTIN
         * /// </summary>
         * /// <param name="epc"></param>
         * /// <returns></returns>
         * public string GetGtin(string epc)
         * {
         *  var epcBinary = Utils.HexToBinary(epc);
         *  var partitionBinary = epcBinary.Substring(s_headerBits + s_filterValueBits,s_partitionBits);
         *  var partition = Convert.ToInt32(partitionBinary, 2).ToString();
         *  var companyPrefixAndItemReferenceBinary = epcBinary.Substring(s_headerBits + s_filterValueBits + s_partitionBits,s_gtinBits);
         *
         *  return GtinManager.ToGtin(companyPrefixAndItemReferenceBinary, partition);
         * }
         * */

        /// <summary>
        /// 根据现有EPC更改serailNumber
        /// </summary>
        /// <param name="epc">24位十六进制数据</param>
        /// <param name="serialNumber">序列号</param>
        /// <returns></returns>
        public string ToEpc(string epc, string serialNumber)
        {
            var epcBinary = Utils.HexToBinary(epc);
            //var epcBinaryWithoutSerialNumber = epcBinary.Substring(s_headerBits + s_filterValueBits + s_partitionBits + s_gtinBits, s_serialNbrBits);
            var epcBinaryWithoutSerialNumber = epcBinary.Substring(0, s_headerBits + s_filterValueBits + s_partitionBits + s_gtinBits);
            var serialNumberBinary           = Convert.ToString(long.Parse(serialNumber), 2).PadLeft(s_serialNbrBits, '0');

            return(EpcManager.BinaryEpcToHex(epcBinaryWithoutSerialNumber + serialNumberBinary));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 转成24位十六进制EPC 二进制为96位
        /// </summary>
        /// <param name="header">96 bit GTIN</param>
        /// <param name="filterValue">Selling Unit</param>
        /// <param name="partition">7 digit Mfg Nbr including number system characters</param>
        /// <param name="upc">UPC will convert to GTIN</param>
        /// <param name="serialNumber">Serial Nbr assigned by EPC Mgr for item</param>
        /// <returns></returns>
        public static string UpcConvertEpc(string header, string filterValue, string partition, string upc, string serialNumber)
        {
            var gtin               = new GtinManager(upc, partition);
            var headerBinary       = Convert.ToString(int.Parse(header), 2).PadLeft(s_headerBits, '0');
            var filterValueBinary  = Convert.ToString(int.Parse(filterValue), 2).PadLeft(s_filterValueBits, '0');
            var partitionBinary    = Convert.ToString(int.Parse(partition), 2).PadLeft(s_partitionBits, '0');
            var gtinBinary         = gtin.ToBinaryString();
            var serialNumberBinary = Convert.ToString(long.Parse(serialNumber), 2).PadLeft(s_serialNbrBits, '0');

            var epcBinary = string.Format("{0}{1}{2}{3}{4}", headerBinary, filterValueBinary, partitionBinary, gtinBinary, serialNumberBinary);

            return(EpcManager.BinaryEpcToHex(epcBinary));
        }