|
MODBUS laajempi esimerkki
|
Modbus functions. More...
#include "kosteus.h"
Functions | |
| unsigned char | check_own_address (unsigned char message[]) |
| Checks if the address in the received ModBus message is the same as the address of this device. More... | |
| unsigned char | get_function (unsigned char *message) |
| Retrieves the function code from the received ModBus message. More... | |
| unsigned int | get_sub_function (unsigned char *message) |
| Retrieves the sub function code from the received ModBus message. Is called only if function code is 0x08. More... | |
| unsigned int | get_start_address_of_holding_registers (unsigned char *message) |
| Retrieves the Start Address value for Holding Register reading. More... | |
| unsigned int | get_number_of_points (unsigned char *message) |
| Retrieves the Number of Points value for Holding Register reading. More... | |
| unsigned char | hex_to_ascii_hex (unsigned char response[], unsigned char length) |
| Converts characters from Hex to ASCII-Hex. More... | |
| unsigned char | ascii_hex_to_hex (unsigned char *message) |
| Converts two ASCII-Hex characters into one Hex-character. More... | |
| unsigned char | calculate_LRC (unsigned char *message, unsigned char nro_characters) |
| Calculates LRC checksum from received ModBus message. More... | |
| unsigned char | calculate_response_LRC (unsigned char *message, unsigned char nro_characters) |
| Calculates LRC checksum for the response to be sended. Called only once. More... | |
| unsigned char | check_LRC (unsigned char *message, unsigned char length_of_message) |
| Check the LRC in the received ModBus message. More... | |
| unsigned char | create_response_message (unsigned char *response) |
| Creates a response message.Not in use. More... | |
| void | create_exception_response (unsigned char function, unsigned char error_condition) |
| Creates a ModBus Exceprion Response message. Described in page 95 Modicon Modbus Protocol Reference Guide. More... | |
| void | create_diagnostic_response (unsigned int sub_function, unsigned int diagnostic_counter_value) |
| Creates a response for ModBus Diagnostic query. More... | |
| void | create_echo_of_query (unsigned char *message, unsigned char *length_of_response_hex) |
| Creates an echo of the received ModBus query. More... | |
| void | error_getting_message (unsigned char *s, unsigned char error_code) |
| Sends a debug message based on a specific error. More... | |
| void | transmit_response (unsigned char *send_pointer, unsigned char length) |
| Transmits the response to a ModBus query. More... | |
| void | clear_receive_buffer (void) |
| Clears the receive buffer. More... | |
| void | clear_response_buffer (void) |
| Clears the response buffer. More... | |
Variables | |
| unsigned char | message [MAX_LENGTH_OF_MESSAGE] |
| unsigned char | response [MAX_LENGTH_OF_MESSAGE] |
| unsigned char | response_in_ascii_hex [MAX_LENGTH_OF_MESSAGE] |
| unsigned char | length_of_ascii_hex_response |
| unsigned char * | send_pointer |
| volatile unsigned char | receive_buffer [MAX_LENGTH_OF_BUFFER] |
| unsigned char | received_character |
| unsigned int | number_of_points |
| unsigned | intstart_address |
| volatile unsigned char | nro_characters_received |
| int | previouse_received_character |
| unsigned int | start_address |
| unsigned char | length_of_response |
| unsigned char | length_of_message |
| unsigned char | modbuss_address |
| unsigned long int | receive_timeout |
| unsigned char | array_of_ascii_characters [16] = "0123456789ABCDEF" |
Modbus functions.
| unsigned char ascii_hex_to_hex | ( | unsigned char * | message | ) |
Converts two ASCII-Hex characters into one Hex-character.
| message | Pointer to two ASCII-Hex characters to be converted. |

| unsigned char calculate_LRC | ( | unsigned char * | message, |
| unsigned char | nro_characters | ||
| ) |
Calculates LRC checksum from received ModBus message.
| message | The received ModBus message in ASCII-Hex. |
| nro_characters | Number of characters in the received ModBus message. |


| unsigned char calculate_response_LRC | ( | unsigned char * | message, |
| unsigned char | nro_characters | ||
| ) |
Calculates LRC checksum for the response to be sended. Called only once.
| message | The response message in HEX. |
| nro_characters | Number of characters to be included in the calculation. |

| unsigned char check_LRC | ( | unsigned char * | message, |
| unsigned char | length_of_message | ||
| ) |
Check the LRC in the received ModBus message.
| message | The received ModBus message. |
| length_of_message | Length of the received message. |


| unsigned char check_own_address | ( | unsigned char | message[] | ) |
Checks if the address in the received ModBus message is the same as the address of this device.
| message | The received ModBus message. |


| void clear_receive_buffer | ( | void | ) |
Clears the receive buffer.

| void clear_response_buffer | ( | void | ) |
Clears the response buffer.

| void create_diagnostic_response | ( | unsigned int | sub_function, |
| unsigned int | diagnostic_counter_value | ||
| ) |
Creates a response for ModBus Diagnostic query.
| sub_function | The sub function value from the received query. |
| diagnostic_counter_value | Diagnostic counter value responding to the received query. |

| void create_echo_of_query | ( | unsigned char * | message, |
| unsigned char * | length_of_response_hex | ||
| ) |
Creates an echo of the received ModBus query.
| message | Pointer to the received ModBus query. |
| length_of_response_hex | Length of the query in Hex. |


| void create_exception_response | ( | unsigned char | function, |
| unsigned char | error_condition | ||
| ) |
Creates a ModBus Exceprion Response message. Described in page 95 Modicon Modbus Protocol Reference Guide.
| function | The ModBus function where the exception occurred. |
| error_condition | The condition why the error occurred (Standard ModBus Exception Error code). |

| unsigned char create_response_message | ( | unsigned char * | response | ) |
Creates a response message.Not in use.
| response | Pointer to response message. |
| void error_getting_message | ( | unsigned char * | s, |
| unsigned char | error_code | ||
| ) |
Sends a debug message based on a specific error.
| s | Pointer to message that caused the error. |
| error_code | Specific error code. |

| unsigned char get_function | ( | unsigned char * | message | ) |
Retrieves the function code from the received ModBus message.
| message | Pointer to the received ModBus message. |


| unsigned int get_number_of_points | ( | unsigned char * | message | ) |
Retrieves the Number of Points value for Holding Register reading.
| message | Pointer to the received ModBus message. |


| unsigned int get_start_address_of_holding_registers | ( | unsigned char * | message | ) |
Retrieves the Start Address value for Holding Register reading.
| message | Pointer to the received ModBus message. |


| unsigned int get_sub_function | ( | unsigned char * | message | ) |
Retrieves the sub function code from the received ModBus message. Is called only if function code is 0x08.
| message | Pointer to the received ModBus message. |


| unsigned char hex_to_ascii_hex | ( | unsigned char | response[], |
| unsigned char | length | ||
| ) |
Converts characters from Hex to ASCII-Hex.
| response | Array of characters to be converted. |
| length | Length of the array. |

| void transmit_response | ( | unsigned char * | send_pointer, |
| unsigned char | length | ||
| ) |
Transmits the response to a ModBus query.
| send_pointer | Response in ASCII-Hex without START- and STOP-characters. |
| length | Length of the response. |


| unsigned char array_of_ascii_characters[16] = "0123456789ABCDEF" |
| unsigned intstart_address |
| unsigned char length_of_ascii_hex_response |
| unsigned char length_of_message |
| unsigned char length_of_response |
| unsigned char message[MAX_LENGTH_OF_MESSAGE] |
Totally received modbus frame
| unsigned char modbuss_address |
| volatile unsigned char nro_characters_received |
| unsigned int number_of_points |
| int previouse_received_character |
| volatile unsigned char receive_buffer[MAX_LENGTH_OF_BUFFER] |
| unsigned long int receive_timeout |
| unsigned char received_character |
| unsigned char response[MAX_LENGTH_OF_MESSAGE] |
Response frame to be sended to master
| unsigned char response_in_ascii_hex[MAX_LENGTH_OF_MESSAGE] |
| unsigned char* send_pointer |
| unsigned int start_address |