![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Hi,
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. |
|
|
|
|
|
|
(permalink) |
|
Have you tried UDP_Send((rom char*)"Hello");
I assume there is also a function UDPPutRAMString which could send actual variable strings. You would of course have to copy your ROM strings to RAM. Mike. |
|
|
|
|
|
|
(permalink) |
|
Hi Mike,
Tried UDP_Send((rom char*)"Hello"); but in wireshark, it shows "10 420.030195 192.168.2.4 192.168.2.2 UDP Source port: vcom-tunnel Destination port: teradataordbms[Malformed Packet]" Yes, it does have function UDPPutRAMString.. Umm, how would I copy the ROM strings to RAM. Is it UDP_Send((ram char*)"Hello");..? |
|
|
|
|
|
|
(permalink) |
|
I just do,
Code:
void CopyString(ram char* RamString,rom char * RomString){
do{
*RamString++=*RomString;
}while(*RomString++!=0);
}
// and then do,
CopyString(RamStringVar,(rom char*) "Hello World");
Mike. |
|
|
|
|
|
|
(permalink) |
|
Thanks alot..
|
|
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Latest |
| plz send | niraj_dave | General Electronics Chat | 3 | 6th April 2008 03:58 PM |
| PIC send SMS | potetojb | Micro Controllers | 1 | 6th March 2006 04:36 AM |
| send data via uhf | elctrochania | Electronic Projects Design/Ideas/Reviews | 14 | 16th November 2005 02:17 PM |
| Need RF to send 8-bit signal | Aidis | General Electronics Chat | 5 | 17th March 2005 06:33 AM |
| can u send me a simple... | Faisal__saf | General Electronics Chat | 2 | 7th June 2003 01:22 PM |