Udp Communication


Jonessy

Recommended Posts

Hello,

I have a device sending readings constantly using UDP. Message is always 1500 bytes long and measures start at byte 52. Each measurement is two bytes and I would like to read 10 measurements from the start and put them into DF's channels to trend, alarm etc.

I can see the data from wireshark but need a litlle help here. Can you give some suggestions how to read the device?

I can set transmission rate from once a second to 100 times in a second. Would it be possible to read data 100Hz?

Thank You

Link to comment
Share on other sites

As far as I know, only older versions of DAQFactory support UDP, and then I'm not sure even how well. Have you been able to make a connection and at least see the data? If you can get that far we can talk parsing, but I want to make sure we get that far first. If you don't see a UDP option, see if you can connect to it over TCP.

Link to comment
Share on other sites

Hello Guru,

the device is sending to port 30002 but I don't know how to make DF to see a packet coming to this port? But if UDP is not supported there is a possibility to make the device log data to a file and get readings from there. Maybe that is a way to go?

Thank you.

Link to comment
Share on other sites

  • 7 months later...

I use an ethernet to serial converter WIZ110SR and it works fine.

 

The UDP package @ 10Hz I receive look like below (the last 2 lines just repeat from the first one) 

Rx:

\000\000\014\000\\HK\198]\000]\240;W\165\185\208\008 \003\000\014\000\005\000\241O\248@\192\027\154Z \001\129}

\000\000\014\000\\HK\198]\000^\240;W\165\185\208\008 \003\000\014\000\005\000\241O\248@\192Z<t \001\129}

\000\000\014\000\\HK\198]\000_\240;W\165\185\208\008 \003\000\014\000\005\000\241O\248@\192L\239\134? \001\129}

 

I use a short script below:

 

while(1)
   try
      device.COMTEST.Purge()
      Private string datain = device.COMTEST.Read(18)      

 

 

      Data = AscA(datain)
     
   catch()               

 

      delay(.2)
      ? strLastError

 

   endcatch
endwhile

 

 

 

 

 

the value of "Data" mostly NULL (which I see 0 on the watch window)

 

Below is the description of the communication protocol of the received package:

 

(this is the header block – one for each UDP packet)

000 000 014 000       

xxx xxx xxx xxx xxx xxx   (this will change when you change the configuration - ignore)

ttt ttt ttt ttt ttt ttt ttt ttt    (this is a packet counter - ignore)

 

 

(this is the “Small Sensor Channel Record” block – should be one for each UDP packet)

003 000    (this value comes from the protocol for “Small Sensor Channel Record”)

           (most of your channels should be this kind)

sss sss    (this is the size of the data with this record. For type 3 it should be

            14 times the number of channels.

          (in this case, 1 channel times 14 equals 14)

 

 

(these bytes should be repeated for each channel)

nnn nnn    (channel number – this is how you will find the channel that you want)

           (in this case, the channel number appears to be 5)

vvv vvv vvv vvv         (the channel value)

  (in this case, the bytes are 241 047 248 032,

   which translates to a floating point value of

   around 4.2 time 10 to the -19 or what we call Zero.)

                        (I recommend you use raw counts (see below) to verify the

                         channels and ignore this value)

qqq        (quality – should be 192; if it isn’t, that usually means a problem.)

ttt ttt ttt ttt        (time offset – ignore)

fff        (flags – ignore)

rrr rrr        (raw counts)

               (in this case, the raw count bytes are 129 125

                which translates to a raw counts value of 32129.)

 

 

Thanks,

Link to comment
Share on other sites

data is declared as a number?

 

You should do read(36) since there are 36 bytes in your data block (if I counted right).  Also, select "Display All ASCII chars as codes" in the serial monitor as this is a strictly binary protocol.

 

You should either get timeout errors, or data should have 36 elements.

Link to comment
Share on other sites

Data is declaired as string and values show on the Watch window is {"0","0","0","0","0","0","0","0","0","0","0","0","4","0","0",.......}

 

Most of them are 0 and somtimes there is a number different than 0 show.

 

  

This is the display on the COM monitor when using All ASCII chars as codes:

Rx:\000\000\014\000\054\001\165\182\093\000\069\021\013\017\067\190\208\008\003\000\014\000\006\000\000\014\251\070\004\119\037\119\061\001\135\125\

 

I tried to read just the first 4 bytes but still don't get the number 14. 

 

Do you have any suggestion on this?

 

Thanks,

Link to comment
Share on other sites

Data should be a number, not a string.  Try adding:

 

? showhidden(datain)

 

right after the line that reads the serial port.  Also note that you don't have any sort of frame alignment, so if you read 4 bytes, you could be getting any four consecutive bytes in the packet.  Usually there is a marker, in your case the first 4 bytes, which you can use to verify that you are aligned.  I typically do purge(), then read(), then verify and if it fails verification, purge again and try again until I get it right.  Once you are lined up, as long as you read 36 bytes at a time you will stay lined up.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.