Click here to Skip to main content
14,773,285 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Blaney;
using System.IO;
using System.IO.Ports;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        Radar _radar;
        public Form1()
        {
            InitializeComponent();
        }
        RadarItem item1 = new SquareRadarItem(1, 8, 0, 60);
        RadarItem item2 = new CircleRadarItem(2, 8, 0, 30);
        RadarItem item3 = new TriangleRadarItem(3, 10, 0, 40);
      
        private void Form1_Load(object sender, EventArgs e)
        {
            _radar = new Radar(pictureBox1.Width);
            pictureBox1.Image = _radar.Image;
            _radar.ImageUpdate += new ImageUpdateHandler(_radar_ImageUpdate);
            _radar.DrawScanInterval = 60;
            _radar.DrawScanLine = true;
        }
    
        void _radar_ImageUpdate(object sender, ImageUpdateEventArgs e)
        {
            // this event is important to catch!
            pictureBox1.Image = e.Image;
        }

        int A = 1;
        private void timer1_Tick(object sender, EventArgs e)
        {
             item3.Azimuth++;      // 0 to 360 
            _radar.AddItem(item3);           
            label2.Text = item3.Azimuth.ToString();
           
            item3.Elevation += A;
            if (item3.Elevation == 75 || item3.Elevation == 40)
            {
                A = -A;
            }
            label4.Text = item3.Elevation.ToString();
     
        }
     
        private void btnSquare_Click(object sender, EventArgs e)
        {
            _radar.AddItem(item1);
        }

        private void btnCircle_Click(object sender, EventArgs e)
        {
            _radar.AddItem(item2);
        }

        private void btnTriangle_Click(object sender, EventArgs e)
        {
            _radar.AddItem(item3);
        }
        private void btnEleplus_Click(object sender, EventArgs e)
        {
            item3.Elevation++;
            label5.Text = item3.Elevation.ToString();
        }
        private void btnEle__Click(object sender, EventArgs e)
        {
            item3.Elevation--;
            label6.Text = item3.Elevation.ToString();
        }
        int r = 300;
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            //var x_dist = e.Location.X - r;
            //var y_dist = e.Location.Y - r;
            //var distance = Math.Sqrt(x_dist * x_dist + y_dist * y_dist); // pythagoras : sqrt(a² + b²) = c
            //distance = distance * 10;
            //textBox1.Text = distance.ToString();
        }

        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            //var x_dist = e.Location.X - r;
            //var y_dist = e.Location.Y - r;
            //var distance = Math.Sqrt(x_dist * x_dist + y_dist * y_dist); // pythagoras : sqrt(a² + b²) = c
            //distance = distance * 10;
            //item3.Elevation = Convert.ToInt16(distance) ;
            //textBox1.Text = distance.ToString();
        }   
    }
}


What I have tried:

This is all code. If this program Triangle item3 is run in circle with azimuth 0 to 360 and elevation 40 to 75 again and again. I want to send this azimuth and elevation data to other computer with serial port hex code.? how to do that?
Posted
Updated 14-Oct-20 22:46pm
v5

First off, that's not good code: there is no limit on Azimuth in there, despite the comment that it should range from 0 to 360.
Each time the timer ticks, you add the same item to the _radar collection - so your change of the Azimuth property immediately above that affects all of the items, not just one. To add different values, you need to create a new instance of whatever item3 is each time you get a new Tick event.
Your if condition just looks weird - unless Elevation and A start with very specific values it's unlikely to work. Pretty much, Elevation would have to start between 40 and 75, and A would have to be 1 or 5 ...

And there is noting there at all about serial data: start here and see what you can get to: SerialPort Class (System.IO.Ports) | Microsoft Docs[^]
   
Quote:
want to send serial port with hex code.
Probably you mean 'want to send binary data (that is an array of bytes) to the serial port'. Have a look at the documentation: SerialPort.Write Method (System.IO.Ports) | Microsoft Docs[^].
   

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900