1
STX8081 / Re:Diferencia entre protocolos para transferencia de datos
« : mayo 05, 2015, 10:57:56 am »
Muchas gracias
Esta sección te permite ver todos los mensajes hechos por este usuario, recuerda que solo puedes ver los mensajes en áreas en donde tu tienes acceso.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using stx8081;
namespace Recetas1
{
public partial class Form1 : Form
{
Stx8081 PioBoard;
public Form1()
{
InitializeComponent();
// Inicializar objeto PioBoard.
PioBoard = new Stx8081("192.168.1.81", 0);
}
private void componentesBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.componentesBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.database1DataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: esta línea de código carga datos en la tabla 'database1DataSet.Componentes' Puede moverla o quitarla según sea necesario.
this.componentesTableAdapter.Fill(this.database1DataSet.Componentes);
}
private void button1_Click(object sender, EventArgs e)
{
// Variable para retorno de estado del PLC.
UdpRxCmdStat OnUdpRxStat = UdpRxCmdStat.OK;
// Crear array de bytes a enviar (24 bytes).
byte[] DataBytes = new byte[24];
// Onbtener valor en celda en: Fila 0, Columna 0.
Int32 Val1 = Convert.ToInt32(componentesDataGridView.Rows[0].Cells[0].Value);
// Copiar Val1 al array de bytes.
DataBytes[0] = (byte)(Val1 >> 0);
DataBytes[1] = (byte)(Val1 >> 8);
DataBytes[2] = (byte)(Val1 >> 16);
DataBytes[3] = (byte)(Val1 >> 24);
// Onbtener valor en celda en: Fila 0, Columna 1.
Int32 Val2 = Convert.ToInt32(componentesDataGridView.Rows[0].Cells[1].Value);
// Copiar Val2 al array de bytes.
DataBytes[4] = (byte)(Val2 >> 0);
DataBytes[5] = (byte)(Val2 >> 8);
DataBytes[6] = (byte)(Val2 >> 16);
DataBytes[7] = (byte)(Val2 >> 24);
// Onbtener valor en celda en: Fila 0, Columna 2.
Int32 Val3 = Convert.ToInt32(componentesDataGridView.Rows[0].Cells[2].Value);
// Copiar Val3 al array de bytes.
DataBytes[8] = (byte)(Val3 >> 0);
DataBytes[9] = (byte)(Val3 >> 8);
DataBytes[10] = (byte)(Val3 >> 16);
DataBytes[11] = (byte)(Val3 >> 24);
// Onbtener valor en celda en: Fila 0, Columna 3.
Int32 Val4 = Convert.ToInt32(componentesDataGridView.Rows[0].Cells[3].Value);
// Copiar Val4 al array de bytes.
DataBytes[12] = (byte)(Val4 >> 0);
DataBytes[13] = (byte)(Val4 >> 8);
DataBytes[14] = (byte)(Val4 >> 16);
DataBytes[15] = (byte)(Val4 >> 24);
// Onbtener valor en celda en: Fila 0, Columna 4.
Int32 Val5 = Convert.ToInt32(componentesDataGridView.Rows[0].Cells[4].Value);
// Copiar Val5 al array de bytes.
DataBytes[16] = (byte)(Val5 >> 0);
DataBytes[17] = (byte)(Val5 >> 8);
DataBytes[18] = (byte)(Val5 >> 16);
DataBytes[19] = (byte)(Val5 >> 24);
// Onbtener valor en celda en: Fila 0, Columna 5.
Int32 Val6 = Convert.ToInt32(componentesDataGridView.Rows[0].Cells[5].Value);
// Copiar Val6 al array de bytes.
DataBytes[20] = (byte)(Val6 >> 0);
DataBytes[21] = (byte)(Val6 >> 8);
DataBytes[22] = (byte)(Val6 >> 16);
DataBytes[23] = (byte)(Val6 >> 24);
// Onbtener valor en celda en: Fila 0, Columna 6.
Int32 Val7 = Convert.ToInt32(componentesDataGridView.Rows[0].Cells[6].Value);
// Copiar Val3 al array de bytes.
DataBytes[24] = (byte)(Val7 >> 0);
DataBytes[25] = (byte)(Val7 >> 8);
DataBytes[26] = (byte)(Val7 >> 16);
DataBytes[27] = (byte)(Val7 >> 24);
MessageBox.Show("Se envía una receta");
// Enviar los 24 bytes UDP al script con el metodo "Send".
PioBoard.Cmd.Udp.Send(DataBytes, 24, out OnUdpRxStat);
}
}
}