Exemple #1
0
 public void SetField55Value(byte[] field55, int len)
 {
     if (len != 0)
     {
         SendPackage.SetArrayData(55, field55, 0, len);
     }
 }
Exemple #2
0
 private SendPackage TC_GetCurrModeAndPlanNo()
 {
     checkConntected();
       SendPackage pkg=new SendPackage(CmdType.CmdQuery,CmdClass.A,m_deviceid,new byte[]{0x04,0x82});
        m_device.Send(pkg);
       return  pkg;
 }
Exemple #3
0
        protected override void Packet()
        {
            SendPackage.SetString(0, "0100");
            //SendPackage.SetString(2, CommonData.BankCardNum); //c
            //if (!string.IsNullOrEmpty(CommonData.BankCardNum) && CommonData.BankCardNum.Length != 0)
            //{
            //    SendPackage.SetString(2, CommonData.BankCardNum);
            //}
            SendPackage.SetString(3, "310000");
            //SendPackage.SetString(4, Utility.AmountToString(CommonData.Amount.ToString()));
            SendPackage.SetString(11, GetTraceNo());
            SendPackage.SetString(12, DateTime.Now.ToString("HHmmss"));
            SendPackage.SetString(13, DateTime.Now.ToString("MMdd"));
            SendPackage.SetString(25, "92");

            //SendPackage.SetString(37, PayEntity.PayReferenceNo);
            SendPackage.SetString(41, GetTerminalNo());
            SendPackage.SetString(42, GetMerchantNo());

            SendPackage.SetArrayData(48, PacketField48());
            SendPackage.SetString(49, "195");
            //SendPackage.SetArrayData(57, PacketField57());
            //SendPackage.SetString(57, (PayEntity.PowerCardData.EF31 + PayEntity.PowerCardData.EF32).PadRight(999, ' '));
            SendPackage.SetString(60, "00" + GetBatchNo() + "000");
        }
Exemple #4
0
        protected override void Packet()
        {
            SendPackage.SetString(0, "0100");
            //if (!string.IsNullOrEmpty(PayEntity.signBankCardNo))
            //{
            //    SendPackage.SetString(2, PayEntity.signBankCardNo);
            //}
            SendPackage.SetString(3, "354000");
            SendPackage.SetArrayData(4, Encoding.Default.GetBytes("0"));
            PayEntity.PayTraceNo = GetTraceNo();
            SendPackage.SetString(11, PayEntity.PayTraceNo);
            SendPackage.SetString(12, DateTime.Now.ToString("HHmmss"));
            SendPackage.SetString(13, DateTime.Now.ToString("yyyyMMdd"));
            SendPackage.SetArrayData(18, Encoding.Default.GetBytes("STA"));
            SendPackage.SetArrayData(41, Encoding.ASCII.GetBytes(GetMerchantNo()));
            SendPackage.SetArrayData(42, Encoding.ASCII.GetBytes(GetTerminalNo()));
            SendPackage.SetString(47, PayEntity.unitNo + PayEntity.cardinfo.cardNo.PadRight(42, ' '));

            if (string.Compare(PayEntity.cardinfo.cardType, "0") == 0)
            {
                //工业卡充钱
                PayEntity.buyNums = 0;
            }
            SendPackage.SetArrayData(48, Encoding.Default.GetBytes("ICDATA" + PayEntity.cardinfo.cardNo + "|" + PayEntity.cardinfo.icMark + "|" + PayEntity.cardinfo.icNum + "|" + GetTerminalNo() + "|" + PayEntity.cardinfo.strEnCrypt + "|" + PayEntity.buyNums.ToString()));
            SendPackage.SetString(49, "156");
        }
Exemple #5
0
        protected override void Packet()
        {
            switch (m_process)
            {
            case 0:
            {
                string strCount = "1" + m_aidList.Count.ToString("00");
                SendPackage.SetString(0, "0820");
                SendPackage.SetString(60, "00" + GetBatchNo() + "382");
                SendPackage.SetArrayData(63, Encoding.Default.GetBytes(strCount), 0, 3);
            } break;

            case 1:
            {
                SendPackage.SetString(0, "0800");
                SendPackage.SetString(60, "00" + GetBatchNo() + "380");
                SendPackage.SetArrayData(63, m_downAID);
            } break;

            case 2:
            {
                SendPackage.SetString(0, "0800");
                SendPackage.SetString(60, "00" + GetBatchNo() + "381");
            } break;
            }
        }
Exemple #6
0
    public void Send(int type, ByteArray data)
    {
        SendPackage temp = new SendPackage(type, data.Bytes);

        _sendPackages.Add(temp);

        StartSend();
    }
Exemple #7
0
    public void Send(int type)
    {
        SendPackage temp = new SendPackage(type);

        _sendPackages.Add(temp);

        StartSend();
    }
Exemple #8
0
        //protected

        protected override bool NeedCalcMac()
        {
            if (SendPackage.GetString(0) == "0800")
            {
                return(false);
            }
            return(true);
        }
Exemple #9
0
        public override void TC_SendCycleSettingData()
        {
            //$base.TC_SendCycleSettingData();

            byte[] data=new  byte[]{0x0f,0x14,0};
            SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, 0xffff, data);
            this.Send(pkg);
        }
Exemple #10
0
 public Task Handle(OrderPaymentRecorded @event, CancellationToken cancellationToken)
 {
     return(commandBus.Send(
                SendPackage.Create(
                    @event.OrderId,
                    @event.ProductItems.Select(pi => new ProductItem(pi.ProductId, pi.Quantity)).ToList()
                    )
                ));
 }
Exemple #11
0
 protected override void Packet()
 {
     if (SendPackage.ExistBit(55))
     {
         byte[] bSend55 = SendPackage.GetArrayData(55);
         byte[] field55 = GetICAutoField55(bSend55, bSend55.Length);//IC卡55域有变动
         SendPackage.SetArrayData(55, field55, 0, field55.Length);
     }
     PackReverse(Reason);
 }
Exemple #12
0
 protected override void Packet()
 {
     SendPackage.SetString(0, "0100");
     SendPackage.SetString(3, "310000");
     SendPackage.SetString(11, GetTraceNo());
     SendPackage.SetString(25, "92"); //服务点条件代码
     SendPackage.SetArrayData(48, PacketField48());
     SendPackage.SetString(49, "156");
     SendPackage.SetString(60, "00" + GetBatchNo() + "000");
 }
        public void SendMessage(string fullName, byte[] data)
        {
            SendPackage sp = new SendPackage
            {
                name = fullName,
                data = data
            };

            SendQueue.Enqueue(sp);
        }
Exemple #14
0
 protected override bool NeedCalcMac()
 {
     if (SendPackage.GetString(3) == "349000")
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemple #15
0
    private void StartSend()
    {
        if (_connected)
        {
            if (_sendPackages.Count == 0)
            {
                return;
            }
            if (_clientSocket == null)
            {
                return;
            }
            try
            {
                ByteArray bytes = _sendData;
                bytes.Clear();

                while (_sendPackages.Count > 0)
                {
                    SendPackage sendData = _sendPackages[0];
                    _sendPackages.RemoveAt(0);

                    //ByteArray package = CmdUtil.GetPackage(sendData.CmdID, (uint)TimeManager.ServerTime, sendData.Body);
                    ByteArray package = CmdUtil.GetPackage(sendData.CmdID, 0, sendData.Body);
                    if (CanLog())
                    {
                        //Log(">>>> [" + _ip + ":" + _port + "][CmdID:" + sendData.CmdID + "][Data Length:" + (package.Length - COMMAND_HEAD_LENGTH) + "]");
                    }
                    bytes.WriteBytes(package);
                }

                _clientSocket.BeginSend(bytes.Bytes, 0, bytes.Length, SocketFlags.None, new AsyncCallback(SendCallback), _clientSocket);
                if (CanLog())
                {
                    //Log(">>>> [" + _ip + ":" + _port + "][Flush....][Data Length:" + bytes.Length + "]");
                }
            }
            catch (SocketException socketEx)
            {
                Debug.Log("StartSend...[" + socketEx.ErrorCode + "]" + socketEx.Message);
                if (socketEx.NativeErrorCode != 10035)
                {
                    Close(true);
                }
            }
            catch (Exception ex)
            {
                Debug.Log("Start Send Exception " + ex.Message);
                Close(true);
                throw ex;
            }
        }
    }
Exemple #16
0
        public override void OneMinTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            //base.OneMinTimer_Elapsed(sender, e);
            try
            {
                if (this.IsTcpConnected)
                {

                    //if(this is Comm.TC.AVITC)
                    //         ConsoleServer.WriteLine("週期詢問狀態");
                    ////  ConsoleServer.WriteLine(this.DeviceName + "secdiff:" + this.TC_SetDateTime(dt.Year, dt.Month, dt.Day, dt.Hour, dt.Minute, dt.Second));
                    //try
                    //{
                    //    if(mincnt==0)
                    //    this.TC_GetHW_Status();
                    //    else
                    //    this.TC_SendCycleSettingData();
                    //}
                    //catch { ;}
                    SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.B, this.m_deviceid, new byte[] { 0x01 });
                    try
                    {
                        this.m_device.Send(pkg);
                    }
                    catch
                    {
                        ;
                    }

                    if (System.DateTime.Now - this.LastReceiveTime > new TimeSpan(0, 3, 0))
                    {
                        this.LastReceiveTime = System.DateTime.Now;
                        this.IsConnected = false;
                        // this.IsTcpConnected = true;
                        ConsoleServer.WriteLine(this.DeviceName + "communication keep silent over 3 min!!");

                        //  this.start_connect();

                    }
                }
                else if (!this.IsTcpConnected && !InConnect_Task)
                {
                    this.start_connect();
                }

                //   Util.GC();
            }
            catch (Exception ex)
            {
                ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
                ;
            }
        }
Exemple #17
0
 public byte TC_GetDisplayType()
 {
     byte[] data = new byte[] { 0x04,0xd2};
     SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, 0xffff, data);
     this.Send(pkg);
     if (pkg.result == CmdResult.ACK)
     {
         return pkg.ReturnTextPackage.Text[8];
     }
     else
         throw new Exception(pkg.result.ToString());
 }
Exemple #18
0
        private TransResult Unpack8583()
        {
            var ret = TransResult.E_RECV_FAIL;

            try
            {
                var RecvData = new byte[recvLen - headLen];
                RecvData = UnpackHead();

                byte[] len8583 = new byte[2];
                Array.Copy(RecvData, len8583, 2);
                int lenthOf8583 = len8583[0] * 256 + len8583[1];
                if (lenthOf8583 != 0)
                {
                    var RecvBytes = new byte[RecvData.Length - headLen_8583]; //包体数据
                    Array.Copy(RecvData, headLen_8583, RecvBytes, 0, RecvData.Length - headLen_8583);
                    var headBytes = new byte[headLen_8583];
                    Array.Copy(RecvData, headBytes, headLen_8583); //包头数据
                    //解包
                    ret        = TransResult.E_UNPACKET_FAIL;
                    FrontBytes = headBytes;
                    HandleFrontBytes(headBytes); //根据报文头来判断是否要下载密钥
                    RecvPackage.ParseBuffer(RecvBytes, SendPackage.ExistValue(0));


                    var nRet = UnPackFix();
                    if (!mInvokeSetResult)
                    {
                        throw new Exception("should invoke SetRespInfo() in UnPackFix()");
                    }
                    mInvokeSetResult = false;
                    ret = nRet ? TransResult.E_SUCC : TransResult.E_HOST_FAIL;
                    CLog.Info(RecvPackage.GetLogText());
                }
                else
                {
                    ret = TransResult.E_HOST_FAIL;
                }
                if (recvLen > headLen + lenthOf8583 + 2)
                {
                    byte[] jsonByte = new byte[recvLen - headLen - lenthOf8583 - 2];
                    Array.Copy(RecvData, lenthOf8583 + 2, jsonByte, 0, jsonByte.Length);
                    var strJson = Encoding.Default.GetString(jsonByte);
                    RecvPackageJson = JsonConvert.DeserializeObject <CommunicateInfo>(strJson);
                }
            }
            catch (Exception ex)
            {
                Log.Error(GetType().Name, ex);
            }
            return(ret);
        }
Exemple #19
0
        protected override void Packet()
        {
            bool bIsIC = false;

            if (CommonData.UserCardType == UserBankCardType.ICCard ||
                CommonData.UserCardType == UserBankCardType.IcMagCard)
            {
                bIsIC = true;
            }
            SendPackage.SetString(0, "0100");
            if (!string.IsNullOrEmpty(CommonData.BankCardNum) && CommonData.BankCardNum.Length != 0)
            {
                SendPackage.SetString(2, CommonData.BankCardNum);
            }

            SendPackage.SetString(3, "351000");
            SendPackage.SetArrayData(4, Encoding.Default.GetBytes(Utility.AmountToString(CommonData.Amount.ToString())));

            PayEntity.PayTraceNo = GetTraceNo();
            SendPackage.SetString(11, PayEntity.PayTraceNo);
            SendPackage.SetString(12, DateTime.Now.ToString("HHmmss"));
            SendPackage.SetString(13, DateTime.Now.ToString("yyyyMMdd"));
            SendPackage.SetArrayData(18, Encoding.Default.GetBytes("STA"));

            if (bIsIC)
            {
                SendPackage.SetArrayData(22, Utility.str2Bcd("051".PadRight(28, '0')));
            }
            if (!string.IsNullOrEmpty(CommonData.BankCardSeqNum) && CommonData.BankCardSeqNum.Length != 0)//卡序列号
            {
                SendPackage.SetArrayData(23, Encoding.Default.GetBytes(CommonData.BankCardSeqNum));
            }
            //SendPackage.SetArrayData(25, Encoding.Default.GetBytes("91")); //服务点条件代码


            if (!string.IsNullOrEmpty(CommonData.Track2) && CommonData.Track2.Length != 0)
            {
                SendPackage.SetArrayData(35, Encoding.Default.GetBytes(CommonData.Track2.Replace('=', 'D')));
            }
            SendPackage.SetArrayData(41, Encoding.ASCII.GetBytes(GetMerchantNo()));
            SendPackage.SetArrayData(42, Encoding.ASCII.GetBytes(GetTerminalNo()));
            SendPackage.SetString(47, PayEntity.unitNo + PayEntity.cardinfo.cardNo.PadRight(42, ' '));
            SendPackage.SetArrayData(48, Encoding.Default.GetBytes(PayEntity.cardinfo.cardNo + "|" + PayEntity.cardinfo.icMark + "|" + PayEntity.cardinfo.icNum + "|" + GetTerminalNo() + "|" + "" + "|" + PayEntity.cardinfo.strEnCrypt));
            SendPackage.SetString(49, "159");
            SendPackage.SetArrayData(52, Utility.str2Bcd(CommonData.BankPassWord));
            if ((bIsIC) && PayEntity.SendField55 != null && PayEntity.SendField55.Length != 0)
            {
                SendPackage.SetString(55, Utility.bcd2str(PayEntity.SendField55, PayEntity.SendField55.Length));
            }

            //SendPackage.SetString(60, ("00" + GetBatchNo() + "000"));
        }
Exemple #20
0
 protected void PackReverse(string reason)
 {
     SendPackage.SetString(0, "0400");
     if (String.IsNullOrEmpty(reason))
     {
         reason = "06";
     }
     SendPackage.SetString(39, reason); //冲正原因
     SendPackage.ClearBitAndValue(26);
     SendPackage.ClearBitAndValue(52);
     SendPackage.ClearBitAndValue(53);
     SendPackage.ClearBitAndValue(64);
 }
Exemple #21
0
        protected override void Packet()
        {
            SendPackage.SetString(0, "0320");
            SendPackage.SetString(2, CommonData.BankCardNum);
            SendPackage.SetString(3, "290000");
            SendPackage.SetString(4, Utility.AmountToString(CommonData.Amount.ToString()));

            SendPackage.SetString(11, GetTraceNo());
            SendPackage.SetString(25, "00"); //服务点条件代码
            SendPackage.SetArrayData(48, PacketField48());
            SendPackage.SetString(49, "156");
            SendPackage.SetString(60, "00" + GetBatchNo() + "362");
        }
Exemple #22
0
 protected override void Packet()
 {
     SendPackage.SetString(0, "0100");
     SendPackage.SetString(3, "350000");
     PayEntity.PayTraceNo = GetTraceNo();
     SendPackage.SetString(11, PayEntity.PayTraceNo);
     SendPackage.SetString(12, DateTime.Now.ToString("HHmmss"));
     SendPackage.SetString(13, DateTime.Now.ToString("yyyyMMdd"));
     SendPackage.SetArrayData(18, Encoding.Default.GetBytes("STA"));
     SendPackage.SetArrayData(41, Encoding.ASCII.GetBytes(GetMerchantNo()));
     SendPackage.SetArrayData(42, Encoding.ASCII.GetBytes(GetTerminalNo()));
     SendPackage.SetString(47, PayEntity.unitNo + DateTime.Now.ToString("yyyyMMddHHmm"));
 }
Exemple #23
0
        public override byte[] TC_GetHW_Status()
        {
            byte[] data = new byte[] { 0x0f, 0x41 };

            SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, 0xffff, data);
            this.Send(pkg);
            //if(pkg.ReturnTextPackage !=null)

            byte[] retdata = new byte[4];
            retdata[0] = pkg.ReturnTextPackage.Text[2];
            retdata[1] = pkg.ReturnTextPackage.Text[3];
            return retdata;
            //return base.TC_GetHW_Status();
        }
Exemple #24
0
        protected override void Packet()
        {
            SendPackage.SetString(0, "0620");
            SendPackage.SetString(60, "00" + GetBatchNo() + "951");

            SendPackage.ClearBitAndValue(14);
            SendPackage.ClearBitAndValue(26);
            SendPackage.ClearBitAndValue(35);
            SendPackage.ClearBitAndValue(36);
            SendPackage.ClearBitAndValue(48);
            SendPackage.ClearBitAndValue(52);
            SendPackage.ClearBitAndValue(53);
            SendPackage.ClearBitAndValue(64);
        }
Exemple #25
0
        public override void ResetComm()
        {
            //base.ResetComm();
            try
            {
                byte[] data = new byte[] { 0x0f, 0x11 };
                SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, 0xffff, data);
                this.Send(pkg);

            }
            catch (Exception ex)
            {
                ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
            }
        }
Exemple #26
0
 protected override void Packet()
 {
     SendPackage.SetString(0, "0100");
     SendPackage.SetString(3, "381008");
     PayEntity.PayTraceNo = GetTraceNo();
     SendPackage.SetString(11, PayEntity.PayTraceNo);
     SendPackage.SetString(12, DateTime.Now.ToString("HHmmss"));
     SendPackage.SetString(13, DateTime.Now.ToString("yyyyMMdd"));
     SendPackage.SetArrayData(18, Encoding.Default.GetBytes("STA"));
     SendPackage.SetArrayData(41, Encoding.ASCII.GetBytes(GetMerchantNo()));
     SendPackage.SetArrayData(42, Encoding.ASCII.GetBytes(GetTerminalNo()));
     SendPackage.SetString(47, PayEntity.unitNo + PayEntity.cardinfo.cardNo.PadRight(20, ' '));
     SendPackage.SetArrayData(48, Encoding.Default.GetBytes(PayEntity.cardinfo.cardNo + "|" + PayEntity.cardinfo.icMark + "|" + PayEntity.cardinfo.icNum + "|" + GetTerminalNo() + "|"));
     SendPackage.SetString(49, "159");
 }
 protected override void Packet()
 {
     SendPackage.SetString(0, "0320");
     SendPackage.SetString(3, "290000");
     SendPackage.SetString(4, Utility.AmountToString(CommonData.Amount.ToString()));
     SendPackage.SetString(11, GetTraceNo());
     SendPackage.SetString(25, "00"); //服务点条件代码
     SendPackage.SetString(41, GetTerminalNo());
     SendPackage.SetString(42, GetMerchantNo());
     SendPackage.SetArrayData(48, PacketField48());
     SendPackage.SetString(49, "156");
     //byte[] field57 = PacketField57();
     //if (field57!=null && field57.Length > 0)
     SendPackage.SetArrayData(57, PacketField57());
     SendPackage.SetString(60, "00" + GetBatchNo() + "362");
 }
Exemple #28
0
        protected override void Packet()
        {
            SendPackage.SetString(0, "0800");
            SendPackage.SetString(11, GetTraceNo());
            switch (DType)
            {
            case DesType.TripleDes:
                SendPackage.SetString(60, "00" + GetBatchNo() + "003");
                break;

            default:
                SendPackage.SetString(60, "00" + GetBatchNo() + "001");
                break;
            }
            SendPackage.SetArrayData(63, Encoding.Default.GetBytes("001"));
        }
Exemple #29
0
        protected override void Packet()
        {
            SendPackage.SetString(0, "0100");
            SendPackage.SetString(2, PayEntity.CreditcardNum);
            SendPackage.SetString(3, "310000");
            SendPackage.SetString(4, Utility.AmountToString(CommonData.Amount.ToString()));
            SendPackage.SetString(11, GetTraceNo());
            SendPackage.SetString(22, "012");
            SendPackage.SetString(25, "92");
            //SendPackage.SetString(48, "PA" + "08" + PayEntity.CreditcardNum.PadRight(19, ' ') + "0".PadRight(11, '0') + "#");
            string f48 = "PA" + "08" + PayEntity.CreditcardNum.PadRight(19, ' ') + "0".PadRight(11, '0') + "#";

            SendPackage.SetArrayData(48, Encoding.Default.GetBytes(f48));

            SendPackage.SetString(49, "156");
        }
Exemple #30
0
    public void Send <T>(int type, T msg) where T : global::ProtoBuf.IExtensible
    {
        MemoryStream stream = new MemoryStream();

        ProtoBuf.Serializer.Serialize <T>(stream, msg);

        byte[] bytes = new byte[stream.Length];
        stream.Position = 0;
        stream.Read(bytes, 0, (int)stream.Length);

        SendPackage temp = new SendPackage(type, bytes);

        _sendPackages.Add(temp);

        StartSend();
    }
Exemple #31
0
 protected override void Packet()
 {
     SendPackage.SetString(0, "0100");
     if (!string.IsNullOrEmpty(PayEntity.cardinfo.cardNo))
     {
         SendPackage.SetString(2, PayEntity.cardinfo.cardNo);
     }
     SendPackage.SetString(3, "300644");
     PayEntity.PayTraceNo = GetTraceNo();
     SendPackage.SetString(11, PayEntity.PayTraceNo);
     SendPackage.SetString(12, DateTime.Now.ToString("HHmmss"));
     SendPackage.SetString(13, DateTime.Now.ToString("yyyyMMdd"));
     SendPackage.SetArrayData(18, Encoding.Default.GetBytes("STA"));
     SendPackage.SetArrayData(41, Encoding.ASCII.GetBytes(GetMerchantNo()));
     SendPackage.SetArrayData(42, Encoding.ASCII.GetBytes(GetTerminalNo()));
     SendPackage.SetString(47, PayEntity.unitNo + PayEntity.cardinfo.cardNo.PadRight(20, ' '));
     SendPackage.SetString(49, "156");
 }
        private void TrySend()
        {
            if (Client == null)
            {
                return;
            }
            if (!Client.IsConnect())
            {
                return;
            }
            if (SendQueue.Count == 0)
            {
                return;
            }
            SendPackage sp = SendQueue.Dequeue();

            Trace.Instance.debug("[SEND] {0}", sp.name);
            Client.SendMessage(sp.data);
        }
        protected override void Packet()
        {
            switch (m_process)
            {
            case 0:
            {
                SendPackage.SetString(0, "0800");
                SendPackage.SetString(60, "00" + GetBatchNo() + "396");
            }
            break;

            case 1:
            {
                SendPackage.SetString(0, "0800");
                SendPackage.SetString(60, "00" + GetBatchNo() + "397");
            }
            break;
            }
        }
Exemple #34
0
 protected override void Packet()
 {
     try
     {
         SendPackage.SetString(0, "0100");
         SendPackage.SetString(3, "349000");
         SendPackage.SetString(11, GetTraceNo());
         SendPackage.SetString(12, DateTime.Now.ToString("HHmmss"));
         SendPackage.SetString(13, DateTime.Now.ToString("yyyyMMdd"));
         //SendPackage.SetString(18, "STA");
         SendPackage.SetArrayData(18, Encoding.ASCII.GetBytes("STA"));
         SendPackage.SetArrayData(41, Encoding.ASCII.GetBytes(GetMerchantNo()));
         SendPackage.SetArrayData(42, Encoding.ASCII.GetBytes(GetTerminalNo()));
         SendPackage.SetArrayData(64, Encoding.ASCII.GetBytes("00000000"));
     }
     catch (Exception ex)
     {
         Log.Error("[ApplicationKeyPay][Packet] err", ex);
     }
 }
        protected override void Packet()
        {
            SendPackage.SetString(0, "0100");
            SendPackage.SetString(3, "380000");
            SendPackage.SetString(11, GetTraceNo());
            SendPackage.SetString(25, "00"); //服务点条件代码
            SendPackage.SetArrayData(48, PacketField48());
            SendPackage.SetString(49, "156");
            switch (DType)
            {
            case DesType.Des:
                SendPackage.SetString(53, "20");
                break;

            case DesType.TripleDes:
                SendPackage.SetString(53, "26");
                break;
            }
            SendPackage.SetString(60, "00" + GetBatchNo() + "000");
        }
    public async Task <Package> SendPackage(SendPackage request, CancellationToken cancellationToken = default)
    {
        if (request == null)
        {
            throw new ArgumentNullException(nameof(request));
        }

        if (request.ProductItems?.Count == 0)
        {
            throw new ArgumentException("It's not possible to send package with empty product items");
        }

        if (!productAvailabilityService.IsEnoughOf(request.ProductItems !.ToArray()))
        {
            await Publish(new ProductWasOutOfStock(request.OrderId, DateTime.UtcNow));

            throw new ArgumentOutOfRangeException(nameof(request.ProductItems), "Cannot send package - product was out of stock.");
        }

        var package = new Package
        {
            Id           = Guid.NewGuid(),
            OrderId      = request.OrderId,
            ProductItems = request.ProductItems.Select(pi =>
                                                       new ProductItem {
                Id = Guid.NewGuid(), ProductId = pi.ProductId, Quantity = pi.Quantity
            }).ToList(),
            SentAt = DateTime.UtcNow
        };

        await Packages.AddAsync(package, cancellationToken);

        var @event = new PackageWasSent(package.Id,
                                        package.OrderId,
                                        package.ProductItems,
                                        package.SentAt);

        await SaveChangesAndPublish(@event, cancellationToken);

        return(package);
    }
Exemple #37
0
        //color length= mesg length execept '\r'
        public void TC_SendDisplay(int g_code_id,int hor_space, string mesg, byte[]colors)
        {
            int ver_no = 1;
            byte[]big5bytes;
              //  if (mesg.IndexOf('\r') == -1)  //append cr 保證 msgleng 不為零
              //      mesg += "\r";

            this.checkConntected();

            lock (this.currDispLockObj)
            {

                if (g_code_id == 0)  //文字模式
                {
                    System.Data.DataSet ds = this.m_protocol.GetSendDataSet("set_display_text");
                    //  ds.Tables["tblMain"].Rows[0]["data_type"] = 0; //text

                    big5bytes = RemoteInterface.Util.StringToBig5Bytes(mesg);

                    ds.Tables["tblMain"].Rows[0]["msgcnt"] = ds.Tables["tblMain"].Rows[0]["msg_length"] = big5bytes.Length;
                    for (int i = 0; i < big5bytes.Length; i++)
                        if (big5bytes[i] == 0x0d)
                            ver_no++;

                    ds.Tables["tblMain"].Rows[0]["ver_no"] = ver_no;
                    ds.Tables["tblMain"].Rows[0]["hor_space"] = hor_space;
                    for (int i = 0; i < ver_no; i++)
                        ds.Tables["tblver_no"].Rows.Add(0);

                    for (int i = 0; i < big5bytes.Length; i++)
                        ds.Tables["tblmsgcnt"].Rows.Add(big5bytes[i]);

                    string mesg1 = mesg.Replace("\r", "");
                    for (int i = 0; i < mesg1.Length; i++)
                    {

                        ds.Tables["tblcolorcnt"].Rows.Add(colors[i]);

                    }
                    ds.Tables["tblMain"].Rows[0]["colorcnt"] = ds.Tables["tblcolorcnt"].Rows.Count;
                    ds.AcceptChanges();
                    currentDispalyDataset = ds;
                    currentDisplayPackage = this.m_protocol.GetSendPackage(ds, 0xffff);
                    this.m_device.Send(currentDisplayPackage);
                    // ds.Dispose();
                }
                else   //圖形模式
                {
                    System.Data.DataSet ds = this.m_protocol.GetSendDataSet("set_display_graph");
                    ds.Tables["tblMain"].Rows[0]["data_type"] = 1;
                    ds.Tables["tblMain"].Rows[0]["g_code_id"] = g_code_id;
                    currentDispalyDataset = ds;
                    ds.AcceptChanges();
                    currentDisplayPackage = this.m_protocol.GetSendPackage(ds, 0xffff);
                    this.m_device.Send(currentDisplayPackage);

                }

                if (curr_mesg != mesg || curr_g_code_id != g_code_id)
                {
                    curr_mesg = mesg;
                    curr_g_code_id = g_code_id;
                    curr_hor_space = hor_space;

                    this.InvokeOutPutChangeEvent(this, this.GetCurrentDisplayDecs());
                }
            }
        }
Exemple #38
0
        void SetAllWarnsetFlash()
        {
            if (this.WarnSetNo == 0)
                  return;
              try
              {

                  byte[] com_data = new byte[2 + 3 * WarnSetNo];
                  com_data[0] = 0xa0;
                  com_data[1] = (byte)WarnSetNo;

                  for (int i = 0; i < WarnSetNo; i++)
                  {
                      com_data[2 + 3 * i] = bossids[i];

                      com_data[2 + 3 * i + 1] = 2;  //flash

                      if(bossids[i]==0x08 || bossids[i]==0x09 || bossids[i]==0x0a || bossids[i]==0x0b)
                        com_data[2 + 3 * i + 2] = 10;
                      else
                        com_data[2 + 3 * i + 2] = 11;

                  }

                  SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, 0xffff, com_data);
                  m_device.Send(pkg);
              }
              catch (Exception ex)
              {
                  Console.WriteLine("SetAllWarnsetFlash," + ex.Message + "," + ex.StackTrace);
              }
        }
Exemple #39
0
        private void getRMSdata()
        {
            try
              {
              SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.B, 0xffff, new byte[] { 0x87 });
              this.Send(pkg);
              if (pkg.result != CmdResult.ACK)
                  return;

              System.Data.DataSet ds = this.m_protocol.GetReturnDsByTextPackage(pkg.ReturnTextPackage);
              System.Data.DataRow r=ds.Tables[0].Rows[0];
              string output = "mode:{0} planno:{1} rmsrate:{2} ";
              output = string.Format(output, r["ctl_mode"], r["plan_no"], r["rmsrate"]);
              output += "rms_lamp_no:" + r["rms_lamp_no"] + " ";

              for (int i = 0; i < ds.Tables["tblrms_lamp_no"].Rows.Count; i++)
              {
                  System.Data.DataRow rr=ds.Tables["tblrms_lamp_no"].Rows[i];
                  output += "rms_lamp_sta:" + rr["rms_lamp_sta"]+ " ";
              }

              //2012/4/24

              for(int i=0;i< ds.Tables["tblwarnsetno"].Rows.Count;i++)
              {
                  System.Data.DataRow rr=ds.Tables["tblwarnsetno"].Rows[i];

                  bossids[i] = System.Convert.ToByte(rr["warnset"]);

                  output += rr["warnset"] + ":" + rr["warn_message_id"] + " " + rr["warnset"]+":"+ rr["bos_sta"]+ " ";
              }
              this.WarnSetNo = ds.Tables["tblwarnsetno"].Rows.Count;

              string sql = "update tblrmsconfig set rmsdata='{0}' where devicename='{1}'";

              sql = string.Format(sql, output.Trim(), this.DeviceName);
              this.InvokeDBDemand(sql);

              }
              catch (Exception ex)
              {
              ConsoleServer.WriteLine("In getRMSdata"+ ex.Message + "," + ex.StackTrace);
              }

             // throw new Exception("The method or operation is not implemented.");
        }
Exemple #40
0
        //取得最近五分鐘資料
        private void getLast5VD_Data()
        {
            System.DateTime dt = System.DateTime.Now.AddMinutes(-4);
               System.Data.DataSet ds;
               for (int i = 0; i < 5; i++)
               {

               byte[] sendData = new byte[] { 0x15, (byte)dt.Day, (byte)dt.Hour,(byte) dt.Minute };
               try
               {
                  SendPackage pkg;

                   this.m_device.Send(pkg=new SendPackage(CmdType.CmdQuery, CmdClass.A, 0xffff, sendData));
                   if (pkg.result == CmdResult.ACK)
                   {
                       ds = m_protocol.GetReturnDsByTextPackage(pkg.ReturnTextPackage);
                       OneMinDataStore.inData(getOneMinAvgData(ds));

                   }
                   else
                   {
                       ConsoleServer.WriteLine(pkg.result.ToString() + pkg.ToString());
                   }

               }
               catch (Exception ex)
               {
                   ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
               }

               dt = dt.AddMinutes(1);

               }

               VD_MinAvgData fiveMinData = this.OneMinDataStore.getFiveMinMovingAvgData();
               ConsoleServer.WriteLine("five min avg:" + fiveMinData.ToString());
               if (this.OnFiveMinAvgData != null)
               this.OnFiveMinAvgData(this, fiveMinData);
        }
Exemple #41
0
 // for compare only
 //private void StartRampControl()
 //{
 //    SendPackage pkg = null;
 //    // new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x04, 0xA5 });
 //    //  m_device.Send(pkg);
 //    //if (pkg.ReturnTextPackage.Text[8] == 2)
 //    //{
 //        pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0xA5, 01 });
 //        m_device.Send(pkg);
 //    //}
 //}
 //private void StopRampControl()
 //{
 //    SendPackage pkg = null;
 //    // new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x04, 0xA5 });
 //    // m_device.Send(pkg);
 //    //if (pkg.ReturnTextPackage.Text[8] == 1)
 //    //{
 //        pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0xA5, 02 });
 //        m_device.Send(pkg);
 //    //}
 //}
 //private SendPackage TC_GetCurrModeAndPlanNo()
 //{
 //    checkConntected();
 //    SendPackage pkg=new SendPackage(CmdType.CmdQuery,CmdClass.A,m_deviceid,new byte[]{0x04,0x82});
 //     m_device.Send(pkg);
 //    return  pkg;
 //}
 //private void TC_GetCurrModeAndPlanNo(ref byte mode, ref byte planno)
 // {
 //     checkConntected();
 //     SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, m_deviceid, new byte[] { 0x04, 0x82 });
 //    // m_device.Send(pkg);
 //  //   return pkg;
 // }
 private void TC_GetModeAndPlanno(ref byte mode, ref byte planno)
 {
     checkConntected();
       if (this.IsF311z)
       {
           SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, m_deviceid, new byte[] { 0x04, 0x80 });
           m_device.Send(pkg);
           mode = pkg.ReturnTextPackage.Text[8];
           pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, m_deviceid, new byte[] { 0x04, 0x83 });
           m_device.Send(pkg);
           planno = pkg.ReturnTextPackage.Text[8];
       }
       else
       {
           SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, m_deviceid, new byte[] { 0x04, 0x82 });
           m_device.Send(pkg);
           mode = pkg.ReturnTextPackage.Text[8];
           //pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, m_deviceid, new byte[] { 0x04, 0x83 });
          // m_device.Send(pkg);
           planno = pkg.ReturnTextPackage.Text[9];
       }
 }
Exemple #42
0
 public void Send(SendPackage[] pkgs)
 {
     this.m_device.Send(pkgs);
 }
Exemple #43
0
        void v2dle_OnReceiveText(object sender, TextPackage txt)
        {
            //throw new NotImplementedException();
            System.Data.DataSet ds;
            if (v2dle == null)
                return;
            try
            {
                switch (txt.Text[0])
                {
                    case 0x04:  //query
                        txt.IsQueryCmd = true;

                        switch (txt.Text[1])
                        {
                            case 0x02: //get date time

                                SendDirect(ControllerID, new byte[] { 04,this.PropertyBag.HWtatus[0],this.PropertyBag.HWtatus[1]
                                    ,this.PropertyBag.HWtatus[2],this.PropertyBag.HWtatus[3],0,7,2 , (byte)(DateTime.Now.Year/256),(byte)(DateTime.Now.Year %256),
                            (byte)DateTime.Now.Month,(byte)DateTime.Now.Day,(byte)DateTime.Now.Hour,(byte)DateTime.Now.Minute,(byte)DateTime.Now.Second}, (byte)txt.Seq);
                                break;
                            case 0x03:  //trandmission cycle
                                int _devtype=1;

                               SendDirect(this.ControllerID,
                                   new byte[]{0x04,PropertyBag.HWtatus[0],PropertyBag.HWtatus[1],PropertyBag.HWtatus[2],PropertyBag.HWtatus[3],
                                       0x00,0x05,0x03,1,PropertyBag.TransmitCycle,PropertyBag.TransmitMode,PropertyBag.HWCycle},(byte)txt.Seq);
                               break;
                            case 0x07:
                               SendDirect(this.ControllerID,
                                new byte[]{0x04,PropertyBag.HWtatus[0],PropertyBag.HWtatus[1],PropertyBag.HWtatus[2],PropertyBag.HWtatus[3],
                                       0x00,0x02,0x07,PropertyBag.IsAllowManualMode?(byte)0:(byte)1}, (byte)txt.Seq);
            //cmd=0x04

            //description="Get Trasmiission cycle"
            //class=A
            //func_name="get_transmission_cycle"
            //type=Query
            //send= protocol_code(1:3-3) device_type(1:4 "4_AM Cycle")
            //return= hw_status_1(1:0-255) hw_status_2(1:0-255) hw_status_3(1:0-255) hw_status_4(1:0-255)
            //protocol_length(2:0-65530) protocol_code(1:3-3)  device_type(1:4 "4_AM Cycle")  transmission_cycle(1:1-255) transmit_mode(1:0 "Polling",1 "Active" ) hwcyc(1: 0 "State change" ,1 "5sec",2 "10Sec",3 "20sec",4 "1min",5 "5min")
            //test=@cmd protocol_code(3) device_type(4)
                                break;

                            case 0x08:
                                SendDirect(this.ControllerID,
                             new byte[]{0x04,PropertyBag.HWtatus[0],PropertyBag.HWtatus[1],PropertyBag.HWtatus[2],PropertyBag.HWtatus[3],
                                       0x00,0x03,0x08,txt.Text[2],this.config.sensors[txt.Text[2]].execution_mode }, (byte)txt.Seq);
                                break;

                            case 0x20:
                                byte[] configbytes = GetConfigBytes();
                                byte[] data = new byte[configbytes.Length + 3];

                                data[0] = 0x20;
                                data[1] = (byte)(configbytes.Length / 256);
                                data[2] = (byte)(configbytes.Length % 256);
                                System.Array.Copy(configbytes, 0, data, 3, configbytes.Length);

                                SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.A, this.ControllerID, To04DataBytes(data));
                                pkg.Seq = txt.Seq;
                                SendDirect(pkg);
                                break;
                            default:
                                OnReceiveText(txt);
                                break;
                        }
                        break;
                    case 0x02:  //set date time get diff
                        int year = txt.Text[1] * 256 + txt.Text[2];
                        int month = txt.Text[3];
                        int day = txt.Text[4];
                        int hour = txt.Text[5];
                        int min = txt.Text[6];
                        int sec = txt.Text[7];

                        DateTime d = new DateTime(year, month, day, hour, min, sec);
                        uint diff = (uint)Math.Abs(d.Subtract(DateTime.Now).TotalSeconds);
                        if (diff > 255)
                            diff = 255;
                        if(diff<3)
                            Comm.Util.SetSysTime(d);
                        txt.IsQueryCmd = true;
                        SendDirect(this.ControllerID, new byte[] { 2, (byte)diff }, (byte)txt.Seq);
                        break;

                    case 0x01: //get hw status

                        // ds = protocol.GetSendDsByTextPackage(txt, CmdType.CmdQuery);
                        txt.IsQueryCmd = true;
                    //    ds= protocol.GetReturnDataSet("get_HW_Status");

                        SendDirect(this.ControllerID, new byte[] { 01, this.PropertyBag.HWtatus[0], this.PropertyBag.HWtatus[1], this.PropertyBag.HWtatus[2], this.PropertyBag.HWtatus[3] }, (byte)txt.Seq);

                        break;
                    case 0x00:  //reset
                        Console.WriteLine("reset!");
                        Environment.Exit(0);

                        break;
                    case 0x03: //Set transmit cycle
            //[Command]
            //cmd=0x03
            //description= "Set Trasmiission cycle"
            //class=A
            //func_name="set_transmission_cycle"
            //type=Set
            //send=device_type(1:4 "4_AM",18 "18_Other")  transmission_cycle(1:0-255) transmit_mode(1:0 "Polling",1 "Active" ) hwcyc(1: 0 "State change" ,1 "5sec",2 "10Sec",3 "20sec",4 "1min",5 "5min")
            //return=
            //test=@cmd device_type(4) transmission_cycle(5) transmit_mode(1) hwcyc(1)
                        ds = protocol.GetSendDsByTextPackage(txt, CmdType.CmdSet);
                        byte device_type= (byte)ds.Tables[0].Rows[0]["device_type"];
                        byte transmission_cycle = (byte)ds.Tables[0].Rows[0]["transmission_cycle"];
                        byte transmit_mode = (byte)ds.Tables[0].Rows[0]["transmit_mode"];
                        byte hwcyc = (byte)ds.Tables[0].Rows[0]["hwcyc"];

                        PropertyBag.HWCycle = hwcyc;
                        PropertyBag.TransmitCycle = transmission_cycle;
                        PropertyBag.TransmitMode = transmit_mode;
                        SetHWStatusTmr();
                        SetTransmitCycleTmr();

                        Console.WriteLine("transmission_cycle:" + transmission_cycle);
                        break;

                    case 0x07: // set Manul Mode
                        if (this.PropertyBag.IsAllowManualMode != ((txt.Text[1] == 0) ? true : false))
                        {
                            this.PropertyBag.IsAllowManualMode = (txt.Text[1] == 0) ? true : false;
                            SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, this.ControllerID, new byte[]{0x07,
                            (byte)(PropertyBag.IsAllowManualMode?0:1)});
                            PostSend(pkg);
                        }
                        break;

                    case 0x08:// set Execution mode
                      //  this.config.execution_mode = txt.Text[1]; execution mode will remove
                        this.config.sensors[txt.Text[1]].execution_mode = txt.Text[2];
                        this.config.Serialize();
                        break;
                    case 0x0b: //get hw status
                        txt.IsQueryCmd = true;
                        SendDirect(this.ControllerID, new byte[] { 0x0b, this.PropertyBag.HWtatus[0], this.PropertyBag.HWtatus[1], this.PropertyBag.HWtatus[2], this.PropertyBag.HWtatus[3],PropertyBag.ComState ,PropertyBag.OPStatus,PropertyBag.OPMode}, (byte)txt.Seq);
                        break;

                    case 0x0E:
                        txt.IsQueryCmd = true;

                        SendDirect(this.ControllerID,
                            new byte[] {0x0e,this.PropertyBag.HWtatus[0],this.PropertyBag.HWtatus[1],this.PropertyBag.HWtatus[2],this.PropertyBag.HWtatus[3],
                           (byte)(BuildDate.Year/256),(byte)(BuildDate.Year%256),(byte)BuildDate.Month,(byte)BuildDate.Day,
                            0x30,0x30,0x30,0x30,0x30,1,this.VersionNo,
                            (byte)(this.ControllerID/256),(byte)(this.ControllerID%256)}, (byte)txt.Seq);
                        break;
                    case 0x20:  //set Communication param
                        SetConfig(txt);
                        break;

                     default:
                         OnReceiveText(txt);
                        break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + "," + ex.StackTrace);
            }
        }
Exemple #44
0
 public void TC_SetDisplayOff(byte boardid)
 {
     checkConntected();
        if (currDisplayBytes[boardid - 1][3] != 0x00)
        {
        SendPackage pk = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x5f, 0x17, boardid, 0x20, 0x20, 0x20, 0x00 });
        this.m_device.Send(pk);
        currDisplayBytes[boardid - 1][0] = 0x20;
        currDisplayBytes[boardid - 1][1] = 0x20;
        currDisplayBytes[boardid - 1][2] = 0x20;
        currDisplayBytes[boardid - 1][3] = 0x00;
        this.InvokeOutPutChangeEvent(this, this.GetCurrentDisplayDecs());
        }
 }
Exemple #45
0
        public override void TC_SetDisplayOff()
        {
            checkConntected();

              SendPackage pk = null;

              if (currDisplayBytes[0][3] != 0x00)
              {
               pk = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x5f, 0x17, 1, 0x20, 0x20, 0x20, 0x00 });
              this.m_device.Send(pk);
              }

              if (currDisplayBytes[1][3] != 0x00)
              {
              pk = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x5f, 0x17, 2, 0x20, 0x20, 0x20, 0x00 });
              this.m_device.Send(pk);
              }

              if (currDisplayBytes[2][3] != 0x00)
              {
              pk = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x5f, 0x17, 3, 0x20, 0x20, 0x20, 0x00 });
              this.m_device.Send(pk);
              }
              //if (pk.result != CmdResult.ACK)
              //    Console.WriteLine(m_deviceName + ":set display off" + pk.result);
              //if (pk.result != CmdResult.ACK)
              //    Console.WriteLine(m_deviceName + ":set display off" + pk.result);
              //if (pk.result != CmdResult.ACK)
              //    Console.WriteLine(m_deviceName + ":set display off" + pk.result);

              for(int i=0;i<3;i++)
              for(int j=0;j<4;j++)
              {
                  if (j == 3)  //color
                  {
                      if(currDisplayBytes[i][3]!=0x00)
                          this.InvokeOutPutChangeEvent(this,"boardid "+(i+1)+ ":熄滅");
                      currDisplayBytes[i][j] = 0x00;
                  }
                  else
                      currDisplayBytes[i][j] = 0x20;
              }
              //if (currentDispalyDataset != null )
              //    this.InvokeOutPutChangeEvent(this, "熄滅");

             // this.currentDispalyDataset = null;
        }
Exemple #46
0
        public void TC_SendDisplay(byte boardid,string traveltime,  byte color)
        {
            lock (this.currDispLockObj)
            {
                byte[] travelbytes = System.Text.ASCIIEncoding.ASCII.GetBytes(traveltime);
                byte[] comdata = new byte[] { 0x5f, 0x17, boardid, travelbytes[0], travelbytes[1], travelbytes[2], color };
                bool isEqual = true;

                isEqual = isEqual && (currDisplayBytes[boardid - 1][0] == travelbytes[0]);
                isEqual = isEqual && (currDisplayBytes[boardid - 1][1] == travelbytes[1]);
                isEqual = isEqual && (currDisplayBytes[boardid - 1][2] == travelbytes[2]);

                isEqual=isEqual &&(color==currDisplayBytes[boardid -1][3]);
                if (!isEqual)
                {

                    try
                    {
                        SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, 0xffff, comdata);

                        System.Array.Copy(comdata, 3, currDisplayBytes[boardid - 1], 0, 4);

                        this.Send(pkg);

                        currDisplayBytes[boardid - 1][0] = travelbytes[0];
                        currDisplayBytes[boardid - 1][1] = travelbytes[1];
                        currDisplayBytes[boardid - 1][2] = travelbytes[2];
                    }
                    catch (Exception ex)
                    {
                        ConsoleServer.WriteLine(ex.Message + "," + ex.StackTrace);
                    }

                    this.InvokeOutPutChangeEvent(this, this.GetCurrentDisplayDecs());
                }
            }
        }
Exemple #47
0
        void SendTask()
        {
            byte[]data=null;
            while (true)
            {
                if (!this.getEnable())
                {
                    Console.WriteLine(m_devName+",send task exit!");
                    return;
                }
                try
                {
                  #region  Get a SendingPkg
                    lock (SendTaskNotifyObj)
                    {

                            if (SendQueueA.Count != 0)
                                while (SendQueueA.Count != 0)
                                {
                                    currentSendingPackage = (SendPackage)SendQueueA.Dequeue();
                                    if (!currentSendingPackage.IsDiscard)
                                        break;
                                    else
                                        currentSendingPackage = null;

                                }

                            else if (SendQueueB.Count != 0)

                                while (SendQueueB.Count != 0)
                                {
                                    currentSendingPackage = (SendPackage)SendQueueB.Dequeue();
                                    if (!currentSendingPackage.IsDiscard)
                                        break;
                                    else
                                        currentSendingPackage = null;
                                }
                            else if (SendQueueC.Count != 0)
                                while (SendQueueC.Count != 0)
                                {
                                    currentSendingPackage = (SendPackage)SendQueueC.Dequeue();
                                    if (!currentSendingPackage.IsDiscard)
                                        break;
                                    else
                                        currentSendingPackage = null;
                                }
                            else if (SendQueueD.Count != 0)
                                while (SendQueueD.Count != 0)
                                {
                                    currentSendingPackage = (SendPackage)SendQueueD.Dequeue();
                                    if (!currentSendingPackage.IsDiscard)
                                        break;
                                    else
                                        currentSendingPackage = null;
                                }
                            else if (TimeOutQueue.Count != 0)
                                while (TimeOutQueue.Count != 0)
                                {
                                    currentSendingPackage = (SendPackage)TimeOutQueue.Dequeue();
                                    if (!currentSendingPackage.IsDiscard)
                                        break;
                                    else
                                        currentSendingPackage = null;
                                }
                            else
                            {
                                //no Data To Send , and waiting

                                currentSendingPackage = null;
                                //GC.Collect();
                                //GC.WaitForPendingFinalizers();
                                System.Threading.Monitor.Wait(SendTaskNotifyObj);

                                continue;
                            }

                    }
                  #endregion

                    try
                    {

                            if (currentSendingPackage == null) continue;

                            if (currentSendingPackage.type== CmdType.CmdSet)  // active report data
                            {
                                if (currentSendingPackage.sendCnt == 0)
                                    data = PackData(currentSendingPackage.address, currentSendingPackage.text);
                                else
                                    data = PackData(currentSendingPackage.address, currentSendingPackage.text, (byte)currentSendingPackage.Seq);
                            }
                            else  //query report
                            {
                                data = PackData(currentSendingPackage.address, currentSendingPackage.text, (byte)currentSendingPackage.Seq);
                            }

                            currentSendingPackage.Seq = data[2];
                            if (!this.getEnable())
                                return;

                            if (currentSendingPackage.sendCnt >= 3)   //discard package
                            {

                                lock (currentSendingPackage)
                                {
                                    currentSendingPackage.result = CmdResult.TimeOut;
                                    System.Threading.Monitor.Pulse(currentSendingPackage);

                                }
                                continue;
                            }
                            currentSendingPackage.sendCnt++;
                        //}

                        if (OnSendingPackage != null)
                            OnSendingPackage(this, currentSendingPackage);
                        lock (stream)
                        {

                            if (OnTextSending != null)
                                OnTextSending(this, ref data);
                            //---------------------------------------------------------------------------------
                            //if (currentSendingPackage.type == CmdType.CmdSet)
                            //    Console.WriteLine("<============Sendig Seq :" + currentSendingPackage.Seq);
                            //--------------------------------------------------------------------

                            stream.Write(data, 0, data.Length);
                            stream.Flush();
                            if (currentSendingPackage.type == CmdType.CmdReport)
                            {
                                currentSendingPackage.result = CmdResult.ACK;
                                System.Threading.Monitor.Pulse(currentSendingPackage);

                            }

                            if (System.Threading.Monitor.Wait(stream, T0ms))
                            {
                                //No Time Out

                                //lock (CurrSendingproxyobj)
                                //{

                                if (this.currentSendingPackage.result == CmdResult.ACK)
                                {
                                    lock (currentSendingPackage)
                                    {
                                        System.Threading.Monitor.Pulse(currentSendingPackage);

                                    }
                                }
                                else
                                {

                                        TimeOutQueue.Enqueue(currentSendingPackage);//nak ,time out
                                        currentSendingPackage = null;

                                }
                                //}

                            }
                            else
                            {
                                //Time out

                                //lock (CurrSendingproxyobj)
                                //{

                                  //  if (currentSendingPackage.result == CmdResult.Unknown)
                                        currentSendingPackage.result = CmdResult.TimeOut;

                                        TimeOutQueue.Enqueue(currentSendingPackage);
                                        this.currentSendingPackage = null;

                                //}
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (this.OnCommError != null)
                            OnCommError(this, ex);
                        if (!this.getEnable())
                        {

                            Console.WriteLine(m_devName + "send task exit");
                            return;
                        }
                        //  Console.WriteLine(ex.Message);
                    }

                }
                catch
                {
                    ;
                }

                }//while
        }
Exemple #48
0
        public void SendDirect(SendPackage pkg)
        {
            if (v2dle == null) return;
            byte[] data = this.v2dle.PackData(pkg.address, pkg.text, (byte)pkg.Seq);

            System.IO.Stream stream = v2dle.GetStream();
            lock (stream)
            {
                stream.Write(data, 0, data.Length);
            }
            // v2dle.isReportCmd = true;
        }
Exemple #49
0
 void PropertyBag_OnHWStatus_Changed(object sender, EventArgs e)
 {
     try
     {
         SendPackage pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, this.ControllerID, new byte[] { 0x0a, PropertyBag.HWtatus[0], PropertyBag.HWtatus[1], PropertyBag.HWtatus[2], PropertyBag.HWtatus[3] });
         //throw new NotImplementedException();
         if (v2dle != null)
             v2dle.Send(pkg);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message + "," + ex.StackTrace);
     }
 }
Exemple #50
0
 public void TC_SetDisplayOff(byte laneid)
 {
     SendPackage pkg;
     byte[] data = new byte[] { 0x5f, 0x23, laneid };
     pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, 0xffff, data);
     this.Send(pkg);
     //lock (currDispLockObj)
     //{
     if (currentDispalyDataset[laneid - 1] != null)
         InvokeOutPutChangeEvent(this, "laneid:" + laneid + " 熄滅");
         currentDispalyDataset[laneid - 1] = null;
         currentDisplayPackage[laneid - 1] = pkg;
         curr_speedlimits[laneid - 1] = -1;
         curr_mesg[laneid - 1] = "";
         curr_g_code_id[laneid - 1] = 0;
     //}
 }
Exemple #51
0
        public override void TC_SetDisplayOff()
        {
            checkConntected();
              SendPackage pk = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0xdf,0xd3 });
              this.m_device.Send(pk);
              if (pk.result != CmdResult.ACK)
              Console.WriteLine(m_deviceName + ":set display off" + pk.result);

              if (currentDispalyDataset != null )
              this.InvokeOutPutChangeEvent(this, "熄滅");

              this.currentDispalyDataset = null;
        }
Exemple #52
0
 void m_device_OnSendingPackage(object sender, SendPackage pkg)
 {
     try
       {
       this.notifier.NotifyAll(new NotifyEventObject(EventEnumType.MFCC_Comm_Moniter_Event, ((Comm.I_DLE)sender).getDeviceName(),
            "==>" + DateTime.Now.ToLongTimeString() + "," + pkg));
       }
       catch { ;}
 }
Exemple #53
0
        void LSTC_OnConnectStatusChanged(object tc)
        {
            try
              {
              if (((TCBase)tc).IsConnected)
              {
                  try
                  {
                      this.TC_SendCycleSettingData();
                  }
                  catch (Exception ex1)
                  {
                      ConsoleServer.WriteLine(this.DeviceName + "," + ex1.Message);
                  }
                  ConsoleServer.WriteLine(((TCBase)tc).DeviceName + "  set cycle settting!");
                  System.DateTime dt = System.DateTime.Now.AddMinutes(-DateTime.Now.Minute);
                  byte[] data = new byte[] { 0x35, (byte)dt.Day, (byte)dt.Hour, (byte)((dt.Minute/10) *10) };

                  try
                  {
                      Comm.SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.B, 0xffff, data);
                      this.Send(pkg);
                      if (pkg.ReturnTextPackage == null)
                          return;
                      try
                      {
                          DataSet ds = this.m_protocol.GetReturnDsByTextPackage(pkg.ReturnTextPackage);

                          last_receive_time = dt;
                          this.currData = ds;
                      }
                      catch (Exception ex1)
                      {
                          ConsoleServer.WriteLine(this.DeviceName + "," + ex1.Message + "," + ex1.StackTrace);
                      }
                  }
                  catch (Exception ex)
                  {
                      ConsoleServer.WriteLine(this.DeviceName + "," + ex.Message+","+ex.StackTrace);
                  }

              }

              }
              catch (Exception ex)
              {
              ConsoleServer.WriteLine(ex.Message + ex.StackTrace);
              }
        }
Exemple #54
0
        private void TC_SetModeAndPlanNo(byte mode, byte planno)
        {
            checkConntected();

              if (mode == 5) //手動燈號模式
              {
                SendPackage pkg;
                   try
                  {
                       pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0xA5, 01 });
                      m_device.Send(pkg);
                  }
                  catch { ;}

                  pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, 0xffff, new byte[] { 0x81,(byte)( planno%10),(byte)(planno/10) });

                  // planno > 10 開啟警示燈 <10 關閉警示燈
                  m_device.Send(pkg);

              }

              else

              if (this.IsF311z)
              {
                  SendPackage pkg = null;
                  try
                  {
                      pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0xA5, 01 });
                      m_device.Send(pkg);
                  }
                  catch { ;}

                  //if (mode == 0 || mode == 4)  //fixed,local area integreted
                  //{

                  //    pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x83, planno, 1, 1 });
                  //    m_device.Send(pkg);
                  //}

                  pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x80, mode });
                  m_device.Send(pkg);

                  if (mode == 0 || mode == 4)  //fixed,local area integreted
                  {
                      System.Threading.Thread.Sleep(40 * 1000);  //wait for 90 sec
                      pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x83, planno, 1, 1 });
                      m_device.Send(pkg);
                  }

              }
              else
              {
                  SendPackage pkg = null;
                  try
                  {
                      pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0xA5, 01 });
                      m_device.Send(pkg);
                  }
                  catch { ;}

                  pkg = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x82, mode,planno });
                  m_device.Send(pkg);

              }

              string sql = "update tblRMSConfig set last_mode={0},last_planno={1} where devicename='{2}'";
              this.InvokeDBDemand(string.Format(sql, mode, planno, this.DeviceName));
        }
Exemple #55
0
        public override void TC_SetDisplayOff()
        {
            checkConntected();
              byte []data = new byte[] { 0xa5, 2 };
              if (!this.isDisplayOff )
                  this.InvokeOutPutChangeEvent(this, "儀控中止");

              SendPackage pkg=new SendPackage( CmdType.CmdSet,CmdClass.B,0xffff,data);
              Send(pkg);
              isDisplayOff=true;
              //throw new Exception("The method or operation is not implemented.");
        }
Exemple #56
0
 public void PostSend(SendPackage pkg)
 {
     new System.Threading.Thread(PostSendThreadJob).Start(pkg);
 }
Exemple #57
0
        public void Send(SendPackage[] pkgs)
        {
            foreach(SendPackage pkg in pkgs)
            {
                try{

                    Send(pkg);
                } catch{;}
            }

             //   isReportCmd = true;
        }
Exemple #58
0
 public override int TC_SetDateTime(int year, int mon, int day, int hour, int min, int sec)
 {
     //  return base.TC_SetDateTime(year, mon, day, hour, min, sec);
        byte[] data = new byte[] { 0x20, (byte)(year / 256), (byte)(year % 256), (byte)mon, (byte)day, (byte)hour, (byte)min, (byte)sec };
        SendPackage  pkg=new SendPackage(CmdType.CmdSet,CmdClass.A,0xffff,data);
        this.Send(pkg);
        return 0;
 }
Exemple #59
0
        void RDTC_OnConnectStatusChanged(object tc)
        {
            // throw new Exception("The method or operation is not implemented.");
            try
            {
                if (((TCBase)tc).IsConnected)
                {
                    this.TC_SendCycleSettingData();
                    ConsoleServer.WriteLine(((TCBase)tc).DeviceName + "  set cycle settting!");
                    System.DateTime dt = System.DateTime.Now.AddMinutes(-5);
                    byte[] data = new byte[] { 0x4d, (byte)dt.Day, (byte)dt.Hour, (byte)(dt.Minute / 5 * 5) };
                    Comm.SendPackage pkg = new SendPackage(CmdType.CmdQuery, CmdClass.B, 0xffff, data);
                    this.Send(pkg);

                    this.curr_amount = (pkg.ReturnTextPackage.Text[8] == 255) ? -1 : pkg.ReturnTextPackage.Text[8];
                    this.curr_acc_amount = (pkg.ReturnTextPackage.Text[9] * 256 + pkg.ReturnTextPackage.Text[10] == 65535) ? -1 : pkg.ReturnTextPackage.Text[9] * 256 + pkg.ReturnTextPackage.Text[10];
                    this.curr_degree = (pkg.ReturnTextPackage.Text[11]==255)?-1:pkg.ReturnTextPackage.Text[11];
                    last_receive_time = dt;

                }
               // System.Data.DataSet ds = this.m_protocol.GetETTU_ReturnDsByTextPackage(pkg.ReturnTextPackage);
            }
            catch(Exception ex) {
             ConsoleServer.WriteLine(ex.Message+ex.StackTrace)   ;}
        }
Exemple #60
0
        protected override void CheckDisplayTask()
        {
            System.Data.DataSet ds;
               bool isEqual = true;
              // if (currentDispalyDataset == null || !IsConnected) return;
              try
              {

              //  System.Data.DataSet ds=this.TC_GetDisplay();
              if (!this.IsConnected)
                  return;
            lock(this.currDispLockObj)
            {

                string dev_display = "";
                byte[] time = new byte[3];
               // bool isWrong = false;
                for (int i = 0; i < 3; i++)
                {
                    ds = this.TC_GetDisplay(i+1);
                    for (int j = 0; j < 3; j++)
                    {
                        isEqual = isEqual && (currDisplayBytes[i][j] == System.Convert.ToByte(ds.Tables[0].Rows[0]["travel_time" + (j + 1)]));
                        time[j] = System.Convert.ToByte(ds.Tables[0].Rows[0]["travel_time" + (j + 1)]);
                    }
                    if (!isEqual)
                    {

                        dev_display += "boardid" + (i + 1) + ":" + System.Text.ASCIIEncoding.ASCII.GetString(time, 0, 3);

                     //   this.InvokeOutPutWrongEvent(GetCurrentDisplayDecs(), GetDisplayDesc(ds));
                        SendPackage pk = new SendPackage(CmdType.CmdSet, CmdClass.A, m_deviceid, new byte[] { 0x5f, 0x17, (byte)(i + 1), currDisplayBytes[i][0], currDisplayBytes[i][1], currDisplayBytes[i][2], currDisplayBytes[i][3] });
                        this.m_device.Send(pk);

                    }
                }

                if (!isEqual)
                {
                    ConsoleServer.WriteLine(this.DeviceName + " 顯示資料比對錯誤!" + GetCurrentDisplayDecs() + "," + dev_display);
                    this.InvokeOutPutWrongEvent(GetCurrentDisplayDecs(), dev_display);
                }

            //bool isEqual = true;
            //for (int i = currentDispalyDataset.Tables[0].Columns.IndexOf("data_type"); i < currentDispalyDataset.Tables[0].Columns.Count; i++)
            //{
            //    isEqual = isEqual && (currentDispalyDataset.Tables[0].Rows[0][i].Equals(ds.Tables[0].Rows[0][currentDispalyDataset.Tables[0].Columns[i].ColumnName]));
            //}

            }
                   // this.OnOutputDataCompareWrongEvent(this, currentDispalyDataset);

              }
              catch (Exception ex)
              {
              ConsoleServer.WriteLine("in check display task"+ex.Message+ex.StackTrace);
              }
        }