Ejemplo n.º 1
0
    void Start()
    {
        style.normal.textColor = Color.red;
        rb = GetComponent <Rigidbody>();
        rb.centerOfMass = centerOfMass;

        uart = new Uart();
        //Time.fixedDeltaTime = 0.005f;
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads the byte.
        /// </summary>
        /// <returns>The byte value. Null if no bytes were read</returns>
        public byte?ReadByte()
        {
            var result = Uart.SerReadByte(Handle);

            if (result >= 0)
            {
                return((byte)result);
            }

            return(default);
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the baud rate.
        /// </summary>
        public void SetBaudRate(BaudRate BaudRate)
        {
            byte H, L;

            switch (BaudRate)
            {
            case BaudRate.Baud___9600:
                H = 0xae;
                L = 0xc8;
                break;

            case BaudRate.Baud__19200:
                H = 0x56;
                L = 0xe4;
                break;

            case BaudRate.Baud__38400:
                H = 0x2a;
                L = 0xf2;
                break;

            case BaudRate.Baud__57600:
                H = 0x1c;
                L = 0x4c;
                break;

            case BaudRate.Baud_115200:
                H = 0x0d;
                L = 0xa6;
                break;

            default:
                throw new ArgumentException("Invalid baud rate", "BaudRate");
            }

            this.EmptyBuffers();

            if (this.uart.OutputToConsole)
            {
                Console.Out.WriteLine("SetBaudRate(" + BaudRate.ToString() + ")");
            }

            this.uart.Transmit(0x56, 0x00, 0x24, 0x03, 0x01, H, L);
            this.uart.ReceiveAndVerify(0x76, 0x00, 0x24, 0x00, 0x00);

            Uart Uart2;

            Uart2                 = new Uart((int)BaudRate, Parity.None, 8, StopBits.None);
            Uart2.NewLine         = this.uart.NewLine;
            Uart2.ReadTimeout     = this.uart.ReadTimeout;
            Uart2.OutputToConsole = this.uart.OutputToConsole;

            this.uart.Dispose();
            this.uart = Uart2;
        }
Ejemplo n.º 4
0
 // Start is called before the first frame update
 void Start()
 {
     uart = new Uart();
     uart.Send("fff");         // pic18 enter fox game state
     transform.localScale = new Vector3(13.6f, 13.6f, 1);
     _rigidbody           = GetComponent <Rigidbody2D>();
     animator.SetInteger("status", 1);
     for (int i = 0; i < heart_count; i++)
     {
         image[i].enabled = true;
     }
     DieText.enabled = false;
 }
Ejemplo n.º 5
0
    // Start is called before the first frame update

    void Start()
    {
        uart = new Uart();
        transform.localScale = new Vector3(13.6f, 13.6f, 1);
        _rigidbody           = GetComponent <Rigidbody2D>();
        animator.SetInteger("status", 1);
        serial_speed = 0;
        for (int i = 0; i < heart_count; i++)
        {
            image[i].enabled = true;
        }
        DieText.enabled = false;
    }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!OpenUart())
            {
                return;
            }
            SetIDForm f = new SetIDForm(Uart);

            uartRxProc = new UartRxProc(f.UartRxProc);
            //this.Uart.DataReceived += new System.IO.Ports.SerialDataReceivedEventHandler(f.Uart_DataReceived);
            f.ShowDialog();
            //this.Uart.DataReceived -= new System.IO.Ports.SerialDataReceivedEventHandler(f.Uart_DataReceived);
            Uart.Close();
            uartRxProc = null;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Class handling the LinkSprite JPEG Color Camera, connected to the UART on the Raspberry Pi GPIO Pin Header.
 /// For more inforation, see: <see cref="http://www.linksprite.com/upload/file/1291522825.pdf"/>
 ///
 /// NOTE: To be able to use the UART on the Raspberry GPIO Pin Header, you need to disable the ttyAMA0 device in Linux. For more information
 /// on how to do this, see: <see cref="http://elinux.org/RPi_Serial_Connection#Connection_to_a_microcontroller_or_other_peripheral"/>.
 /// </summary>
 /// <param name="BaudRate">Baud Rate to use</param>
 public LinkSpriteJpegColorCamera(BaudRate BaudRate)
 {
     this.uart                 = new Uart((int)BaudRate, Parity.None, 8, StopBits.None);
     this.uart.NewLine         = "\r\n";
     this.uart.OutputToConsole = false;                  // Set to true, to debug communication.
 }
Ejemplo n.º 8
0
        private void CargarConfiguracion()
        {
            Cargando loading = new Cargando();

            if (!System.Security.Principal.WindowsIdentity.GetCurrent().Name.Contains("omartinez"))
            {
                loading.Topmost     = true;
                loading.WindowStyle = WindowStyle.None;
            }
            loading.Show();

            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += (s, e) =>
            {
                try
                {
                    this.config   = BDConfiguracion.Leer();
                    Store.Bancada = BDSQL.Select.ObtenerBancadaPorId(this.config.IdBancada);
                    if (Store.Bancada != null && Store.Bancada.EsMaster && Store.Bancada.IdHermano.HasValue)
                    {
                        Store.BancadaEsclavo = BDSQL.Select.ObtenerBancadaPorId(Store.Bancada.IdHermano.Value);
                    }
                    else if (Store.Bancada != null && !Store.Bancada.EsMaster && Store.Bancada.IdHermano.HasValue)
                    {
                        Store.BancadaMaster = BDSQL.Select.ObtenerBancadaPorId(Store.Bancada.IdHermano.Value);
                    }

                    DateTime ahora = DateTime.Now;
                    Turno    turno = Horario.CalcularTurnoAFecha(ahora);
                    DateTime fechaInicio;
                    DateTime fechaFin;
                    Horario.CalcularHorarioTurno(turno, ahora, out fechaInicio, out fechaFin);

                    var paquetes = new List <MaquinasRegistrosDatos>();
                    foreach (var maquina in Store.Bancada.Maquinas)
                    {
                        paquetes.AddRange(Select.HistoricoPaquetesOperario(maquina.IpAutomata, maquina.Posicion, fechaInicio, fechaFin));
                    }

                    foreach (var paquete in paquetes.Where(x => x.PiezaIntroducida))
                    {
                        var maq = Store.Bancada.Maquinas.FirstOrDefault(x => x.IpAutomata == paquete.IpAutomata && x.Posicion == paquete.PosicionMaquina);
                        if (maq != null)
                        {
                            maq.Pulsos.Add(new PulsoMaquina
                            {
                                IdTarea        = paquete.IdTarea,
                                CodigoEtiqueta = paquete.CodigoEtiqueta,
                                Control        = BuscarControl(paquete.IdOperacion, maq),
                                Fecha          = paquete.FechaCreacion,
                                Pares          = paquete.Pares,
                                IdOperario     = paquete.IdOperario,
                                CodigoOrden    = paquete.CodigoOrden,
                                Talla          = paquete.Talla,
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Write(ex);
                }
            };

            bw.RunWorkerCompleted += (s, e) =>
            {
                try
                {
                    if (Store.Bancada != null && Store.Bancada.Maquinas.Any())
                    {
                        if (Store.Bancada.EsMaster)
                        {
                            var maquinasUart = Store.Bancada.Maquinas.ToList();
                            if (Store.BancadaEsclavo != null)
                            {
                                maquinasUart.AddRange(Store.BancadaEsclavo.Maquinas.ToList());
                            }
                            uart = new Uart(maquinasUart);
                            uart.OnPulsoGenerado += this.Uart_OnPulsoGenerado;
                        }

                        this.IniciarMQTT();
                    }
                    else
                    {
                        MessageBox.Show("Bancada no configurada", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    loading.Close();
                }
                catch (Exception ex)
                {
                    Log.Write(ex);
                    loading.Close();
                }
                Notifica();
            };

            bw.RunWorkerAsync();
        }
Ejemplo n.º 9
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     Uart.Close();
 }
Ejemplo n.º 10
0
 private void btNetStart_Click(object sender, EventArgs e)
 {
     if (btNetStart.Text == "启动网络")
     {
         Uart.PortName = cbCom.Text;
         RxPacket      = new CP1616Packet();
         if (WFGlobal.OpenSerialPort(ref Uart) == false)
         {
             return;
         }
         Properties.Settings.Default.PortName = cbCom.Text;
         Properties.Settings.Default.Save();
         sensorSingIn.clearSignIn();
         listView1.Items.Clear();
         chart1.Series[0].Points.Clear();
         chart2.Series[0].Points.Clear();
         chart3.Series[0].Points.Clear();
         chart4.Series[0].Points.Clear();
         chart3.Series[1].Points.Clear();
         chart4.Series[1].Points.Clear();
         chart3.Series[2].Points.Clear();
         chart4.Series[2].Points.Clear();
         chart3.Series[3].Points.Clear();
         chart4.Series[3].Points.Clear();
         bStopNet = false;
         for (int i = 0; i < 3; i++)
         {
             startResult = 0;
             waitCommand = 1;
             CP1616Packet.CP1616ComSend(ref Uart, waitCommand, 0, (ushort)0);
             int x = 0;
             while (true)
             {
                 Thread.Sleep(1);
                 if (startResult != 0)
                 {
                     break;
                 }
                 x++;
                 if (x > 1000)
                 {
                     startResult = 0xff;
                     break;
                 }
             }
             if (startResult == 0xff)//超时了
             {
             }
             else
             {
                 break;
             }
         }
         if (startResult == 0xff)
         {
             MessageBox.Show("网络控制器未做应答!!!");
             Uart.Close();
             btNetStart.Text = "启动网络";
             return;
         }
         else if (startResult == 2)
         {
             bStopNet        = false;
             btNetStart.Text = "停止网络";
             MessageBox.Show("网络已经启动,等待接入");
         }
         else if (startResult == 3)
         {
             bStopNet        = false;
             btNetStart.Text = "停止网络";
             MessageBox.Show("标定网络已经启动,将自动转为测量网络,等待接入");
         }
         else
         {
             WaitSometingForm.WaitSometing_Init();
             waitCommand = 0x10;//点名完成
             if (!WaitSometingForm.WaitSometing(10, 3000, "等待无线节点组网,预计时长25s"))
             {
                 waitCommand = 0;
                 Uart.Close();
                 MessageBox.Show("组网失败");
                 return;
             }
             if (listView1.Items.Count != 0)
             {
                 WaitSometingForm.WaitSometing_Init();
                 waitCommand = 0x20;//等待测量数据
                 if (!WaitSometingForm.WaitSometing(10, 500, "等待网络数据,预计时长3s"))
                 {
                     waitCommand = 0;
                     MessageBox.Show("组网失败");
                     Uart.Close();
                     bStopNet = false;
                     return;
                 }
                 bStopNet        = false;
                 btNetStart.Text = "停止网络";
                 MessageBox.Show("网络启动成功");
             }
             else
             {
                 waitCommand = 0;
                 MessageBox.Show("当前网络没有发现任何无线节点,网络自动停止");
                 Uart.Close();
                 btNetStart.Text = "启动网络";
                 return;
             }
         }
     }
     else
     {
         bStopNet = true;
         WaitSometingForm.WaitSometing_Init();
         waitCommand = 0x02;//等待网络停止
         if (!WaitSometingForm.WaitSometing(10, 500, "等待网络停止,预计时长5s"))
         {
             waitCommand = 0;
             MessageBox.Show("网络停止失败");
             return;
         }
         MessageBox.Show("网络已停止");
         Uart.Close();
         btNetStart.Text = "启动网络";
     }
 }
Ejemplo n.º 11
0
        void Uart_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            int  irx;
            byte rx;

            while (true)
            {
                try
                {
                    irx = Uart.ReadByte();
                }
                catch
                {
                    return;
                }
                if (!Uart.IsOpen)
                {
                    return;
                }
                if (irx == -1)
                {
                    return;
                }
                rx = (byte)irx;
                if (RxPacket.DataPacketed(rx))
                {
                    byte[] data = new byte[2];
                    data[0] = RxPacket.Header.Command;
                    if (waitCommand == RxPacket.Header.Command)
                    {
                        WaitSometingForm.bGenerateSometing = true;
                    }
                    if (bStopNet)
                    {
                        data[1] = 0x02;//要求关闭网络
                        CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data);
                    }
                    else if (RxPacket.Header.Command == 1)//标定网络启动确认
                    {
                        startResult = RxPacket.Data[0];
                    }
                    else if (RxPacket.Header.Command == 0x22)//标定网络,请求转换为测量网络
                    {
                        this.Invoke((EventHandler)(delegate
                        {
                            textBox1.AppendText(DateTime.Now.ToString("HH:mm:ss:ffff") + ":标定网络转换为测量网络\r\n");
                        }));
                        startResult = 3;
                        data[1]     = 0x03;
                        CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data);
                    }
                    else if (RxPacket.Header.Command == 0x10)
                    {
                        data[1] = 0x00;
                        CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data);
                        SignInProc();
                    }
                    else if (RxPacket.Header.Command == 0x20)
                    {
                        startResult = 2;
                        if (listView1.Items.Count == 0)
                        {
                            data[1] = 0x01;//请求传感器名单
                            CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data);
                        }
                        else
                        {
                            data[1] = 0x00;
                            CP1616Packet.CP1616ComSend(ref Uart, 3, 0, data);
                            ADCDataProc();
                        }
                        this.Invoke((EventHandler)(delegate
                        {
                            if (btNetStart.Text == "启动网络")
                            {
                                btNetStart.Text = "停止网络";
                            }
                        }));
                    }
                    RxPacket = new CP1616Packet();
                }
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UartPort"/> class.
 /// </summary>
 /// <param name="portName">Name of the port.</param>
 /// <param name="baudRate">The baud rate.</param>
 internal UartPort(string portName, UartRate baudRate)
 {
     Handle   = Uart.SerOpen(portName, baudRate);
     BaudRate = (int)baudRate;
     PortName = portName;
 }
		/// <summary>
		/// Class handling the LinkSprite JPEG Color Camera, connected to the UART on the Raspberry Pi GPIO Pin Header.
		/// For more inforation, see: <see cref="http://www.linksprite.com/upload/file/1291522825.pdf"/>
		/// 
		/// NOTE: To be able to use the UART on the Raspberry GPIO Pin Header, you need to disable the ttyAMA0 device in Linux. For more information
		/// on how to do this, see: <see cref="http://elinux.org/RPi_Serial_Connection#Connection_to_a_microcontroller_or_other_peripheral"/>.
		/// </summary>
		/// <param name="BaudRate">Baud Rate to use</param>
		public LinkSpriteJpegColorCamera (BaudRate BaudRate)
		{
			this.uart = new Uart ((int)BaudRate, Parity.None, 8, StopBits.None);
			this.uart.NewLine = "\r\n";
			this.uart.OutputToConsole = false;	// Set to true, to debug communication.
		}
		public void Dispose ()
		{
			if (this.uart != null)
			{
				this.uart.Dispose ();
				this.uart = null;
			}
		}
		/// <summary>
		/// Sets the baud rate.
		/// </summary>
		public void SetBaudRate (BaudRate BaudRate)
		{
			byte H, L;

			switch (BaudRate)
			{
				case BaudRate.Baud___9600:
					H = 0xae;
					L = 0xc8;
					break;

				case BaudRate.Baud__19200: 
					H = 0x56;
					L = 0xe4;
					break;

				case BaudRate.Baud__38400: 
					H = 0x2a;
					L = 0xf2;
					break;

				case BaudRate.Baud__57600: 
					H = 0x1c;
					L = 0x4c;
					break;

				case BaudRate.Baud_115200: 
					H = 0x0d;
					L = 0xa6;
					break;

				default:
					throw new ArgumentException ("Invalid baud rate", "BaudRate");
			}

			this.EmptyBuffers ();

			if (this.uart.OutputToConsole)
				Console.Out.WriteLine ("SetBaudRate(" + BaudRate.ToString () + ")");

			this.uart.Transmit (0x56, 0x00, 0x24, 0x03, 0x01, H, L);
			this.uart.ReceiveAndVerify (0x76, 0x00, 0x24, 0x00, 0x00);

			Uart Uart2;

			Uart2 = new Uart ((int)BaudRate, Parity.None, 8, StopBits.None);
			Uart2.NewLine = this.uart.NewLine;
			Uart2.ReadTimeout = this.uart.ReadTimeout;
			Uart2.OutputToConsole = this.uart.OutputToConsole;

			this.uart.Dispose ();
			this.uart = Uart2;
		}
Ejemplo n.º 16
0
 // Start is called before the first frame update
 void Start()
 {
     uart = new Uart();
     uart.Send("mmm");
     selectValue = 0;
 }