MX Foundation 4
ar429_UDPCommTx.cs
/*******************************************************************************
//
// File:
// ar429_UDPCommTX.cs
//
// Copyright (c) MAX Technologies Inc. 1988-2019, All Rights Reserved.
// CONFIDENTIAL AND PROPRIETARY INFORMATION WHICH IS THE
// PROPERTY OF MAX TECHNOLOGIES INC.
//
// The embedded program "ar429_UDPCommRxEmbedded.c" is required by this program
// and compiled executable (ar429_UDPCommRxEmbedded.mxf) must have been transferred
// (by tftp or any mean) on the FM in the maxfiles folder to be used.
// The ar429_UDPCommRxEmbedded.mxf must be started first (usually ./ar429_UDPCommRxEmbedded.mxf).
// It sends a UDP datagram to the FM that is going to be used to start an aperiodic transmission,
// and waits for the answer (another UDP datagram sent by the FM).
// The UDP datagram sent by the FM must be the same than the one sent to the FM.
//
// Hardware Requirements:
// - MAXT FlexMulti with AR429 ports on it
//
*******************************************************************************/
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ar429_example
{
class ar429_UDPCommTX
{
static void Main(string[] args)
{
const int BUFFER_SIZE = 100;
string transmitStrg = "L 101 102 103 104 D 1111 2222 3333 4444";
byte[] txBuffer = Encoding.ASCII.GetBytes(transmitStrg);
string receivedStrg = "";
byte[] rxBuffer = new byte[BUFFER_SIZE];
IPAddress fmIpAddr = IPAddress.Parse("192.168.0.1");
IPEndPoint endPoint = new IPEndPoint(fmIpAddr, 8888);
//Creates the socket
using (Socket txPortSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
//Sends the datagram to the FM
try
{
Console.Write("Sending datagram...\n");
txPortSocket.SendTo(txBuffer, endPoint);
Console.Write("Datagram sent successfully.\n");
}
catch (Exception e)
{
Console.Write("Error sending datagram, {0}\n", e);
}
//Receives the datagram from the FM
try
{
Console.Write("Waiting for datagram...\n");
txPortSocket.Receive(rxBuffer);
receivedStrg = Encoding.ASCII.GetString(rxBuffer);
Console.Write("Datagram received from the FM : {0}", receivedStrg);
}
catch (Exception e)
{
Console.Write("Error waiting for datagram, {0}\n", e);
}
}
Console.Write("\n\nPress a key to terminate\n");
Console.ReadKey();
return;
}
}
}
Updated 10/23/2023