A judge has ordered a former Maine State Police chief accused of sexually assaulting a 4-year-old child to undergo a mental examination.

Andrew Demers Jr., 74, of New Gloucester has remained free on $5,000 bail since his arrest March 17. He pleaded not guilty on April 16 to a two-count indictment charging him with gross sexual assault and unlawful sexual contact.

Superior Court Justice Roland Cole issued an order on July 8 granting a motion by Demers’ attorney, Walter McKee, requesting that the State Forensic Service conduct a mental evaluation to assess Demers’ sanity within 45 days.

If Demers is convicted, he would face as many as 30 years in prison for gross sexual assault, a Class A felony. The charge of unlawful sexual contact is a Class B felony, punishable by a maximum of 10 years in prison.

Cumberland County Sheriff Kevin Joyce has said that Demers admitted to assaulting the child multiple times, but McKee has said he has not seen a written confession.

State police got a tip about the alleged crimes March 10 and referred it to the district attorney, who asked the sheriff’s office to investigate. The District Attorney’s Office and McKee arranged for Demers to turn himself in at the county jail.

Demers, named a Legendary Trooper in 2003, served 26 years with the state police and held the department’s top position from 1987 to 1993, when he retired.

McKee also has filed a motion seeking to amend the conditions of Demers’ bail. He is currently barred from having any contact with the alleged victim in the case and any children younger than 16. McKee is asking that Demers still be allowed contact with his four grandchildren.

A hearing on the motion to amend bail conditions is set for Tuesday. Demers’ trial is tentatively set for Sept. 22.