This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AMIC110: Modbus TCP/IP

Part Number: AMIC110


Hi,

I am developing Modbus TCP/IP functionality on AMIC110 and it works, but I have some questions.

  1. Every time when Ethernet packet comes, the program stops at the line of red text (yellow backgrould) when I set a breakpoint there.

If there is no Ethernet packets coming, my original understanding is that the program is in the loop of while(ioh->running). 

But I found my understanding seems wrong, the program does not stop at any line in while(ioh->running) if I set breakpoints in it.

How is the program behavior in the case of Ethernet packet comes and not come?

Does the program counter jumps to other function if there is no Ethernet packets coming?

static int32_t MBSTCPserver_parser (io_handler_t *ioh)
{
  uint8_t station_no;
  ioh->running = TRUE;
  while (ioh->running)
  {
    // Receive from socket
    bytes = recv(ioh->socket, ioh->receive_buffer, BUFFER_SIZES, 0); //receive byte by byte...
    if (bytes <= 0)
      break;
    station_no = ioh->receive_buffer[MDS_TCP_HDR_LEN - 1];
    if(station_no != 0)
    {
      if(!IsMyModbusFrame(station_no) && (station_no != 255))
      { break; }
    }
    ioh->receive_buffer[MDS_TCP_HDR_LEN - 1] = GetModbusStationId();
    int len = modbus_decode(ioh->receive_buffer + MDS_TCP_HDR_LEN,
                             bytes - MDS_TCP_HDR_LEN);

    // Update the length in MODBUS TCP header
    ioh->receive_buffer[5] = len;

    bytes = send(ioh->socket, ioh->receive_buffer, len + 6, 0);
    if (bytes <= 0)
      break;

  }

  return ERROR_SUCCESS;
}

2. The reason I ask the question above is that I want to send the data periodically and initiatively to the host, which connets to AMIC via Ethernnet.

So my thinking is to check a flag in while (ioh->running), then I call send() to send the data if the flag is set in other applicaiton functions.

But it seems not work because the program looks like not loop in the while().

Does any way to send the data initiatively?

Thanks in advance.

Kind regards,

Sandro