I want send data by UDP to cr1000 with NL115, but no data is recevied. Program like this:
Sub Data_UDP
'Form the first part of the string
DataString = "Rainfall Tip occurred." 'This is the event message string
'Now calculate a UKMO 16-bit CRC on the contents of the message
DataCRC = CheckSum(DataString,5,0)
'Now insert the CRC into the requisite part of the string
DataStringCRC_OUT = DataString+"CRC="+DataCRC+CHR(13)+CHR(10)
' UDP to primary IP address
' Format is UDPDataGram("IPAddress",UDP Port, SendBuffer, SendLength, RecvBuffer, Timeout)
' as it turns out, the Port number can't be a string enclosed in quotes. It must be a number.
'UDPDataGram(UDPPrimary,8002,DataStringCRC_OUT,100,0,0)
UDPDataGram("192.168.1.109",6785,0,0,DataStringCRC_IN,10)
EndSub
Whg573,
I will admit that I have only used UDPOpen and TCPOpen in conjunction with SerialOut. However, I think the following examples [REMOVED-SEE CODE POSTED LATER IN THREAD] will at least get you started in the right direction.
At first your code looks to be forming a message for transmission. Then you configure the UDPDataGram instruction for receiving. Not a good combo.
Additionally, I would stay away from 6785 since the logger is probably configured to use 6785 for PakBus communications.
[CODE EXAMPLES REMOVED-SEE CODE POSTED LATER IN THREAD]
* Last updated by: Sam on 1/17/2011 @ 2:14 PM *
Sam, Thank U so much!
But I have to tell you that: These 2 methods can send the data to a computer, and the PC can get the data from dataloggers,but dataloggers can not receive data from the computer! I don't know Why,Maybe you can Send me soft which you used to send data from computer to dataloggers
I have only used UDPOpen and UDPDataGram for sending data from the logger to a computer/server. I'll look into this further.
In the mean time, does your application require UDP? Or is TCP acceptable?
If TCP is acceptable, I have tested the following.
In this example, a client (e.g. computer) initiates the connection with the datalogger (in this case the host). When this happens, Sock > 100. When the client sends a message, the logger responds with an OK[#].
Public TX As String * 63
Public RX As String * 63
Public Sock As Long
Public NBRX
Public Counter
BeginProg
Scan (5,Sec,0,0)
Sock = TCPOpen ("",6000,100) 'listen for inbound connection
If Sock >=100 Then ' a connection has been established
NBRX = SerialInBlock (Sock,RX,50) 'receive data
If NBRX > 0 Then
Counter = Counter + 1
TX = "OK:" + Counter
SerialOutBlock (Sock,TX,63) 'respond with acknowledgement
EndIf
EndIf
NextScan
EndProg
Sam
whg573,
Can you tell me more about how you are initiating a UDP message on the computer? It occurred to me that the symptoms you describe would occur if you had not bound a port on the computer to the destination.
Sam
whg573,
I understand your frustration now. I am not having success with receiving data using the UDPDataGram instruction. I will bring this up with Engineering. In the mean time, I am going to edit my post above to remove the non-working code, and I am posting some code below that is working well for me.
' LOGGER OPENS CONNECTION WITH HOST
' - WAITS FOR INPUT FROM HOST
' - RESPONDS WITH TX STRING (OK)
Public RX As String * 63
Public TX As String * 63 = "OK"
Public Sock As Long
BeginProg
Scan (5,Sec,0,0)
Sock = UDPOpen ("192.168.13.100",6000,100)
RX = ""
SerialIn (RX,Sock,100,"",100)
If RX <> "" Then
SerialOut (Sock,TX,"",0,100)
EndIf
NextScan
EndProg
I used two software programs for testing the code above -
* HW-group's "Hercules"
* Simple Com Tools' "UDP Test Tool"
* Last updated by: Sam on 1/17/2011 @ 2:16 PM *
Hi, Sam
Badly I am not having success with receiving data from datalogger, Maybe you can tell me that NL115's seting of TCP/IP and Net Services you use!
And the IP 192.168.13.100 in your code is computer'IP, right?
whg573,
Correct, in the example, 192.168.13.100 is the IP address of my computer.
Double check your computer's firewall settings.