KMTronic DINo UDP to RS485 example
-----------------------------------------------------------------------------------
Test software
KMTronic DINo 4 Relay UDP Test Software.zip
Monitoring software
(using USB<>RS485 adapter)
Source code
#include "EtherShield.h"
uint8_t mymac[6] = {0xCF,0x70,0x7C,0xE4,0x8A,0xB8};
uint8_t myip[4] = {192,168,1,25};
uint16_t MYWWWPORT = 80;
#define BUFFER_SIZE 750
static uint8_t buf[BUFFER_SIZE+1];
char reply[]="Realized";
const int RS485_control = 3;
//Set this pin to high when you want to send data from RS485//
static uint8_t udp_length;
static uint8_t udp_buffer[50];
EtherShield es=EtherShield();
uint16_t plen, dat_p;
///----------------------------------------------------------
void setup(){
pinMode(RS485_control, OUTPUT);
digitalWrite(RS485_control, HIGH); // Set pin to send data
Serial.begin(9600);
es.ES_enc28j60Init(mymac);
es.ES_init_ip_arp_udp_tcp(mymac,myip, MYWWWPORT);
} // end setup
///----------------------------------------------------------
void loop(){
// read packet, handle ping and wait for a tcp packet:
dat_p=es.ES_packetloop_icmp_tcp(buf,es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf));
if (buf[IP_PROTO_P]==IP_PROTO_UDP_V){
udp_length=buf[39]-8; // calculate UDP data lenght
for (int i = 0; i < udp_length; i++)
{
Serial.write(buf[42+i]);
}
es.ES_make_udp_reply_from_request(buf,reply,8,12345);
buf[IP_PROTO_P]=0;
}
} // end loop