Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 28th May 2008, 01:48 AM   (permalink)
Default Help with UDP send

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.
MrNobody is offline   Reply With Quote
Old 28th May 2008, 05:19 AM   (permalink)
Default

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.
Pommie is offline   Reply With Quote
Old 28th May 2008, 07:07 AM   (permalink)
Default

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");..?
MrNobody is offline   Reply With Quote
Old 28th May 2008, 07:28 AM   (permalink)
Default

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");
It is rather confusing having different pointer types that are not interchangeable.

Mike.
Pommie is offline   Reply With Quote
Old 28th May 2008, 03:40 PM   (permalink)
Default

Thanks alot..
MrNobody is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
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



All times are GMT. The time now is 08:55 AM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.