BARNSTABLE — A West Yarmouth man was ordered held on $2,000 bail after allegedly assaulting a Barnstable police officer Friday.

Gerald Lopes Jr., 37, who is homeless, pleaded not guilty Tuesday in Barnstable District Court to charges of possession with intent to distribute a class B substance, assault and battery on a police officer, resisting arrest, disorderly conduct and trespassing.

Barnstable police were providing assistance to the Yarmouth Police Department on Friday, the day after Yarmouth K-9 Officer Sean Gannon was shot and killed while serving a warrant in Marstons Mills.

Lopes was involved in a scuffle with police shortly before 1 p.m. at The Cove at Yarmouth on Route 28 in West Yarmouth, after he refused to vacate a guest room.

Lopes appeared to be under the influence of narcotics when officers found him in the room, according to a police report.

As officers tried to stop Lopes from reaching for something in a backpack, he refused to release the bag and was brought to the ground, where he began kicking and thrashing at multiple officers. At one point he was able to get a hand free and lunged forward at officers before he was subdued with a stun gun, the report states.

A Barnstable police officer's hand was injured when he was kicked during the struggle, according to the report.

A stack of money totaling $535 and approximately 7 grams of cocaine were found on Lopes after he was arrested, the report says.

A Massachusetts Probation Service query showed Lopes had been convicted of a subsequent offense of possession with intent to distribute a class A substance in 2013.

A pretrial hearing has been scheduled for May 14.