private int searchforProtocolAndBaud_sub(ref CommunicationManager comm) { string[] strArray = new string[10]; string[] strArray2 = new string[10]; string str = string.Empty; string str2 = string.Empty; comm.portDataInit(); if (comm.MessageProtocol == "NMEA") { comm.RxType = CommunicationManager.ReceiverType.NMEA; if (comm.waitforNMEAMsg()) { comm.AutoDetectProtocolAndBaudDone = true; return 1; } str = "OSP,NMEA,OSP,NMEA,OSP,OSP,OSP,OSP,OSP,OSP,OSP,OSP,NMEA,NMEA,NMEA,NMEA,NMEA"; str2 = "115200,4800,4800,115200,38400,9600,57600,19200,230400,460800,912600,1228800,38400,9600,57600,19200,115200"; } else if (comm.MessageProtocol == "OSP") { comm.RxType = CommunicationManager.ReceiverType.SLC; if (comm.waitforSSBMsg()) { comm.AutoDetectProtocolAndBaudDone = true; return 1; } str = "NMEA,OSP,NMEA,OSP,NMEA,NMEA,NMEA,NMEA,NMEA,OSP,OSP,OSP,OSP,OSP,OSP,OSP,OSP"; str2 = "4800,115200,115200,4800,38400,9600,57600,19200,115200,38400,9600,57600,19200,230400,460800,912600,1228800"; } else { comm.AutoDetectProtocolAndBaudDone = true; return 2; } strArray = str2.Split(new char[] { ',' }); strArray2 = str.Split(new char[] { ',' }); frmSimpleDialog dialog = new frmSimpleDialog("Auto Detect Baud"); dialog.Show(); for (int i = 0; i < strArray2.Length; i++) { comm.AutoDetectProtocolAndBaudDone = false; dialog.DisplayMessage = string.Format("\tDetecting {0} - {1}\n\n\t\tPlease wait...", strArray2[i], strArray[i]); dialog.ShowMessage(); if ((comm.CurrentProtocol != strArray2[i]) || (comm.CurrentBaud != strArray[i])) { comm.BaudRate = strArray[i]; comm.MessageProtocol = strArray2[i]; if (strArray2[i] == "OSP") { comm.RxType = CommunicationManager.ReceiverType.SLC; comm.RxTransType = CommunicationManager.TransmissionType.GPS; } else { comm.RxType = CommunicationManager.ReceiverType.NMEA; comm.RxTransType = CommunicationManager.TransmissionType.Text; } Refresh(); comm.SetupRxCtrl(); uint baud = uint.Parse(comm.BaudRate); bool flag = false; int num3 = 0; while (num3++ < 5) { flag = comm.comPort.UpdateBaudSettings(baud); if (flag) { break; } } if (!flag) { dialog.Close(); comm.ErrorPrint("Error updating port"); return 3; } comm.portDataInit(); Thread.Sleep(5); if (comm.MessageProtocol == "OSP") { if (comm.waitforSSBMsg()) { comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 1; } } else if (comm.MessageProtocol == "NMEA") { if (comm.waitforNMEAMsg()) { comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 1; } } else { comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 2; } } } comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 3; }
public void AutoDetectBaudAfterFacRst4E(ref CommunicationManager targetComm) { if (CommunicationManager.ValidateCommManager(targetComm)) { targetComm.AutoDetectProtocolAndBaudDone = false; targetComm.RxCurrentTransmissionType = CommunicationManager.TransmissionType.Text; targetComm.TxCurrentTransmissionType = CommunicationManager.TransmissionType.Text; targetComm.BaudRate = "4800"; targetComm.Flag_didFacRst_atSSB = true; uint baud = uint.Parse(targetComm.BaudRate); targetComm.comPort.UpdateBaudSettings(baud); targetComm.portDataInit(); targetComm.AutoDetectProtocolAndBaudDone = true; string msg = NMEAReceiver.NMEA_AddCheckSum(string.Format("$PSRF100,0,{0},8,1,0", targetComm.ToSwitchBaud)); msg = NMEAReceiver.NMEA_AddCheckSum("$PSRF105,1") + "\r\n" + msg; targetComm.WriteData(msg); Thread.Sleep(0x3e8); targetComm.RxType = CommunicationManager.ReceiverType.SLC; targetComm.RxCurrentTransmissionType = CommunicationManager.TransmissionType.GPS; targetComm.TxCurrentTransmissionType = CommunicationManager.TransmissionType.GP2; targetComm.BaudRate = targetComm.ToSwitchBaud; int num2 = 0; uint num3 = uint.Parse(targetComm.BaudRate); while (num2++ < 5) { if (targetComm.comPort.UpdateBaudSettings(num3)) { break; } Thread.Sleep(1); } targetComm.portDataInit(); targetComm.AutoDetectProtocolAndBaudDone = true; } }
private int searchforProtocolAndBaud(ref CommunicationManager comm) { comm.AutoDetectProtocolAndBaudDone = false; comm.CurrentProtocol = comm.MessageProtocol; comm.CurrentBaud = comm.BaudRate; Refresh(); if (!comm.OpenPort()) { return 0; } Thread.Sleep(10); int num = searchforProtocolAndBaud_sub(ref comm); if (num == 3) { comm.BaudRate = comm.CurrentBaud; comm.MessageProtocol = comm.CurrentProtocol; if (comm.CurrentProtocol == "OSP") { comm.RxType = CommunicationManager.ReceiverType.SLC; comm.RxTransType = CommunicationManager.TransmissionType.GPS; } else { comm.RxType = CommunicationManager.ReceiverType.NMEA; comm.RxTransType = CommunicationManager.TransmissionType.Text; } comm.SetupRxCtrl(); comm.comPort.BaudRate = int.Parse(comm.BaudRate); comm.comPort.UpdateSetttings(); comm.portDataInit(); } comm.AutoDetectProtocolAndBaudDone = true; return num; }