Ejemplo n.º 1
0
 public NetworkLayerProtocol()
 {
     sendFuc += _nF =>
     {
         DataLinkLayer.ActionDllSendFuc(_nF);
     };
 }
Ejemplo n.º 2
0
        private static void SynchroSend(object sfc_object)
        {
            var sfc = sfc_object as ApplicationLayerProtocol;

            //字节小于7个
            if (sfc.A_Data.Count <= 7)
            {
                SemaphorePool.Wait();
                List <byte> sendData = new List <byte> {
                };
                sendData.AddRange(NetworkLayerDataBuffer.SetSingleFrame(sfc.A_Data.Count));
                sendData.AddRange(sfc.A_Data);

                DataLinkLayer.ActionDllSendFuc(ConvertToCANFrame(sfc.Address, sendData));
                SemaphorePool.Release();
            }
            else
            {
                BufferMultiFrameSend.ListNetLayerByteData = sfc.A_Data;
                BufferMultiFrameSend.nID = sfc.Address;

                #region 设置所有参数 重置参数
                BufferMultiFrameSend.RemainFrameCount = 1;  // 发送首帧
                BufferMultiFrameSend.Offset           = 0;
                BufferMultiFrameSend.ExpectedSN       = 0;
                #endregion

                ThreadPool.QueueUserWorkItem(NetworkLayerSendMultiFrame);
            }
        }
Ejemplo n.º 3
0
        public static void NetworkLayerSendMultiFrame(object obj)
        {
            string strSendBytes = DataFormatConvert.ListToStr(BufferMultiFrameSend.ListNetLayerByteData);

            int nSendTimes = 0;

            try
            {
                while (true)
                {
                    if (BufferMultiFrameSend.Offset < BufferMultiFrameSend.ListNetLayerByteData.Count && BufferMultiFrameSend.RemainFrameCount > 0 &&
                        (MainWindow.m_OperateType == OperateType.WriteAllMasterPara ||    //ParaManageWnd.IsUpdateAllPara ||
                         MainWindow.m_OperateType == OperateType.WriteAllMasterAdjustPara ||
                         MainWindow.m_OperateType == OperateType.WriteMasterControlPara)) // (BufferMultiFrameSend.RemainFrameCount != 0)
                    {
                        if (BufferMultiFrameSend.Offset > 0)                              // 非首帧
                        {
                            DataLinkLayer.ActionDllSendFuc(BufferMultiFrameSend.SendConsecutiveFrame());
                        }
                        else
                        {
                            DataLinkLayer.ActionDllSendFuc(BufferMultiFrameSend.SendFirstFrame());
                        }

                        BufferMultiFrameSend.RemainFrameCount--;
                    }
                    else
                    {
                        if (MainWindow.m_OperateType != OperateType.WriteAllMasterPara)  //(!ParaManageWnd.IsUpdateAllPara)  // 关闭参数管理窗口,停止设置参数 清空发送数据
                        {
                            BufferMultiFrameSend.ClearMessage();
                        }

                        break;
                    }

                    Thread.Sleep(200);
                }
            }
            catch (Exception ex)
            {
            }
        }
Ejemplo n.º 4
0
        private void ReceiveFirstFrame(DataLayerEvent _event)
        {
            BufferMultiFrameReceive.nID     = _event.ID;
            BufferMultiFrameReceive.DataLen = NetworkLayerDataBuffer.GetFF_DLSign(_event.listData);
            if (BufferMultiFrameReceive.DataLen < 8)
            {
                return;
            }

            int nDataIndex = 2;

            BufferMultiFrameReceive.ListNetLayerByteData.Clear();
            BufferMultiFrameReceive.ListNetLayerByteData = new List <byte>(new byte[BufferMultiFrameReceive.DataLen]);


            for (int i = nDataIndex; i != 8; ++i)
            {
                BufferMultiFrameReceive.ListNetLayerByteData[(int)(i - nDataIndex)] = _event.listData[i];
            }

            int nCount = 0;

            if ((BufferMultiFrameReceive.DataLen - 6) / 7 == 0)
            {
                nCount = (BufferMultiFrameReceive.DataLen - 6) / 7;
            }
            else
            {
                nCount = (BufferMultiFrameReceive.DataLen - 6) / 7 + 1;
            }

            BufferMultiFrameReceive.Offset           = 6;
            BufferMultiFrameReceive.ProCtrlType      = ProtocolCtrlType.FlowControl;
            BufferMultiFrameReceive.RemainFrameCount = nCount;
            BufferMultiFrameReceive.ExpectedSN       = 1;

            DataLinkLayer.ActionDllSendFuc(BufferMultiFrameReceive.SendFlowControl());
        }