Example #1
0
 private void frmSwitchProtocolsSetBtn_Click(object sender, EventArgs e)
 {
     if (CommunicationManager.ValidateCommManager(this.comm))
     {
         string        msg     = string.Empty;
         StringBuilder builder = new StringBuilder();
         if (this.comm.MessageProtocol == "NMEA")
         {
             if (this.frmSwitchProtocolNMEARadioBtn.Checked)
             {
                 return;
             }
         }
         else if (this.frmSwitchProtocolSSBRadioBtn.Checked)
         {
             return;
         }
         if (this.frmSwitchProtocolNMEARadioBtn.Checked)
         {
             int    num         = 1;
             string messageName = "Switch to NMEA Protocol";
             clsGlobal.ToSwitchProtocol = "NMEA";
             this.comm.ToSwitchProtocol = "NMEA";
             builder.Append("129,2,");
             try
             {
                 num = Convert.ToByte(this.frmSwitchProtocolGGARateComboBox.Text);
             }
             catch
             {
                 num = 1;
             }
             builder.Append(num);
             builder.Append(",1,");
             try
             {
                 num = Convert.ToByte(this.frmSwitchProtocolGLLRateComboBox.Text);
             }
             catch
             {
                 num = 1;
             }
             builder.Append(num);
             builder.Append(",1,");
             try
             {
                 num = Convert.ToByte(this.frmSwitchProtocolGSARateComboBox.Text);
             }
             catch
             {
                 num = 1;
             }
             builder.Append(num);
             builder.Append(",1,");
             try
             {
                 num = Convert.ToByte(this.frmSwitchProtocolGSVRateComboBox.Text);
             }
             catch
             {
                 num = 1;
             }
             builder.Append(num);
             builder.Append(",1,");
             try
             {
                 num = Convert.ToByte(this.frmSwitchProtocolRMCRateComboBox.Text);
             }
             catch
             {
                 num = 1;
             }
             builder.Append(num);
             builder.Append(",1,");
             try
             {
                 num = Convert.ToByte(this.frmSwitchProtocolVTGRateComboBox.Text);
             }
             catch
             {
                 num = 1;
             }
             builder.Append(num);
             builder.Append(",1,0,1,0,0,0,1,0,0,");
             builder.Append(this.frmSwitchProtocolBaudRateComboBox.Text);
             msg = this.comm.m_Protocols.ConvertFieldsToRaw(builder.ToString(), messageName, "SSB");
             if (msg == string.Empty)
             {
                 clsGlobal.PerformOnAll = false;
                 return;
             }
         }
         else
         {
             builder.Append("$PSRF100,0,");
             builder.Append(this.frmSwitchProtocolBaudRateComboBox.Text);
             builder.Append(",8,1,0");
             msg = NMEAReceiver.NMEA_AddCheckSum(builder.ToString());
             msg = NMEAReceiver.NMEA_AddCheckSum("$PSRF105,1") + "\r\n" + msg;
             clsGlobal.ToSwitchProtocol = "OSP";
             this.comm.ToSwitchProtocol = "OSP";
         }
         clsGlobal.ToSwitchBaudRate = this.frmSwitchProtocolBaudRateComboBox.Text;
         if (clsGlobal.PerformOnAll)
         {
             foreach (string str3 in clsGlobal.g_objfrmMDIMain.PortManagerHash.Keys)
             {
                 PortManager manager = (PortManager)clsGlobal.g_objfrmMDIMain.PortManagerHash[str3];
                 if (((manager != null) && manager.comm.IsSourceDeviceOpen()) && (manager.comm.ProductFamily == CommonClass.ProductType.GSD4e))
                 {
                     manager.comm.ToSwitchProtocol = clsGlobal.ToSwitchProtocol;
                     manager.comm.ToSwitchBaud     = clsGlobal.ToSwitchBaudRate;
                     manager.comm.WriteData(msg);
                 }
             }
             clsGlobal.PerformOnAll = false;
         }
         else
         {
             this.comm.ToSwitchProtocol = clsGlobal.ToSwitchProtocol;
             this.comm.ToSwitchBaud     = clsGlobal.ToSwitchBaudRate;
             this.comm.WriteData(msg);
         }
         base.DialogResult = DialogResult.OK;
         base.Close();
     }
 }
 private void UpdateRawDataToSendBox()
 {
     if (this.frmTransmitSerialMessageInputText.Text.Length != 0)
     {
         this.frmTransmitSerialMessageInputText.Text = this.frmTransmitSerialMessageInputText.Text.Replace("\r\n", "");
         StringBuilder builder = new StringBuilder();
         if (this.frmTransmitSerialMessageNmeaRadioBtn.Checked)
         {
             this.frmTransmitSerialMessageOutputText.Text = NMEAReceiver.NMEA_AddCheckSum(this.frmTransmitSerialMessageInputText.Text);
         }
         else if (this.frmTransmitSerialMessageRawRadioBtn.Checked)
         {
             this.frmTransmitSerialMessageOutputText.Text = this.frmTransmitSerialMessageInputText.Text;
         }
         else
         {
             builder.Append("A0A2");
             string str   = this.frmTransmitSerialMessageInputText.Text.Replace(" ", "").Replace("\r", "").Replace("\n", "");
             int    num   = str.Length / 2;
             bool   slcRx = false;
             try
             {
                 if (((this.comm._rxType == CommunicationManager.ReceiverType.SLC) || (this.comm._rxType == CommunicationManager.ReceiverType.TTB)) && (this.comm.MessageProtocol != "OSP"))
                 {
                     num++;
                     slcRx = true;
                 }
                 if (this.frmTransmitSerialMessageSsbRadioBtn.Checked)
                 {
                     if (this.comm._rxType == CommunicationManager.ReceiverType.SLC)
                     {
                         str = "EE" + str;
                     }
                 }
                 else if (!this.frmTransmitSerialMessageOspRadioBtn.Checked)
                 {
                     if (this.frmTransmitSerialMessageFRadioBtn.Checked)
                     {
                         str = "02" + str;
                         num++;
                     }
                     else if (this.frmTransmitSerialMessageAi3RadioBtn.Checked)
                     {
                         str = "01" + str;
                         num++;
                     }
                     else if (this.frmTransmitSerialMessageTTBRadioBtn.Checked)
                     {
                         str = "CC" + str;
                         num++;
                     }
                 }
                 builder.Append(num.ToString("X").PadLeft(4, '0'));
                 builder.Append(str);
                 builder.Append(this.comm.m_Protocols.GetChecksum(str, slcRx));
                 builder.Append("B0B3");
                 this.frmTransmitSerialMessageOutputText.Text = builder.ToString();
             }
             catch
             {
                 MessageBox.Show("Error in building message", "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             }
         }
     }
 }