Sending UDP Data
I have an AXL2152 and am trying to read in a 3rd party IO-Link sensor to the IOL8.
I am able to successfully read in synchronous data (haven't been able to make asynchronous work). I am then trying to publish this data over UDP.
I have it almost working, this is how far I've gotten:
IF socket_active = TRUE THEN
UDP_SEND_22(REQ := FALSE, HANDLE := serv_sock, DEST_IP := ip_address, DEST_PORT := 9999, DATA_CNT := data_size, DATA := iol_1_1_IN, ERROR => sender_error, STATUS => sender_status, BUSY => sender_busy, DONE => sender_done);
IF sender_busy = FALSE THEN
UDP_SEND_22(REQ := TRUE, HANDLE := serv_sock, DEST_IP := ip_address, DEST_PORT := 9999, DATA_CNT := data_size, DATA := iol_1_1_IN, ERROR => sender_error, STATUS => sender_status, BUSY => sender_busy);
END_IF
END_IF
Where iol_1_1_IN is the input global variable of the sensor. I have a small python script on the computer I am trying to read from that receives some times just garbage, and at best the first byte of the iol_1_1_IN WORD.
I have even tried writing this iol_1_1_IN to a buffer of a byte array, but this has had the same result. I can't tell if this is an issue with how I am reading the data (I do not expect this), or how I am sending the data (I am more suspicious of this). I'd be beholden for a good structured text example using UDP.
Thanks in advance for the help.
Comments
Hi!
It seems you are missed with send request management. Try to modify it in the next way...
UDP_SEND_22( HANDLE := serv_sock
, DEST_IP := ip_address
, DEST_PORT := 9999
, DATA_CNT := data_size
, DATA := iol_1_1_IN
, ERROR => sender_error
, STATUS => sender_status
, BUSY => sender_busy
, DONE => sender_done);
IF socket_active and not sender_busy THEN
UDP_SEND_22.REQ := TRUE;
END_IF;
IF sender_done or sender_error or NOT socket_active THEN
UDP_SEND_22.REQ := FALSE;
END_IF;