Usually the police will arrange for consular access if you request it, whether they know what number to call is a different matter. Good preparation for your visit would be to keep the local consulate emergency numbers handy in your passport (or stored in your phone) and ask to be put in touch with your countries consulate. Don't get your hopes up high, the consulate usually gets you in touch with a lawyer from their list to assist in the legal process, which is the same for anyone. In the eye of the law you are a foreigner, but that really doesn't matter to the judge. At most you may be sent home to serve the sentence in your home country. Some developed nations are pretty successful in obtaining such concessions.
Diplomatic immunity is also not limitless. The police can arrest and detain diplomats if they think they committed an offence or can help in the resolution of a crime. They can't be prosecuted or 'punished' but simply sent home.