// Reciver Control Program // Coded by UTAH // Create 2014/12/30 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Net; using System.Threading.Tasks; using System.Windows.Forms; namespace SUPRXCLV00 { public partial class Form1 : Form { // COMMON DATA AREAS char UDPopen_FLG = ' '; string remoteHost; // IP ADDRESS Int32 remotePort = 10040; // PROT-NO // RX use area Int64 BAND_Freq; Int64 MAIN_Freq; Int64 WORK_Freq; Int64 VFO1_Freq; Int64 VFO2_Freq; Int64 VFO3_Freq; // 453.5KHz Int64 VFO4_Freq; // 1732.5KHz Int64 STAT_width; // 100KHz Int64 Fstep; char STAT_whpos; // R L char STAT_filnw; // W N char STAT_2ndfl; // W M N char STAT_2ndfc; // filter cnt char STAT_vfo34 = '3'; // VFO3:3 VFO4:4 char STAT_step; // step cnt char STAT_mode; // L;USB U;USB C;CW R;RTTY A:AM(BFO OFF) char STAT_mcnt; // char STAT_Fmod; // L;low M;modile H;high char STAT_AGC; // AGC A:ON/N:OFF char STAT_INPUT; // in1,in2,in3 char STAT_IFSFT; // IF shift on/off char STAT_sdron; // SDR on/off char STAT_bfoif; // VFO4/VFO4 string WORK_Fdata; // Int16 WORK_step = 1; // step Freq Int16 WORK_stpc = 0; // step cntr // UDP init // UDP USE System.Net.Sockets.UdpClient UDP = new System.Net.Sockets.UdpClient(10040); // UDP CHECK PROC private delegate void Delegate_RcvData(string Rdata, Int32 Rleng); public Form1() { InitializeComponent(); } // UDP read PROC public void UDP_read_PROC() { string rcvMsg; // UDP read while (UDPopen_FLG == 'O') { try { System.Text.Encoding enc = System.Text.Encoding.UTF8; Console.WriteLine("UDP_read started"); System.Net.IPEndPoint remoteEP = null; byte[] rcvBytes = UDP.Receive(ref remoteEP); rcvMsg = enc.GetString(rcvBytes); //textBoxUDPrdata.Text = rcvMsg; //Console.WriteLine("RCV Data:{0}", rcvMsg); //Console.WriteLine("RCV adrs:{0}/Port-NO:{1}", // remoteEP.Address, remoteEP.Port); Invoke(new Delegate_RcvData(UDPproc), new Object[] { rcvMsg, rcvMsg.Length }); } catch (Exception ex) { //MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); UDPopen_FLG = 'C'; // close } } Console.WriteLine("end of UDP_read"); } // UDP RECIVE DATA PROC private void UDPproc(string Rdata, Int32 Rleng) { //Console.WriteLine("UDP Data:{0}", Rdata); textBoxUDPrdata.Text = Rdata; // char cmd0 = Convert.ToChar(Rdata.Substring(0, 1)); char cmd1 = Convert.ToChar(Rdata.Substring(1, 1)); // Command PROCESS if (cmd0 == 'I') // init Command ? { // *********************** C command ************************** if (cmd1 == 'C') // Connect info data ? { UDPset(Rdata); } } if (cmd0 == 'C') // Command ? { // *********************** D command ************************** if (cmd1 == 'D') // RX data ? { UDPset(Rdata); } } } // UDP DATA SET PROC private void UDPset(string Rdata) { BAND_Freq = Convert.ToInt64(Rdata.Substring(12, 10)); MAIN_Freq = Convert.ToInt64(Rdata.Substring(22, 10)); //textBoxFreq.Text = Convert.ToString(MAIN_Freq); textBoxFreq.Text = String.Format("{0:#,0}", MAIN_Freq); //textBoxMFREQ.Text = String.Format("{0:#,0}", MAIN_Freq); VFO1_Freq = Convert.ToInt64(Rdata.Substring(32, 10)); textBoxDDS1F.Text = String.Format("{0:#,0}", VFO1_Freq); VFO2_Freq = Convert.ToInt64(Rdata.Substring(42, 10)); textBoxDDS2F.Text = String.Format("{0:#,0}", VFO2_Freq); VFO3_Freq = Convert.ToInt64(Rdata.Substring(52, 10)); textBoxDDS3F.Text = String.Format("{0:#,0}", VFO3_Freq); textBoxBfreq.Text = textBoxDDS3F.Text; Int64 VFO2wk = VFO2_Freq + VFO3_Freq; textBoxSCfreq.Text = String.Format("{0:#,0}", VFO2wk); if (STAT_mode == 'C') { Int64 MFwork = VFO3_Freq - 455000; MFwork = MAIN_Freq + MFwork; textBoxMFREQ.Text = String.Format("{0:#,0}", MFwork); } else { textBoxMFREQ.Text = String.Format("{0:#,0}", MAIN_Freq); } VFO4_Freq = Convert.ToInt64(Rdata.Substring(62, 10)); textBoxDDS4F.Text = String.Format("{0:#,0}", VFO4_Freq); Decimal VF04wk = (VFO4_Freq - 1732500); textBoxIFS.Text = (VF04wk/1000).ToString("F3"); Fstep = Convert.ToInt64(Rdata.Substring(82, 10)); if (Fstep == 0) { Fstep = 1; } textBoxStepF.Text = String.Format("{0:#}", Fstep); STAT_Fmod = Convert.ToChar(Rdata.Substring(96, 1)); textBoxFmode.Text = Rdata.Substring(96, 1); STAT_mode = Convert.ToChar(Rdata.Substring(94, 1)); if (STAT_mode == 'L') { textBoxMODE.Text = "LSB"; } if (STAT_mode == 'U') { textBoxMODE.Text = "USB"; } if (STAT_mode == 'C') { textBoxMODE.Text = "CW"; } if (STAT_mode == 'R') { textBoxMODE.Text = "RTY"; } if (STAT_mode == 'A') { textBoxMODE.Text = "AM"; } STAT_filnw = Convert.ToChar(Rdata.Substring(93, 1)); if (STAT_filnw == 'W') { textBoxFIL1.Text = "100KHz"; } if (STAT_filnw == 'N') { textBoxFIL1.Text = "5KHz"; } if (STAT_filnw == 'W') { Int64 BSwk1 = ((VFO2wk - 10600000) + 500) / 2500; Int32 BSwk1i = (Int32)BSwk1; if (BSwk1i < 0) { BSwk1i = 0; } if (BSwk1i > 80) { BSwk1i = 80; } textBoxBscp.Text = new string(' ', BSwk1i) + "|"; } if (STAT_filnw == 'N') { Int64 BSwk1 = ((VFO2wk - 10695000) + 50) / 125; Int32 BSwk1i = (Int32)BSwk1; if (BSwk1i < 0) { BSwk1i = 0; } if (BSwk1i > 80) { BSwk1i = 80; } textBoxBscp.Text = new string(' ', BSwk1i) + "|"; } STAT_2ndfl = Convert.ToChar(Rdata.Substring(95, 1)); if (STAT_2ndfl == 'W') { textBoxFIL2.Text = "16KHz"; } if (STAT_2ndfl == 'M') { textBoxFIL2.Text = "2.7KHz"; } if (STAT_2ndfl == 'N') { textBoxFIL2.Text = "180Hz"; } STAT_whpos = Convert.ToChar(Rdata.Substring(92, 1)); if (STAT_whpos == 'L') { if (STAT_filnw == 'W') { buttonLR.Text = "Left side"; textBoxBCL.Text = "600"; textBoxBCR.Text = "700"; labelBSr1.Text = "800"; labelBSc1.Text = "700"; labelBSl1.Text = "600"; labelBSr0.Text = "-100"; labelBSc0.Text = " 0"; labelBSl0.Text = "+100"; } if (STAT_filnw == 'N') { buttonLR.Text = "Left side"; textBoxBCL.Text = "695"; textBoxBCR.Text = "700"; labelBSr1.Text = "705"; labelBSc1.Text = "700"; labelBSl1.Text = "695"; labelBSr0.Text = " -5"; labelBSc0.Text = " 0"; labelBSl0.Text = " +5"; } } if (STAT_whpos == 'R') { if (STAT_filnw == 'W') { buttonLR.Text = "Right side"; textBoxBCL.Text = "700"; textBoxBCR.Text = "800"; labelBSr1.Text = "800"; labelBSc1.Text = "700"; labelBSl1.Text = "600"; labelBSr0.Text = " 0"; labelBSc0.Text = "+100"; labelBSl0.Text = "+200"; } if (STAT_filnw == 'N') { buttonLR.Text = "Right side"; textBoxBCL.Text = "700"; textBoxBCR.Text = "705"; labelBSr1.Text = "705"; labelBSc1.Text = "700"; labelBSl1.Text = "695"; labelBSr0.Text = " 0"; labelBSc0.Text = " +5"; labelBSl0.Text = " +10"; } } STAT_IFSFT = Convert.ToChar(Rdata.Substring(99, 1)); if (STAT_IFSFT == 'S') { buttonSFT.Text = "IF-Son"; } if (STAT_IFSFT == '*') { buttonSFT.Text = "IF-Soff"; } STAT_sdron = Convert.ToChar(Rdata.Substring(100, 1)); if (STAT_sdron == 'n') { buttonBSC.Text = "BSC off"; } if (STAT_sdron == 'O') { buttonBSC.Text = "BSC on"; } //STAT_bfoif = Convert.ToChar(Rdata.Substring(101, 1)); // if (STAT_bfoif == '3') { buttonBIF.Text = "BFO";} // if (STAT_bfoif == '4') { buttonBIF.Text = "IFS"; } STAT_INPUT = Convert.ToChar(Rdata.Substring(98, 1)); button3.Text = "Input " + STAT_INPUT; } // UDP WRITE DATA PROC private void UDPsend(string Sdata) { if (UDPopen_FLG == 'O') // UDP opened ? { System.Text.Encoding enc = System.Text.Encoding.UTF8; byte[] sendBytes = enc.GetBytes(Sdata); UDP.Send(sendBytes, sendBytes.Length); } } // UDP connect PROC private void button_UDPConn_Click(object sender, EventArgs e) { if (UDPopen_FLG == ' ') // UDP open ? { // use UTF8 code System.Text.Encoding enc = System.Text.Encoding.UTF8; // remote IP & Port-no remoteHost = textBox_UDPIPadr.Text; UDP.Connect(remoteHost, remotePort); // Make task for UDP_read_PROC // Make object System.Threading.Thread UDP_task = new System.Threading.Thread( new System.Threading.ThreadStart(UDP_read_PROC)); // run UDP_task UDP_task.Start(); button_UDPConn.Text = "stop"; UDPopen_FLG = 'O'; // Open string INITDAT = "ICSUPRXCL1 "; // I+C+CLname(8) UDPsend(INITDAT); } else { // clode UDP string LOGOFFDAT = "IOSUPRXCL1 "; UDPsend(LOGOFFDAT); System.Threading.Thread.Sleep(2000); // wait 2Sec UDP.Close(); button_UDPConn.Text = "end "; UDPopen_FLG = 'C'; // Close Application.Exit(); } } private void buttonUDPsend_Click(object sender, EventArgs e) { UDPsend(textBoxUDPsdata.Text); } private void buttonMODC_Click(object sender, EventArgs e) { string SDATA = "BCC" + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonMODL_Click(object sender, EventArgs e) { string SDATA = "BCL" + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonMODR_Click(object sender, EventArgs e) { string SDATA = "BCR" + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonMODA_Click(object sender, EventArgs e) { string SDATA = "BCA" + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void button2_Click(object sender, EventArgs e) { } private void buttonMODU_Click(object sender, EventArgs e) { string SDATA = "BCU" + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonFIL1_Click(object sender, EventArgs e) { string SDATA = "BG " + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonFIL2_Click(object sender, EventArgs e) { string SDATA = "B@ " + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonSFT_Click(object sender, EventArgs e) { string SDATA = "BE " + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonLR_Click(object sender, EventArgs e) { string SDATA = "BD " + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonBSC_Click(object sender, EventArgs e) { string SDATA = "B5 " + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonB1p8_Click(object sender, EventArgs e) { WORK_Fdata = "0001820000"; textBoxBAND.Text = "1.8"; BAND_sub(); } private void buttonB1p9_Click(object sender, EventArgs e) { WORK_Fdata = "0001910000"; textBoxBAND.Text = "1.9"; BAND_sub(); } private void buttonB3p5_Click(object sender, EventArgs e) { WORK_Fdata = "0003500000"; textBoxBAND.Text = "3.5"; BAND_sub(); } private void buttonB3p8_Click(object sender, EventArgs e) { WORK_Fdata = "0003750000"; textBoxBAND.Text = "3.8"; BAND_sub(); } private void buttonB7_Click(object sender, EventArgs e) { WORK_Fdata = "0007000000"; textBoxBAND.Text = "7"; BAND_sub(); } private void buttonB10_Click(object sender, EventArgs e) { WORK_Fdata = "0010100000"; textBoxBAND.Text = "10"; BAND_sub(); } private void buttonB14_Click(object sender, EventArgs e) { WORK_Fdata = "0014000000"; textBoxBAND.Text = "14"; BAND_sub(); } private void buttonB18_Click(object sender, EventArgs e) { WORK_Fdata = "0018100000"; textBoxBAND.Text = "18"; BAND_sub(); } private void buttonB21_Click(object sender, EventArgs e) { WORK_Fdata = "0021000000"; textBoxBAND.Text = "21"; BAND_sub(); } private void buttonB24_Click(object sender, EventArgs e) { WORK_Fdata = "0024910000"; textBoxBAND.Text = "24"; BAND_sub(); } private void buttonB28_Click(object sender, EventArgs e) { WORK_Fdata = "0028000000"; textBoxBAND.Text = "28"; BAND_sub(); } private void buttonBgen_Click(object sender, EventArgs e) { WORK_Fdata = "0010000000"; textBoxBAND.Text = "10"; BAND_sub(); } private void BAND_sub() { string SDATA = "BV " + WORK_Fdata + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonSTP_Click(object sender, EventArgs e) { WORK_stpc++; if (WORK_stpc > 2) { WORK_stpc = 0; } if (WORK_stpc == 0) { WORK_step = 1; } if (WORK_stpc == 1) { WORK_step = 10; } if (WORK_stpc == 2) { WORK_step = 100; } textBoxSTP.Text = String.Format("{0:#,0}", WORK_step); } private void textBoxSTP_TextChanged(object sender, EventArgs e) { } private void buttonFRUP_Click(object sender, EventArgs e) { MAIN_Freq = MAIN_Freq + WORK_step; WORK_Fdata = Convert.ToString(MAIN_Freq); WORK_Fdata = WORK_Fdata.PadLeft(10, '0'); string SDATA = "BV " + WORK_Fdata + "0000000000" + 0x00; Console.WriteLine(SDATA); UDPsend(SDATA); } private void buttonFRDN_Click(object sender, EventArgs e) { MAIN_Freq = MAIN_Freq - WORK_step; WORK_Fdata = Convert.ToString(MAIN_Freq); WORK_Fdata = WORK_Fdata.PadLeft(10, '0'); string SDATA = "BV " + WORK_Fdata + "0000000000" + 0x00; Console.WriteLine(SDATA); UDPsend(SDATA); } private void buttonBIF_Click(object sender, EventArgs e) { if (STAT_vfo34 == '3') { STAT_vfo34 = '4'; buttonBIF.Text = "IFS"; } else { STAT_vfo34 = '3'; buttonBIF.Text = "BFO"; } } private void button3_Click(object sender, EventArgs e) { string SDATA = "BF " + "0000000000" + "0000000000" + 0x00; UDPsend(SDATA); } private void buttonBfreqUP_Click(object sender, EventArgs e) { if (STAT_vfo34 == '3') // BFO ? { VFO3_Freq = VFO3_Freq + 10; WORK_Fdata = Convert.ToString(VFO3_Freq); FSET_sub(); } if (STAT_vfo34 == '4') // IF-Shift ? { VFO4_Freq = VFO4_Freq + 10; WORK_Fdata = Convert.ToString(VFO4_Freq); FSET_sub(); } } private void buttonBfreqDN_Click(object sender, EventArgs e) { if (STAT_vfo34 == '3') // BFO ? { VFO3_Freq = VFO3_Freq - 10; WORK_Fdata = Convert.ToString(VFO3_Freq); FSET_sub(); } if (STAT_vfo34 == '4') // IF-Shift ? { VFO4_Freq = VFO4_Freq - 10; WORK_Fdata = Convert.ToString(VFO4_Freq); FSET_sub(); } } private void FSET_sub() { WORK_Fdata = WORK_Fdata.PadLeft(10, '0'); string SDATA = "CF" + STAT_vfo34 + WORK_Fdata + "0000000000" + 0x00; UDPsend(SDATA); } private void label44_Click(object sender, EventArgs e) { } private void label45_Click(object sender, EventArgs e) { } private void label43_Click(object sender, EventArgs e) { } } // Form1 END } // name space end