rfid capturing and ethernet sending to matlab thru udp problem

here is my arduino code that uses pin 6 to capture the rfid id, it works when i opoen the serial, but there is something wrong with the udp.write() or that char c is not a matrix i think, because when i use wireshark to capture my udp packets, everything is working fine, except that in the data section it is filled with zeros rather than the id.can anyone help me?

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SoftwareSerial.h>

byte mac[]={0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(192,168,1,177);
unsigned int localPort=8888;
SoftwareSerial rfid=SoftwareSerial(6,1);

char packetBuffer[UDP_TX_PACKET_MAX_SIZE];
char replyBuffer[]="l";
char c;
EthernetUDP udp;

void setup() {
  Serial.println("Serial Ready");
  Serial.println("RFID READY");

void loop() {
  while(rfid.available()>0) {
    int packetSize=udp.parsePacket();
    if (packetSize) {
    Serial.print("Received packet of size");
    IPAddress remote=udp.remoteIP();
    for (int i=0; i<4; i++) {
      Serial.print(remote[i], DEC);
      if (i<3) {
        Serial.print("."); }

and here is my matlab code for receiving the rfid values

close all
clear all

u=udp('',8888, 'TimeOut', 10);


or that char c is not a matrix i think

I'm not sure what definition of matrix you are using, but I can't think of a single one in which one character could be construed as being a matrix.

Where are you sending the data? I see you trying to read a UDP packet after reading each character from the RFID reader. What are you expecting to receive?

I see where, maybe, you are sending the data. But, what you are sending is NOT what you read. You are reading again, and sending the new character, which may not have arrived yet.

SoftwareSerial::read() returns an int, so that it can handle the case where there was nothing to read. If that happens, the low order byte is 0, and the high order byte is -1. EthernetUdp::write() expects a byte. When you pass an int, the low order byte is all that arrives.

what i want arduino to send to matlab, is the tag's id. and i want to send it as a whole. i don't care if it's in hex or dec. for ex. 2 98 54 76 43 43 23 65 3 . instead of that i get one number at a time. if i run the m file over and over again really fast i see the value of A changing for example. 2 , then it may become 76, then 65. i want to read it continously. but how do i do that? i believe i have to make c a matrix but how do i put the each value in there? also, i send two udp packets, the first one i send the letter l (replybuffer) just to check that its working, i don't need it anyways, i just used it to make sure that the packet gets sent out.don't let it bother you. the second packet is the one with the problem..

what i want arduino to send to matlab, is the tag's id. and i want to send it as a whole.

As a whole what? The values could be packed in a string (a NULL terminated array of chars) or the values could be packed in a long.

i believe i have to make c a matrix

The term is array, not matrix.

You first need to figure out how to read all the data for an RFID tag, without all that Ethernet and UDP stuff.

Only when you know what defines the start and end of an RFID tag can you hope to know when you have read a complete tag.