unsafe protected bool TransmitData(string Data, uint deviceType, uint deviceIndex, uint cANIndex, uint frameid)
        {
            bool IsTransmitSuccess = false;

            if (IsOpen)
            {
                VCI_CAN_OBJ sendobj = new VCI_CAN_OBJ()
                {
                    SendType   = 2,       //=0时为正常发送,=1时为单次发送,=2时为自发自收,=3时为单次自发自收,只在此帧为发送帧时有意义。
                    ID         = frameid, //帧ID
                    DataLen    = 8,       //数据长度
                    RemoteFlag = 0,       //是否是远程帧
                    ExternFlag = 0,       //是否是扩展帧。
                    TimeFlag   = 1        //是否使用时间标识,为 1 时 TimeStamp 有效,TimeFlag 和 TimeStamp 只在此帧为接收帧时有意义
                };

                string      strdata  = Data;
                int         len      = (strdata.Length + 1) / 3;
                List <byte> bytelist = new List <byte>();
                for (int t = 0; t < len; t++)
                {
                    //bytelist.Add(Convert.ToByte("0x" + strdata.Substring(t * 3, 2), 16));
                    bytelist        = ConvertFrom.HexstringToBytesArray(Data);
                    sendobj.Data[t] = bytelist[t];
                }
                if (VCI_Transmit(deviceType, deviceIndex, cANIndex, ref sendobj, 2) == 1)
                {
                    IsTransmitSuccess = true;
                }
                return(IsTransmitSuccess);
            }
            return(IsTransmitSuccess);
        }
Exemple #2
0
 public GenericStdFunctionProcess(DefaultValue defaultValue, ProcessAction <T> processAction, ConvertFrom <T> convertFrom, bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal)
     : base(inInput, inInternal, outOutput, outInternal)
 {
     this.defaultValue  = defaultValue;
     this.processAction = processAction;
     this.convertFrom   = convertFrom;
 }
Exemple #3
0
 public GenericStdFunctionProcess(DefaultValue defaultValue, ProcessAction <T> processAction, ConvertFrom <T> convertFrom, int firstInput, int lastInput, int output)
     : base(firstInput, lastInput, output)
 {
     this.defaultValue  = defaultValue;
     this.processAction = processAction;
     this.convertFrom   = convertFrom;
 }
Exemple #4
0
 public GenericStdFunctionProcess(DefaultValue defaultValue, ProcessAction <T> processAction, bool[] inInput, bool[] inInternal, bool[] outOutput, bool[] outInternal)
     : base(inInput, inInternal, outOutput, outInternal)
 {
     this.defaultValue  = defaultValue;
     this.processAction = processAction;
     this.convertFrom   = delegate(IValueStructure value) { return((T)value); };
 }
Exemple #5
0
 public GenericStdFunctionProcess(DefaultValue defaultValue, ProcessAction <T> processAction, int firstInput, int lastInput, int output)
     : base(firstInput, lastInput, output)
 {
     this.defaultValue  = defaultValue;
     this.processAction = processAction;
     this.convertFrom   = delegate(IValueStructure value) { return((T)value); };
 }
Exemple #6
0
        public override string Read(SerialPort serialPort)
        {
            byte[] tempdata = new byte[serialPort.ReadBufferSize];
            int    i        = serialPort.Read(tempdata, 0, tempdata.Length);

            return(ConvertFrom.ByteArrayToString(tempdata, Encoding.ASCII).Replace("\0", "").Replace("\r\n", ""));
        }
Exemple #7
0
 public GenericStdFunctionProcess(DefaultValue defaultValue, ConvertFrom <T> convertFrom, ProcessAction <T> processAction, int count)
     : base(0, count > 0 ? count - 1 : 0, 0)
 {
     this.defaultValue  = defaultValue;
     this.processAction = processAction;
     this.convertFrom   = convertFrom;
 }
Exemple #8
0
        public IMerchantPayment FindPayment(string purse, long number,
                                            Contracts.BasicTypes.PaymentNumberKind numberKind)
        {
            if (null == purse)
            {
                throw new ArgumentNullException(nameof(purse));
            }

            var request = new MerchantOperationObtainer(Purse.Parse(purse), number,
                                                        ConvertFrom.ContractTypeToApiType(numberKind))
            {
                Initializer = CreateInitializer(purse)
            };

            MerchantOperation response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            var merchantPayment = new MerchantPayment(response.TransferId, response.InvoiceId,
                                                      response.Amount, response.CreateTime.ToUniversalTime(), response.Description, response.SourceWmId,
                                                      response.SourcePurse.ToString())
            {
                IsCapitaller  = response.CapitallerFlag,
                IsEnum        = response.EnumFlag,
                IPAddress     = response.IpAddress,
                TelepatPhone  = response.TelepatPhone,
                PaymerNumber  = response.PaymerNumber,
                PaymerEmail   = response.PaymerEmail,
                CashierNumber = response.CashierNumber,
                CashierDate   = response.CashierDate?.ToUniversalTime(),
                CashierAmount = response.CashierAmount,
            };


            if (null != response.TelepatMethod)
            {
                merchantPayment.TelepatMethod = ConvertFrom.ApiTypeToContractType(response.TelepatMethod.Value);
            }

            if (XmlInterfaces.BasicObjects.PaymerType.None != response.PaymerType)
            {
                merchantPayment.PaymerType = ConvertFrom.ApiTypeToContractType(response.PaymerType);
            }

            // TODO [L] Расшифровать тип e-invoicing платежа.
            if (null != response.SdpType)
            {
                merchantPayment.InvoicingMethod = (byte)response.SdpType.Value;
            }

            return(merchantPayment);
        }
Exemple #9
0
 public override void WriteCommand(SerialPort serialPort, string command)
 {
     if (serialPort.IsOpen)
     {
         List <byte> list = ConvertFrom.HexstringToBytesArray(command);
         serialPort.Write(list.ToArray(), 0, list.Count);
     }
 }
Exemple #10
0
        public override string Read(SerialPort serialPort)
        {
            int tempdatalenth = serialPort.BytesToRead;

            byte[] tempbytes = new byte[tempdatalenth];
            serialPort.Read(tempbytes, 0, tempdatalenth);
            return(ConvertFrom.ArrayToHexString(tempbytes));
        }
Exemple #11
0
 public override bool TrySetMember(SetMemberBinder binder, object value)
 {
     if (!IsObject)
     {
         return(false);
     }
     _data.Dictionary[binder.Name] = ConvertFrom.Convert(value);
     return(true);
 }
Exemple #12
0
 public void writesp(string data)
 {
     if (mySerialPort.IsOpen)
     {
         List <byte> bytelist = ConvertFrom.HexstringToBytesArray(data);
         mySerialPort.Write(bytelist.ToArray(), 0, bytelist.Count);
     }
     else
     {
         MessageBox.Show("串口未打开!");
     }
 }
Exemple #13
0
        static PlatformConfig()
        {
            Configuration.Add("x86 standard", new Platform
            {
                Description     = "x86 Standard (32-bit, little endian, double)",
                BigEndian       = false,       // 1 = little endian
                IntegerSize     = 4,           // (data type sizes in bytes)
                SizeT           = 4,
                InstructionSize = 4,
                NumberSize      = 8,           // this & integral identifies the
                IsFloatingPoint = true,        // (0) type of lua_Number
                NumberType      = "double",    // used for lookups
            });
            Configuration.Add("big endian int", new Platform
            {
                Description     = "(32-bit, big endian, int)",
                BigEndian       = true,
                IntegerSize     = 4,
                SizeT           = 4,
                InstructionSize = 4,
                NumberSize      = 4,
                IsFloatingPoint = false,
                NumberType      = "int",
            });
            Configuration.Add("amd64", new Platform
            {
                Description     = "AMD64 (64-bit, little endian, double)",
                BigEndian       = false,
                IntegerSize     = 4,
                SizeT           = 8,
                InstructionSize = 4,
                NumberSize      = 8,
                IsFloatingPoint = true,
                NumberType      = "double",
            });
            // you can add more platforms here

            LuaNumberID.Add("80", "double");         // IEEE754 double
            LuaNumberID.Add("40", "single");         // IEEE754 single
            LuaNumberID.Add("41", "int");            // int
            LuaNumberID.Add("81", "long long");      // long long

            ConvertFrom.Add("double", fromDouble);
            ConvertFrom.Add("single", fromSingle);
            ConvertFrom.Add("int", fromInt);
            ConvertFrom.Add("long long", fromInt);

            ConvertTo.Add("double", toDouble);
            ConvertTo.Add("int", toInt);
            ConvertTo.Add("single", toSingle);
            ConvertTo.Add("long long", toInt);
        }
        private void Sendbut_Click(object sender, EventArgs e)
        {
            //Displytb.Text = "";
            //CANAbstract USBCAN2I = new USBCAN_2I();
            //Displytb.Text = CANG(USBCAN2I, Datatb.Text);
            //List<byte> sbytet = new List<byte> { 160, 151, 12, 12, 19, 255, 01, 00, 02, 03 };
            //Displytb.Text = ConvertFrom.ByteArrayToHexString(sbytet.ToArray());



            //Displytb.Text = ConvertFrom.ByteArrayToString(new byte[] { 48, 49, 50, 51, 52, 53, 65, 66, 67, 68 }, Encoding.ASCII);
            string btadd = "21 62 09 00 00 0D E9 08 22 62 A5 B7 00 00 00 00 22 62 A5 B7 00 00 00 00";
            string ssss  = substrings(btadd);

            btadd.Substring(0);
            string ss = ConvertFrom.HexStringToString("ec a0 45 2d 43 61 72 78 ec a0 45 2d 43 61 72 78", Encoding.ASCII);

            Displytb.Text = ss;
            //77B 91 70 35 00 31 39 30 33


            //string ss = "31 39 30 33 32 36 31 38 30 33 32 38 31 30 31 31 34 2E 31 32 36 34 4E 30 30 30 33 30 2E 34 37 38 30 45 30 30 2E 38 30 30 30 2E 38 30 30 30 30 33 35 00 00 00";

            //Displytb.Text += ConvertFrom.HexStringToString(ss, Encoding.ASCII);

            CANAbstract USBCAN2I = new USBCAN_2I();

            CANG(USBCAN2I, Datatb.Text);


            //test test1 = new test();
            //test1.TestItem.Add("123", "test1");
            //test1.TestItem.Add("345", "test2");
            //test1.TestItem.Add("456", "test3");

            //test1.CANIndex = 0;B
            //string s = JsonHelper.ObjToJsonString(test1);
            //WriteLog.WriteLogFile(s);
            //test test2 = JsonHelper.JsonToObj<test>(s);
            ////test test1 = new test();
            //test1 = SimpleFactory.Create<test>();
            //foreach (var item in test1.TestItem)
            //{
            //    string key = item.Key;
            //    string value = item.Value;
            //}
        }
        public IEnumerable <IOutgoingInvoice> SelectOutgoingInvoices(string purse, DateTime fromTime, DateTime toTime,
                                                                     bool fresh = false)
        {
            var request =
                new OutgoingInvoiceFilter(Purse.Parse(purse), fromTime, toTime)
            {
                Initializer = Session.AuthenticationService.ObtainInitializer()
            };

            OutgoingInvoiceRegister response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            var outgoingInvoices = response.OutgoingInvoiceList.Select(oi =>
            {
                var outgoingInvoice = new BusinessObjects.OutgoingInvoice(oi.PrimaryId, oi.SecondaryId, oi.OrderId,
                                                                          oi.SourceWmId,
                                                                          oi.TargetPurse.ToString(), oi.Amount, oi.Description, oi.Expiration,
                                                                          ConvertFrom.ApiTypeToContractType(oi.InvoiceState), oi.CreateTime, oi.UpdateTime)
                {
                    Address = oi.Address
                };

                if (oi.Period > 0)
                {
                    outgoingInvoice.ProtectionPeriod = oi.Period;
                }

                if (oi.TransferId > 0)
                {
                    outgoingInvoice.TransferId = oi.TransferId;
                }

                return(outgoingInvoice);
            })
                                   .OrderByDescending(oi => oi.UpdateTime)
                                   .ToList();

            return(outgoingInvoices);
        }
Exemple #16
0
        /// <summary>
        /// 変換可能か確認します。
        /// </summary>
        /// <returns>変換可能な場合はtrue,不可能な場合はfalse</returns>
        public bool TryConvertTest(string path)
        {
            ConvertFrom         basecon = instConvertType;
            bool                isClear = true;
            IOtherDataConverter iodc;

            if (instConvertType == ConvertFrom.JaneStyle)
            {
                iodc = new JaneConverter(path);
                try { iodc.ConvertCookie(); }
                catch { isClear = false; }
            }
            else if (instConvertType == ConvertFrom.V2C)
            {
                iodc = new V2CConverter(path);
                try { iodc.ConvertCookie(); }
                catch { isClear = false; }
            }
            else
            {
                isClear = false;
            }
            if (isClear)
            {
                return(true);
            }
            else
            {
                //bool isSecondClear = true;
                if (basecon == 0)
                {
                }
                else if (instConvertType == ConvertFrom.V2C)
                {
                    iodc = new JaneConverter(path);
                    try { iodc.ConvertCookie(); }
                    catch { isClear = false; }
                }
                else if (instConvertType == ConvertFrom.JaneStyle)
                {
                    iodc = new V2CConverter(path);
                    try { iodc.ConvertCookie(); }
                    catch { isClear = false; }
                }
            }
            throw new NotImplementedException();
        }
Exemple #17
0
        public IEnumerable <ITransfer> SelectTransfers(string purse, DateTime fromTime, DateTime toTime)
        {
            if (null == purse)
            {
                throw new ArgumentNullException(nameof(purse));
            }

            var request = new TransferFilter(Purse.Parse(purse), fromTime, toTime)
            {
                Initializer = Session.AuthenticationService.ObtainInitializer()
            };

            TransferRegister response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            return(response.TransferList.Select(t =>
            {
                var transfer = new BusinessObjects.Transfer(Session.CurrentIdentifier, t.PrimaryId, t.SecondaryId,
                                                            t.SourcePurse.ToString(), t.TargetPurse.ToString(), t.Amount,
                                                            t.Commission, ConvertFrom.ApiTypeToContractType(t.TransferType), t.Description, t.Partner,
                                                            t.Rest,
                                                            t.CreateTime.ToUniversalTime(), t.UpdateTime.ToUniversalTime())
                {
                    InvoiceId = t.InvoiceId,
                    OrderId = t.OrderId,
                    PaymentId = t.PaymentId,
                    ProtectionPeriod = t.Period,
                    Locked = t.IsLocked,
                    Description = !string.IsNullOrEmpty(t.Description) ? t.Description : "[empty]"
                };


                return transfer;
            }));
        }
        private static bool Satellite(string value)
        {
            List <byte> listvar        = ConvertFrom.HexstringToBytesArray(value);
            List <byte> Satelliteindex = new List <byte>();
            List <int>  Strength       = new List <int>();
            var         newlist        = listvar.Select((b, index) => new { index, b });//投影出index

            foreach (var item in newlist)
            {
                if (item.index % 2 == 1)
                {
                    Strength.Add(item.b);
                }
                else
                {
                    Satelliteindex.Add(item.b);
                }
            }
            return(Strength.Where(i => i > 21).Count() >= 7);
        }
Exemple #19
0
        public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
        {
            var internalObject = ConvertFrom.Convert(value);

            if (IsObject)
            {
                _data.Dictionary[(string)indexes[0]] = internalObject;
                return(true);
            }
            var index = (int)indexes[0];

            if (index < _data.Array.Count)
            {
                _data.Array[index] = internalObject;
            }
            else
            {
                _data.Array.Add(internalObject);
            }
            return(true);
        }
Exemple #20
0
 private void MySerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
 {
     if (mySerialPort.IsOpen)
     {
         strlist.Clear();
         int tempdatalenth = mySerialPort.BytesToRead;
         tempbytes = new byte[tempdatalenth];
         mySerialPort.Read(tempbytes, 0, tempdatalenth);
         strlist.Add(ConvertFrom.ToHexString(tempbytes));
     }
     if (tempbytes.Length > 0)
     {
         foreach (var item in strlist)
         {
             showMessageEvent(item);
         }
     }
     else
     {
         return;
     }
 }
Exemple #21
0
 public GenericStdParallelProcess(ProcessItem <Tin, Tout> processItem, int firstInput, int firstOutput, int count, bool inputIsInternal, bool outputIsInternal)
     : base(firstInput, firstOutput, count, inputIsInternal, outputIsInternal)
 {
     this.processItem = processItem;
     this.convertFrom = delegate(IValueStructure value) { return((Tin)value); };
 }
Exemple #22
0
 /// <summary>
 /// 予測される変換元を指定してこのクラスの新しいインスタンスを初期化します
 /// </summary>
 /// <param name="ct">予測されるタイプ</param>
 public CheckCanConvert(ConvertFrom ct)
 {
     this.instConvertType = ct;
 }
        public ITrustConfirmationInstruction RequestTrust(IOriginalExpressTrust originalExpressTrust)
        {
            if (null == originalExpressTrust)
            {
                throw new ArgumentNullException(nameof(originalExpressTrust));
            }

            XmlInterfaces.BasicObjects.ConfirmationType confirmationType =
                ConvertFrom.ContractTypeToApiType(originalExpressTrust.ConfirmationType);

            ExpressTrustRequest request;

            switch (originalExpressTrust.Identifier.Type)
            {
            case ExtendedIdentifierType.Phone:
                var phone = originalExpressTrust.Identifier.Value;

                if (!phone.StartsWith("+"))
                {
                    phone = $"+{phone}";
                }

                request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse),
                                                  (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit,
                                                  (Amount)originalExpressTrust.MonthLimit, Phone.Parse(phone),
                                                  confirmationType);
                break;

            case ExtendedIdentifierType.WmId:
                request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse),
                                                  (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit,
                                                  (Amount)originalExpressTrust.MonthLimit, WmId.Parse(originalExpressTrust.Identifier.Value),
                                                  confirmationType);
                break;

            case ExtendedIdentifierType.Email:
                MailAddress mailAddress = new MailAddress(originalExpressTrust.Identifier.Value);

                request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse),
                                                  (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit,
                                                  (Amount)originalExpressTrust.MonthLimit, mailAddress,
                                                  confirmationType);
                break;

            case ExtendedIdentifierType.Purse:
                request = new ExpressTrustRequest(Purse.Parse(originalExpressTrust.StorePurse),
                                                  (Amount)originalExpressTrust.DayLimit, (Amount)originalExpressTrust.WeekLimit,
                                                  (Amount)originalExpressTrust.MonthLimit, Purse.Parse(originalExpressTrust.Identifier.Value),
                                                  confirmationType);
                break;

            default:
                throw new InvalidOperationException("originalExpressTrust.Identifier.Type == " +
                                                    originalExpressTrust.Identifier.Type);
            }

            request.DayLimit   = (Amount)originalExpressTrust.DayLimit;
            request.WeekLimit  = (Amount)originalExpressTrust.WeekLimit;
            request.MonthLimit = (Amount)originalExpressTrust.MonthLimit;

            request.Initializer = Session.AuthenticationService.ObtainInitializer();

            ExpressTrustResponse response;

            try
            {
                response = request.Submit();
            }
            catch (WmException exception)
            {
                throw new ExternalServiceException(exception.Message, exception);
            }

            var instruction = new TrustConfirmationInstruction(response.Reference,
                                                               ConvertFrom.ApiTypeToContractType(response.ConfirmationType), response.Info, response.SmsReference);

            return(instruction);
        }
Exemple #24
0
 internal JsonObject(object obj)
 {
     _data = ConvertFrom.Convert(obj);
 }
        unsafe protected string ReceiveData(uint FilterID, int timeout, uint deviceType, uint deviceIndex, uint cANIndex)
        {
            string dataStrList = $"读取{FilterID}失败!";

            uint num = VCI_GetReceiveNum(deviceType, deviceIndex, cANIndex);

            if (num > 0)
            {
                var         cancelTokenSource = new CancellationTokenSource(timeout);
                List <byte> Data_Frame        = new List <byte>();
                if (IsOpen)                                            //是否打开CAN
                {
                    while (!cancelTokenSource.IsCancellationRequested) //设置读取超时
                    {
                        #region .net
                        //UInt32 con_maxlen = 50;
                        //int size = Marshal.SizeOf(typeof(VCI_CAN_OBJ));
                        //IntPtr pt = Marshal.AllocHGlobal(size * (int)con_maxlen);
                        //uint result = VCI_Receive(deviceType, deviceIndex, cANIndex, pt, con_maxlen, 100);
                        //for (uint i = 0; i < result; i++)
                        //{
                        //    VCI_CAN_OBJ obj = (VCI_CAN_OBJ)Marshal.PtrToStructure((IntPtr)((uint)pt + i * size), typeof(VCI_CAN_OBJ));
                        //    if (obj.ID == FilterID)
                        //    {
                        //        if (obj.RemoteFlag == 0)
                        //        {
                        //            List<uint> temp = new List<uint>();
                        //            byte len = (byte)(obj.DataLen % 9);
                        //            byte j = 0;
                        //            if (j++ < len)
                        //            {
                        //                for (int d = 0; d < len; d++)
                        //                {
                        //                    temp.Add(obj.Data[d]);
                        //                }
                        //                temp.RemoveRange(0, 2);//去除CAN协议头俩位数据(东峻专用)
                        //                uintlist.AddRange(temp);
                        //            }
                        //        }

                        //    }
                        #endregion

                        #region 指针

                        VCI_CAN_OBJ[] canObj = new VCI_CAN_OBJ[100];
                        fixed(VCI_CAN_OBJ *pcanObj = canObj)
                        {
                            VCI_CAN_OBJ *pNewcanObj = pcanObj;
                            int          szie       = sizeof(VCI_CAN_OBJ) * canObj.Length;
                            uint         result     = VCI_Receive(deviceType, deviceIndex, cANIndex, pcanObj, 100, 400);

                            for (uint i = 0; i < result; i++)
                            {
                                if (pNewcanObj->ID == FilterID)      //判断是否为过滤的ID
                                {
                                    if (pNewcanObj->RemoteFlag == 0) //判断是否为远程幁
                                    {
                                        List <byte> temp  = new List <byte>();
                                        byte *      pdata = pNewcanObj->Data + 2;//每一帧的前两位去掉(帧头和长度)
                                        for (int t = 0; t < 6; t++)
                                        {
                                            temp.Add(*pdata);
                                            pdata++;
                                        }
                                        Data_Frame.AddRange(temp);
                                    }
                                }
                                pNewcanObj++;
                            }
                        }

                        #endregion

                        #region old
                        //string dataStr = string.Empty;
                        //dataStr += Convert.ToString(obj.ID, 16);
                        //if (obj.RemoteFlag == 0)
                        //{
                        //    //dataStr += " 数据: ";
                        //    byte len = (byte)(obj.DataLen % 9);
                        //    byte j = 0;

                        //    if (j++ < len)
                        //    {
                        //        for (int d = 0; d < len; d++)
                        //        {

                        //            dataStr += " " + string.Format("{0:X2}", obj.Data[d]);

                        //        }
                        //    }
                        //    if (obj.ID == FilterID)//0x77B
                        //    {
                        //        //dataStringList.Add(dataStr.ToUpper());
                        //    }
                        //}
                        ////Console.WriteLine(dataStr.ToUpper());



                        //if (dataStringList.Count > 0)
                        //{
                        //    foreach (var item in dataStringList)
                        //    {
                        //        dataStrList += item;
                        //    }
                        //    return dataStrList;
                        //}//判断是否有 指定的数据
                        //else
                        //{
                        //    dataStringList = null;
                        //    dataStrList = "";
                        //    //ReceiveData(FilterID, timeout);
                        //    return $"CAN1 读取帧ID: {Convert.ToString(FilterID, 16).ToUpper()} 失败!";
                        //}



                        //return $"CAN1 读取帧ID: {Convert.ToString(FilterID, 16).ToUpper()} 失败!";
                        #endregion
                    }
                }
                if (Data_Frame.Count > 0)
                {
                    Data_Frame.RemoveRange(0, 2);
                    return(dataStrList = ConvertFrom.ToHexString(Data_Frame.ToArray()));
                }
            }
            return(dataStrList);
        }
Exemple #26
0
 public GenericStdParallelProcess(ProcessItem <Tin, Tout> processItem, int count)
     : base(0, 0, count, false, false)
 {
     this.processItem = processItem;
     this.convertFrom = delegate(IValueStructure value) { return((Tin)value); };
 }
Exemple #27
0
 public GenericStdParallelProcess(ProcessItem <Tin, Tout> processItem, ConvertFrom <Tin> convertFrom, int count)
     : base(0, 0, count, false, false)
 {
     this.processItem = processItem;
     this.convertFrom = convertFrom;
 }
Exemple #28
0
 public static void Serialize(object obj, TextWriter writer, int maxDepth)
 {
     Serialize(ConvertFrom.Convert(obj), writer, maxDepth);
 }
Exemple #29
0
 public GenericStdParallelProcess(ProcessItem <Tin, Tout> processItem, ConvertFrom <Tin> convertFrom, int firstInput, int firstOutput, int count, bool inputIsInternal, bool outputIsInternal)
     : base(firstInput, firstOutput, count, inputIsInternal, outputIsInternal)
 {
     this.processItem = processItem;
     this.convertFrom = convertFrom;
 }
        unsafe protected string ReceiveData(UInt32 FilterID, int timeout, uint deviceType, uint deviceIndex, uint cANIndex)
        {
            string        dataStrList       = "读取失败!";
            List <string> dataStringList    = new List <string>();
            var           cancelTokenSource = new CancellationTokenSource(timeout);

            if (IsOpen) //是否打开CAN
            {
                List <uint> Data_Frame = new List <uint>();
                while (!cancelTokenSource.IsCancellationRequested)//设置读取超时
                {
                    //uint num = VCI_GetReceiveNum(deviceType, deviceIndex, cANIndex);
                    uint   con_maxlen = 100;
                    int    size       = Marshal.SizeOf(typeof(VCI_CAN_OBJ));                                 //获取结构体占用空间大小
                    IntPtr pt         = Marshal.AllocHGlobal(size * (Int32)con_maxlen);                      //声明一个同样大小的空间的指针或句柄
                    UInt32 result     = VCI_Receive(deviceType, deviceIndex, cANIndex, pt, con_maxlen, 100); //返回最大100幁数据
                    for (UInt32 i = 0; i < result; i++)
                    {
                        VCI_CAN_OBJ obj = (VCI_CAN_OBJ)Marshal.PtrToStructure((IntPtr)((uint)pt + i * size), typeof(VCI_CAN_OBJ)); //将结构体放到这个空间中
                        if (obj.ID == FilterID)                                                                                    //判断是否为过滤的ID
                        {
                            if (obj.RemoteFlag == 0)                                                                               //判断是否为远程幁
                            {
                                //Data_Frame.Add(obj.ID);
                                byte len = (byte)(obj.DataLen % 9);
                                byte j   = 0;
                                if (j++ < len)
                                {
                                    for (int d = 0; d < len; d++)
                                    {
                                        Data_Frame.Add(obj.Data[d]);
                                    }
                                }
                            }
                            dataStrList = ConvertFrom.UintArrayToHexString(Data_Frame.ToArray());
                        }
                    }
                    #region old
                    //dataStr = "帧ID: ";
                    //dataStr = Convert.ToString(obj.ID, 16);
                    //    if (obj.ID == FilterID)
                    //    {
                    //        if (obj.RemoteFlag == 0)
                    //        {
                    //            //dataStr += " 数据: ";
                    //            byte len = (byte)(obj.DataLen % 9);
                    //            byte j = 0;
                    //            if (j++ < len)
                    //            {
                    //                for (int d = 0; d < len; d++)
                    //                {
                    //                    dataStr += " " + string.Format("{0:X2}", obj.Data[d]);//01 00 00 00 00 00 00 08
                    //                }
                    //            }
                    //            dataStringList.Add(dataStr.ToUpper());
                    //        }
                    //    }
                    //    //Console.WriteLine(dataStr.ToUpper());
                    //}


                    //if (dataStringList.Count > 0)
                    //{
                    //    foreach (var item in dataStringList)
                    //    {
                    //        dataStrList += item + "\r\n";
                    //    }
                    //    return dataStrList;
                    //}//判断是否有 指定的数据
                    //else
                    //{
                    //    dataStringList = null;
                    //    dataStrList = "";
                    //    //ReceiveData(FilterID, timeout);
                    //    return $"CAN1 读取帧ID: {Convert.ToString(FilterID, 16).ToUpper()} 失败!";
                    //}
                    #endregion
                }
                return(dataStrList);
            }

            return(dataStrList);
            //return $"CAN1 读取帧ID: {Convert.ToString(FilterID, 16).ToUpper()} 失败!";
        }