Ok, my next issue. Having completed the code to generate a byte array which represents a Pelco command, I now want to use C# to UDP that byte array to an UNO I have up stairs. So, no probs with the c# code :
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IPAddress serverAddr = IPAddress.Parse("192.168.1.111");
IPEndPoint endPoint = new IPEndPoint(serverAddr, 4567);
byte check = (0x02 + 0x00 + 0x00 + 0x00 + 0x00) % 256;
byte[] send_buffer = {0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, check};
sock.SendTo(send_buffer, endPoint);
but I'm having a heck of a time getting it out the other end intact.
My UDP server code ON THE uno looks like this
#include <SPI.h> // needed for Arduino versions later than 0018
#include <Ethernet.h>
#include <EthernetUdp.h> // UDP library from: bjoern@cs.stanford.edu 12/30/2008
...
char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; //buffer to hold incoming packet,
int packetSize = Udp.parsePacket();
if(packetSize)
{
digitalWrite(MAX485, HIGH);
delay(50);
while(Udp.available() != 0)
{
Serial.print((int)Udp.read());
Serial.print(",");
//Serial.write((byte)Udp.read()); THIS WILL PUT THE BYTE ONTO THE PELCO SERIAL WIRES, NOT USED IN THIS TEST
}
Serial.println("");
delay(50);
digitalWrite(MAX485, LOW);
}
Ok, so the general idea is that I'm sat in the office and have a live feed from the cam on my PC screen. On the same PC I have a mega with attatched joystick issuing Peloc commands to my c# app via usb. The c# app takes the commands, sends them to the uno running the UDP server whos only job is to grab the from the UDP packet and send the out the serial port to the camera.
To test the c#->udp server connection I have created the c# code above, problem is that when I instruct the uno to bung the packet data onto a serial monitor it is not consistent with what I've sent with my test c# code.
So, c# is udping 0xFF, 0x02, 0x00, 0x00, 0x00, 0x00, check, which equates to 255,2,0,0,0,0,0,2, sometimes I see this in the uno serial monitor, sometimes not. the following is a screen grab from the serial monitor :
255,2,255,0,255,0,254,
255,254,0,255,0,255,2,
255,2,0,0,0,0,2,
255,2,0,0,0,0,2,
255,2,0,0,0,0,2,
255,254,0,0,0,0,2,-1,-1,-1,-1,-1,-1,-1,-1 ...........on and on and on and, you get the idea ![]()
Please could you suggest what ideotic mistake I am making ![]()