User manual

268Bibliotheken
© 2013 Conrad Electronic
void SendSyslogMsg(dword ip, byte level, char text[])
{
byte buf[100];
Str_Printf(buf, "<%d>%s", 16*8+level, text);
ETH_SendUDP(ip, 514, buf, Str_Len(buf));
}
void main(void)
{
while(1)
{
SendSyslogMsg(IP_ADDR(192,168,0,1), 3, "test message");
AbsDelay(1000);
}
}
2. Programm sendet auf UDP Port 50000 empfangene Daten wieder zurück an den Absender:
byte buf[ETH_BUF(500,0)], rbuf[200]; // 500 byte Empfangspuffer
void main(void)
{
word info[4], plen;
dword ip;
ETH_SetConnBuf(buf, 500, 0);
ETH_ListenUDP(50000); // Listen auf Port 50000
while(1)
{
ip= ETH_CheckReceiveBuf(info);
if(ip)
{
plen= info[3]; // Länge
if(plen > 200) plen= 200; // Begrenze auf 200 bytes
ETH_ReceiveData(rbuf, plen);
ETH_SendUDP(ip, 50000, rbuf, plen);
}
}
}
5.11.4 ETH_ConnectTCP
Ethernet Funktionen
Syntax
byte ETH_ConnectTCP(dword ip, word port);
Sub ETH_ConnectTCP(ip As ULong, port As Word) As Byte