The invention discloses an ONU automatic detection and EPON-and-GPON-
adaptation method and device, and relates to the technical field of
PONs. The method comprises the steps of electrifying to start an ONU, running current access mode parameters of the ONU, judging that LOS signals of an
optical link are eliminated, using the ONU to detect downlink optical signals of an OLT, setting a framing mode of a medium
access control layer according to a current access mode of the ONU, running a frame delimiting state
machine according to the framing mode of the medium
access control layer, setting detection duration parameters, setting detection time according to the detection duration parameters, using the frame delimiting state
machine to detect whether the downlink optical signals reach a frame synchronous state or not, keeping the current access mode of the ONU if the downlink optical signals reach the frame synchronous state, and replacing the current access mode of the ONU if the downlink optical signals do not reach the frame synchronous state. According to the ONU automatic detection and EPON-and-GPON-
adaptation method and device, the access mode of the OLT can be automatically detected and adapted, the application range is wide, convenience is brought to use and dilatation of a communication
system, and existing resources and existing layouts can be effectively used.