Extra points if you break each step into its own method, to make it easy for the main program to choose between methods later (e.g. modify the TCP client to read back those data, and prove it works by parsing those data and printing the results to standard output.Įach one of those steps is typically, and often far, less than a couple dozen lines of code.modbus address offset = 16 and quantity = 3 => 16, 17, 18), subtracting each from 65535 (so 65519, 65518, 65517) and converting those to a Modbus response (additional address, function code, 2-byte byte count, register data), and sending that message (add'l address, 0x03, 6, 65519, 65518, 65517) as a response to the client modify the TCP server the generate data for a response by taking the addresses requested (e.g.modify the TCP client to generate a Read Holding Registers Modbus protocol request and send same to the TCP server, and prove it works by having the server print out the details of the request (additional address, function code, offset to starting address, request quantity).3 (0x03) Read Holding Registers, so it will see the byte 3, parse the next two bytes as an MSByte-first offset into the server's "holding registers," and the next two bytes as an MSByte-first quantity of registers requested. modify the TCP server to parse the PDU for one type of function code e.g.modify the TCP client to send that Modbus protocol message to the server connection, and prove it works by having the server print the additional address and the function code (first byte) of the PDU.modify the TCP server to parse a Modbus protocol message don't worry about fully parsing the PDU beyond the function code yet.modify the TCP client to create a Modbus protocol message (ADU = additional (modbus unit, usually 1 or 0) address (1 byte) + PDU (1 to 253 bytes) Modbus TCP needs no CRC PDU = function code (1 byte) _[1 to 252 bytes)) as data, and print it to standard output, but converted to hexadecimal so you can read it. ![]() By this point, you have more or less duplicated the hello world examples.modify the TCP client to read the response from the server, and prove it works by having the client print "received response YYYY-mm-ddTHH:MM:SSOK.".the current time plus "OK," back to the client over the connection modify the TCP server to, after receiving the client data, to send response data (e.g.modify the TCP client to write data to the connection, and prove it works by having the server above print "received data" to the terminal.modify the TCP server to read the accepted connection. ![]()
0 Comments
Leave a Reply. |