Hi,
Below is a function in C18 to send data using UDP. It is able to send "BYE" successfully.
How can i convert the code into a function which is able to receive variable passed to it, forexample UDP_Send("Hello") will send "Hello" instead of sending "BYE".
I tried to convert the code into:
and call it using UDP_Send("Hello"); but it doesn't seem to work..
Please advice.
Below is a function in C18 to send data using UDP. It is able to send "BYE" successfully.
Code:
void UDP_Send()
{
#define LPORT_SEND 8001 //Local port to send from
#define RPORT_SEND 8002 //Remote port to send to
static ROM BYTE *StringData = "BYE";
UDP_SOCKET SocketTransmit;
NODE_INFO Remote;
BYTE *A;
Remote.IPAddr.v[0]=192;
Remote.IPAddr.v[1]=168;
Remote.IPAddr.v[2]=2;
Remote.IPAddr.v[3]=2;
if(!MACIsLinked())
return;
SocketTransmit = UDPOpen(LPORT_SEND, &Remote, RPORT_SEND);
if(SocketTransmit == INVALID_UDP_SOCKET)
return;
if(!UDPIsPutReady(SocketTransmit))
{
UDPClose(SocketTransmit);
return;
}
AAA = UDPPutROMString(StringData); // Send string
UDPFlush();
UDPClose(SocketTransmit);
}
How can i convert the code into a function which is able to receive variable passed to it, forexample UDP_Send("Hello") will send "Hello" instead of sending "BYE".
I tried to convert the code into:
Code:
void UDP_Send(ROM BYTE *StringData)
{
#define LPORT_SEND 8001 //Local port to send from
#define RPORT_SEND 8002 //Remote port to send to
UDP_SOCKET SocketTransmit;
NODE_INFO Remote;
BYTE *A;
Remote.IPAddr.v[0]=192;
Remote.IPAddr.v[1]=168;
Remote.IPAddr.v[2]=2;
Remote.IPAddr.v[3]=2;
if(!MACIsLinked())
return;
SocketTransmit = UDPOpen(LPORT_SEND, &Remote, RPORT_SEND);
if(SocketTransmit == INVALID_UDP_SOCKET)
return;
if(!UDPIsPutReady(SocketTransmit))
{
UDPClose(SocketTransmit);
return;
}
AAA = UDPPutROMString(StringData); // Send string
UDPFlush();
UDPClose(SocketTransmit);
}
and call it using UDP_Send("Hello"); but it doesn't seem to work..
Please advice.