Click here to Skip to main content
15,868,292 members
Articles / Programming Languages / C#

FT857D Manager Ham Radio Controller

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
22 Mar 2016CPOL4 min read 16.7K   386   6   7
Change the frequency , the mode and sent morse code on radio
Image 1 Image 2
Image 3 Image 4
Image 5 Image 6

Introduction

The code connects to a Ham Radio via CAT cable and it changes the frequency and mode on the Radio. It also sends the CW (morse code) via a cable connected to the Radio CW keyer stick from a USB-to-SERIAL port and with two resistors and an NPN transistor. So it uses the Radio's own sound device and a sound card is not used for sending morse code.

Background

The idea was to make a Radio controller controlled by the computer and learn how to use CAT commands. So the first part of the project was to create a program that could change the frequency on screen and later connect to the radio so the CAT command could be used to change the frequency and the mode (LSB,USB,CW) on the radio by pushing a button on in the Windows application. So I started to write the software and ordered the CAT cable and a USB-to-USB cable. When the cable came I finished the 1.0 version of the program. After that, I was challenged to make the CW (morse code) sending part. I ordered new cables and get make some test and code the CW part of the application.

Using the Code

The code is built in three parts. One Windows project and two class libraries. The first class library is called ft857d and it controls the CAT connections to the radio. The second class library is called ft857dcw and it controls the cw sending to the radio.

Image 7

This part of the code in the CAT controller change the frequency on the radio. It gets a string from eight textboxes (the frequency ex. "01,40,00,00" for the 14MHz). It first removes the "," then converts to a 16 byte (40 - 0x40). Then it sends the byte array to the COM port and changes the frequency on the radio.

C#
public void WriteTx(string tx)
       {

           string a = tx.Substring(0, 2);
           string b = tx.Substring(3, 2);
           string c = tx.Substring(6, 2);
           string d = tx.Substring(9, 2);


           byte[] talbyte = { Convert.ToByte(a, 16), Convert.ToByte(b, 16), Convert.ToByte(c, 16), Convert.ToByte(d, 16), 0x01};

           try {



                   comPort.Write(talbyte, 0, talbyte.Length);

           }
           catch  {  }

       }

This code in the CW controller takes the text from the textboxes and translate it to morse code. For example: "abc de" ".-¤-...¤-.-. -..¤." The ¤ is set between the letters and space is just a space.

C#
 public void createCW(string text, int wpm)
        {
            text = text.ToLower();
            int dit = 1200 / wpm;
            string cwText = "";
            char[] ctext = text.ToCharArray();
            for(int i=0; i<ctext.Length; i++)
            {
                cwText += CW(ctext[i]);
                cwText += "¤";

            }
            sentCW(cwText, dit);
        }

private string CW(char letter)
        {   
            string cwtext = "";
            switch (letter)
            {
                case 'a':
                    cwtext = ".-";
                    break;
                case 'b':
                    cwtext = "-...";
                    break;

This part of the code in the CW controller sends the code to the radio. It opens the COM port and when the DRT is true, it sends a tone and close when the DRT is false. Thread.sleeping is a how long the tone has to be sent or wait before it is sent the next letter. The "dit" is the "." and "dah" is the "-".

C#
private void sentCW(string cwtext, int dit)
       {
           try
           {
               int dah = 3 * dit;
               int space = 5 * dit;
               comPort.Open();
               char[] cw = cwtext.ToCharArray();
               for (int a = 0; a < cw.Length; a++)
               {
                   switch (cw[a])
                   {
                       case '.':
                           comPort.DtrEnable = true; ;
                           System.Threading.Thread.Sleep(dit);
                           comPort.DtrEnable = false;
                           break;
                       case '-':
                           comPort.DtrEnable = true; ;
                           System.Threading.Thread.Sleep(dah);
                           comPort.DtrEnable = false;
                           break;
                       case '¤':

                           System.Threading.Thread.Sleep(dah);

                           break;
                       case ' ':

                           System.Threading.Thread.Sleep(space);

                           break;
                   }
                   System.Threading.Thread.Sleep(dit);
               }
               comPort.Close();
           }
           catch { MessageBox.Show("You have to connect a CW Com Port."); }
       }

The program is in C#.

Points of Interest

When I was beginning to code the Windows Application I think that I was not able to get it to work. It looked too difficult and I was worried a lot about how it was gonna work when I ordered the cables. I ordered cables two times. First the CAT cable and the USB-to-USB. After that worked, I ordered the USB-SERIAL and SERIAL-to-SERIAL and the two 10kOhm resistors and the NPN BD 135 transistor because I also have to solder some the component. I am not good at electronics so I thought I might not be able to finish the project. But I was very surprised over how easy it was and I was also able to learn about thread sleeping.

I ran into a problem when I changed the frequency on the radio. It would only change the Tx frequency and not the Rx frequency, but I was told I needed to just add thread sleeping into the code.

This code is in Form1.cs and is activated when the Update button in the Radio or in the memory Tab.

C#
private void Update_Write(string con)
       {

           FT857D_CatControl.Instance.PortName = comboPortsCAT.Text;
           FT857D_CWControl.Instance.PortName = comboPortsCW.Text;
           FT857D_CatControl.Instance.DisplayWindow = rtbDisplay;
           FT857D_CWControl.Instance.DisplayWindow = rtbDisplay;
           SerialPort comPort = FT857D_CatControl.Instance.OpenPort();
           SerialPort comPort1 = FT857D_CWControl.Instance.OpenPort();
           nr++;
           if (con == "ptt")
           {
                 if (comPort.CtsHolding)
                 {
               try
               {
                   string msgMode = comboMode.Text;
                   FT857D_CatControl.Instance.SetMode(msgMode);

                   FT857D_CatControl.Instance.ToggleVFO();
                   System.Threading.Thread.Sleep(200);
                   FT857D_CatControl.Instance.SetMode(msgMode);
                   string msgTx = lblFreTx_0.Text + lblFreTx_1.Text + "," + lblFreTx_2.Text + lblFreTx_3.Text + "," + lblFreTx_4.Text + lblFreTx_5.Text + "," + lblFreTx_6.Text + lblFreTx_7.Text;
                   FT857D_CatControl.Instance.WriteTx(msgTx);
                   System.Threading.Thread.Sleep(200);
                   FT857D_CatControl.Instance.ToggleVFO();

                   System.Threading.Thread.Sleep(200);
                   FT857D_CatControl.Instance.SetMode(msgMode);
                   string msgRx = lblFreRx_0.Text + lblFreRx_1.Text + "," + lblFreRx_2.Text + lblFreRx_3.Text + "," + lblFreRx_4.Text + lblFreRx_5.Text + "," + lblFreRx_6.Text + lblFreRx_7.Text;
                   FT857D_CatControl.Instance.WriteRx(msgRx);


               }
               catch (Exception ex) { MessageBox.Show(ex.ToString()); }

                   }
                        else { MessageBox.Show("You kneed to Connect your Radio"); }
           }

           FT857D_CatControl.Instance.ClosePort();

           FT857D_CWControl.Instance.ClosePort();
       }

Images on the listview. In the Form1.cs

C#
private void FillHelpTop()
       {
           listViewHelpTop.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
           ListViewItem item1 = new ListViewItem("Connect CAT", 0);
           item1.SubItems.Add("Connect");
           ListViewItem item2 = new ListViewItem("Connect CW", 0);
           item2.SubItems.Add("Connect");
           ListViewItem item3 = new ListViewItem("Select frequency", 1);
           item3.SubItems.Add("Radio");
           ListViewItem item4 = new ListViewItem("Edit Memory Stations", 2);
           item4.SubItems.Add("Memory");
           ListViewItem item5 = new ListViewItem("Wheater", 1);
           item5.SubItems.Add("Radio");
           ListViewItem item6 = new ListViewItem("Sent CW", 3);
           item6.SubItems.Add("CW");
           listViewHelpTop.Items.AddRange(new ListViewItem[] { item1, item2, item3,item4,item5,item6 });
       }

Change frequency by mouseclick

C#
private void lbl_MouseClick(object sender, MouseEventArgs e, string box)
       {
           int btTal = 0;
           switch (e.Button)
           {

               case MouseButtons.Left:

                   btTal = -1;
                   break;

               case MouseButtons.Right:

                   btTal = 1;
                   break;
           }
           int tal = 0;
           switch(box)
           {
               case "Tx0": tal = int.Parse(lblFreTx_0.Text) + btTal;
                   if (tal < 0) { tal = 4; } else if (tal >  4) { tal = 0; }
                   lblFreTx_0.Text = tal.ToString();
                   lblMemTx_0.Text = tal.ToString();
                   break;
               case "Tx1":
                   tal = int.Parse(lblFreTx_1.Text) + btTal;
                   if (tal < 0) { tal = 9; } else if (tal >  9) { tal = 0; }
                   lblFreTx_1.Text = tal.ToString();
                   lblMemTx_1.Text = tal.ToString();
                   break;

History

  • Version 1.0 (never released only to test) XML database for radio memory and changing frequecy on the radio.
  • Version 2.0 (this version) XML database for CW memory and morse code text could be sent via the radio.

Thanks

Thanks to Michael OZ8AGB for guiding me though the project and it was his idea that I should make the project.

Thanks to Bjarne OZ7BKJ for the help with the xml gateway.

Thanks to Niels OZ5NM that showed my the diagram how to solder the resistors and transistors.

Thanks to my litle brother Brian that guided me how to create the CW translator.

The Connect code to the Com Port was something I found on the WEB.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Denmark Denmark
My name is Tommy Clemmensen

My call is OZ1THC that is a danish Amatour Callsign.

I am from 1967 years old.
And is a before pensionist.

Comments and Discussions

 
QuestionGreat Article! Minor Edits ... Pin
bling22-Mar-16 10:50
bling22-Mar-16 10:50 
AnswerRe: Great Article! Minor Edits ... Pin
Member 1233878922-Mar-16 11:21
Member 1233878922-Mar-16 11:21 
AnswerRe: Great Article! Minor Edits ... Pin
Member 1233878922-Mar-16 12:31
Member 1233878922-Mar-16 12:31 
GeneralRe: Great Article! Minor Edits ... Pin
bling22-Mar-16 13:06
bling22-Mar-16 13:06 
GeneralRe: Great Article! Minor Edits ... Pin
Member 1233878922-Mar-16 13:26
Member 1233878922-Mar-16 13:26 
GeneralRe: Great Article! Minor Edits ... Pin
Member 1233878922-Mar-16 13:55
Member 1233878922-Mar-16 13:55 
GeneralRe: Great Article! Minor Edits ... Pin
Member 1233878923-Mar-16 0:08
Member 1233878923-Mar-16 0:08 
I run in to another problem and thought I have turned the transitor the wrong way because the station dont sent a tone when i set the DTR to true, so i turn it around and found out I had set it correct the first time and had to resolder some times. I find out that I had just forgot to Open the Com Port comm.Open() in the code.

Tommy

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.