Hi all, I've set up the basic UDP communication between DK-S7G2 and PC initially through NetX method, 1) but how to insert data to UDP packet, is there any sample code as references? I try to use the following method, but found it doesn't work... /***********************************************************************************************************************/ ... static NX_PACKET packet_ptr; ... static uint8_t packet_test[5]={0x06,0x07,0x08,0x09,0x0a}; ... packet_ptr.nx_packet_prepend_ptr = packet_test; packet_ptr.nx_packet_append_ptr = packet_test+4; OR /* Append data to the specified packet. */ /status = nx_packet_data_append(&packet_ptr, packet_test, 5, &pool_0, 5); /* If status is NX_SUCCESS, the additional five bytes have been appended to the packet. */ /* Check for UDP packet append errors. */ if (status) error_counter++; /* Send a packet to the UDP server at server_address on port 11000. */ status = nx_udp_socket_send(&udp_socket, packet_ptr, slave_address, 11000); /* If status == NX_SUCCESS, the application successfully transmitted the packet out the UDP socket to its peer. */ /* Check for UDP enable errors. */ if (status) error_counter++; .... /*******************************************************************************************************************************/ 2) Same questions to the reading process, what I get from the below buffer is just what I set in the Actual Data area in the Packet Pool. (not the data sent from PC) /*******************************************************************************************************************************/ ... static NX_PACKET packet_ptr; ... NX_PACKET *packet_ptr_ptr = &packet_ptr; ... /* Receive a packet from a previously created and bound UDP socket. If no packets are currently available, wait for 500 timer ticks before giving up. */ status = nx_udp_socket_receive(&udp_socket, packet_ptr_ptr, NX_WAIT_FOREVER); /* If status is NX_SUCCESS, the received UDP packet is pointed to by packet_ptr. */ /* Check for UDP enable errors. */ if (status) error_counter++; /* Retrieve data from packet pointed to by "packet_ptr". */ status = nx_packet_data_retrieve(&packet_ptr, buffer, &bytes_copied); /* If status is NX_SUCCESS, buffer contains the contents of the packet, the size of which is contained in "bytes_copied." */ /* Check for UDP enable errors. */ if (status) error_counter++; ... /*******************************************************************************************************************************/ What's the correct method to insert data and read data from UDP packet? (Here is the original code for reference, which implements basic UDP communication with PC and have commented all the uncertain lines (Please visit the site to view this file); PC UDP test code runs in VS2010 IDE or above version (Please visit the site to view this file))
↧