private int searchforProtocol_I2C(ref CommunicationManager comm) { comm.AutoDetectProtocolAndBaudDone = false; comm.CurrentProtocol = comm.MessageProtocol; if (!comm.OpenPort()) { return 0; } Thread.Sleep(5); frmSimpleDialog dialog = new frmSimpleDialog("Auto Detect Protocol"); dialog.Show(); dialog.MdiParent = clsGlobal.g_objfrmMDIMain; dialog.DisplayMessage = string.Format("\tDetecting {0}\n\n\t\t Please wait...", "NMEA"); dialog.ShowMessage(); if (comm.waitforNMEAMsg_I2C() != string.Empty) { comm.AutoDetectProtocolAndBaudDone = false; Thread.Sleep(50); if (!comm.ClosePort()) { dialog.Close(); return 0; } Thread.Sleep(5); comm.RxType = CommunicationManager.ReceiverType.NMEA; comm.RxType = CommunicationManager.ReceiverType.SLC; if (!comm.OpenPort()) { dialog.Close(); return 0; } comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 1; } dialog.DisplayMessage = string.Format("\tDetecting {0}\n\n\t\t Please wait...", "OSP"); dialog.ShowMessage(); if (comm.waitforSSBMsg_I2C() != string.Empty) { comm.AutoDetectProtocolAndBaudDone = false; Thread.Sleep(50); if (!comm.ClosePort()) { dialog.Close(); return 0; } Thread.Sleep(5); comm.MessageProtocol = "OSP"; comm.RxType = CommunicationManager.ReceiverType.SLC; if (!comm.OpenPort()) { dialog.Close(); return 0; } comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 1; } dialog.Close(); return 2; }
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; }