써멀이 쓸데없이 귀엽게 발라졌네
소중한 딸래미의 개인정보 유출 방지를 위해 eMMC를 아작내버리고 쓰레기통으로 슝~
'개소리 왈왈 > 모바일 생활' 카테고리의 다른 글
요금제 변경 시도 (0) | 2022.06.02 |
---|---|
어라 요금제 폭탄? (0) | 2022.05.17 |
오늘의 지름 (0) | 2022.04.06 |
v50s 액정 사설 수리 비용 (0) | 2022.03.04 |
액정깨짐 (0) | 2021.10.23 |
써멀이 쓸데없이 귀엽게 발라졌네
소중한 딸래미의 개인정보 유출 방지를 위해 eMMC를 아작내버리고 쓰레기통으로 슝~
요금제 변경 시도 (0) | 2022.06.02 |
---|---|
어라 요금제 폭탄? (0) | 2022.05.17 |
오늘의 지름 (0) | 2022.04.06 |
v50s 액정 사설 수리 비용 (0) | 2022.03.04 |
액정깨짐 (0) | 2021.10.23 |
그냥 그냥저냥 지나감
포켓몬 빵 사겠다고 (2) | 2022.05.15 |
---|---|
요즘은 금쪽이 보고 사는 중 (0) | 2022.05.13 |
생일, 결혼기념일 (0) | 2022.05.07 |
노트5 파괴! (0) | 2022.05.06 |
어린이날 (0) | 2022.05.05 |
5월 가정 경제 파탄의 달 마지막(?) 행사가 되길 ㅠㅠ
요즘은 금쪽이 보고 사는 중 (0) | 2022.05.13 |
---|---|
어버이날 (0) | 2022.05.08 |
노트5 파괴! (0) | 2022.05.06 |
어린이날 (0) | 2022.05.05 |
메인보드 구매, 교체 (0) | 2022.04.30 |
기본 소스를 사용해보면. modbus_receive() 에서 블록킹 된 상태라서 다른걸 할 수가 없다.
검색을 해보니 libmodbus issue 쪽에서 발견한 내용으로
poll 에서 확인이 되면 소켓을 modbus_set_socket() 함수를 이용하여 context에 연결하고 receive 하도록 구성되어 있다.
modbus_t *ctx = modbus_new_tcp("0.0.0.0", port_); int server_socket = modbus_tcp_listen(ctx, 2); if (server_socket < 0) { // error handling modbus_free(ctx); return; } if (p->revents & POLLIN) { modbus_set_socket(ctx, p->fd); // set the socket to libmodbus answers to the right client uint8_t query[MODBUS_RTU_MAX_ADU_LENGTH]; int rc = modbus_receive(ctx, query); if (rc <= 0) { // connection has been closed actually by the client ::close(p->fd); p = sockets.erase(p); // remove it from the poll-array continue; } /* rc is the query size */ rc = modbus_reply_callback(ctx, query, rc); // handle the reply (via the callbacks) if (rc < 0) { // error handling - invalid request ::close(p->fd); // close client p = sockets.erase(p); continue; } } |
[링크 : https://github.com/stephane/libmodbus/issues/173]
[링크 : https://libmodbus.org/docs/v3.0.8/modbus_set_socket.html]
libmodbus pi 함수들 (0) | 2022.05.10 |
---|---|
libmodbus modbus_mapping_new() (0) | 2022.05.10 |
modbus tcp (0) | 2022.05.04 |
libmodbus 예제 프로그램 (0) | 2022.05.04 |
libmodbus tcp 예제 (0) | 2022.05.04 |
modbus tcp의 MBAP(ModBus Application Protocol) 헤더(?)에는 아래와 같은 내용들이 들어있다.
[링크 : https://www.modbus.org/docs/Modbus_Messaging_Implementation_Guide_V1_0b.pdf]
[링크 : http://comfilewiki.co.kr/ko/doku.php?id=tcpport:modbus-tcp_프로토콜이란:index]
Function Code (0x03) + start Address(0x0000) + quantity of regitster(0x0001)
Protocol ID(0x0000 고정) Length Function Code 00 01 00 00 00 06 03 03 00 00 00 01 Unit ID(0x01 고정) Transaction ID (시퀀셜 증가) |
-a로 tcp MBAP 상의 Unit ID를 변경할 순 있지만 ID=1 로 고정되어 있다고 하니 어떻게 처리를 해야 하려나?
$ sudo ./modpoll -m tcp localhost 00 01 00 00 00 06 01 03 00 00 00 01 $ sudo ./modpoll -m tcp -a 3 localhost 00 01 00 00 00 06 03 03 00 00 00 01 |
$ ./modpoll --help modpoll 3.10 - FieldTalk(tm) Modbus(R) Master Simulator Copyright (c) 2002-2021 proconX Pty Ltd Visit https://www.modbusdriver.com for Modbus libraries and tools. Usage: modpoll [OPTIONS] SERIALPORT|HOST [WRITEVALUES...] Arguments: SERIALPORT Serial port when using Modbus ASCII or Modbus RTU protocol COM1, COM2 ... on Windows /dev/ttyS0, /dev/ttyS1 ... on Linux HOST Host name or dotted IP address when using MDBUS/TCP protocol WRITEVALUES List of values to be written. If none specified (default) modpoll reads data. General options: -m ascii Modbus ASCII protocol -m rtu Modbus RTU protocol (default if SERIALPORT contains a /) -m tcp MODBUS/TCP protocol (default otherwise) -m udp MODBUS UDP -m enc Encapsulated Modbus RTU over TCP -a # Slave address (1-247 for serial, 0-255 for TCP, 1 is default) -r # Start reference (1-65536, 100 is default) -c # Number of values to read (1-125, 1 is default), optional for writing (use -c 1 to force FC5 or FC6) -t 0 Discrete output (coil) data type -t 1 Discrete input data type -t 3 16-bit input register data type -t 3:hex 16-bit input register data type with hex display -t 3:int 32-bit integer data type in input register table -t 3:mod 32-bit module 10000 data type in input register table -t 3:float 32-bit float data type in input register table -t 4 16-bit output (holding) register data type (default) -t 4:hex 16-bit output (holding) register data type with hex display -t 4:int 32-bit integer data type in output (holding) register table -t 4:mod 32-bit module 10000 type in output (holding) register table -t 4:float 32-bit float data type in output (holding) register table -i Slave operates on big-endian 32-bit integers -f Slave operates on big-endian 32-bit floats -e Use Daniel/Enron single register 32-bit mode (implies -i and -f) -0 First reference is 0 (PDU addressing) instead 1 -1 Poll only once only, otherwise every poll rate interval -l # Poll rate in ms, (1000 is default) -o # Time-out in seconds (0.01 - 10.0, 1.0 s is default) Options for MODBUS/TCP, UDP and RTU over TCP: -p # IP protocol port number (502 is default) Options for Modbus ASCII and Modbus RTU: -b # Baudrate (e.g. 9600, 19200, ...) (19200 is default) -d # Databits (7 or 8 for ASCII protocol, 8 for RTU) -s # Stopbits (1 or 2, 1 is default) -p none No parity -p even Even parity (default) -p odd Odd parity -4 # RS-485 mode, RTS on while transmitting and another # ms after |
libmodbus modbus_mapping_new() (0) | 2022.05.10 |
---|---|
libmodbus poll 적용 (0) | 2022.05.04 |
libmodbus 예제 프로그램 (0) | 2022.05.04 |
libmodbus tcp 예제 (0) | 2022.05.04 |
libmodbus (0) | 2022.05.03 |
$ sudo find / -name "modbus\.h" /usr/include/modbus/modbus.h |
$ ll /usr/lib/x86_64-linux-gnu/libmodbus.so* lrwxrwxrwx 1 root root 18 12월 4 01:53 /usr/lib/x86_64-linux-gnu/libmodbus.so -> libmodbus.so.5.0.5 lrwxrwxrwx 1 root root 18 12월 4 01:53 /usr/lib/x86_64-linux-gnu/libmodbus.so.5 -> libmodbus.so.5.0.5 -rw-r--r-- 1 root root 39256 12월 4 01:53 /usr/lib/x86_64-linux-gnu/libmodbus.so.5.0.5 |
$ cat Makefile all: gcc modbus_tcp_server.c -o modbustcp -I/usr/include/modbus -lmodbus -L/usr/lib/x86_64-linux-gnu clean: rm modbustcp |
$ pkg-config --libs --cflags libmodbus -I/usr/include/modbus -lmodbus |
[링크 : https://github.com/stephane/libmodbus/issues/123]
+
modbus_mapping_new_start_address()가 없고 modbus_mapping_new() 있긴 하다..
$ readelf -Ws /usr/lib/x86_64-linux-gnu/libmodbus.so | grep "modbus_" 48: 0000000000004ce0 222 FUNC GLOBAL DEFAULT 12 modbus_report_slave_id 49: 0000000000005320 208 FUNC GLOBAL DEFAULT 12 _modbus_rtu_check_integrity 50: 0000000000005050 86 FUNC GLOBAL DEFAULT 12 modbus_get_byte_from_bits 51: 0000000000004400 102 FUNC GLOBAL DEFAULT 12 modbus_read_bits 52: 0000000000004fd0 38 FUNC GLOBAL DEFAULT 12 modbus_set_bits_from_byte 53: 00000000000057e0 183 FUNC GLOBAL DEFAULT 12 modbus_rtu_set_serial_mode 54: 00000000000047a0 14 FUNC GLOBAL DEFAULT 12 modbus_write_register 55: 00000000000047b0 470 FUNC GLOBAL DEFAULT 12 modbus_write_bits 56: 0000000000004470 102 FUNC GLOBAL DEFAULT 12 modbus_read_input_bits 57: 0000000000003040 2825 FUNC GLOBAL DEFAULT 12 modbus_reply 58: 0000000000004690 94 FUNC GLOBAL DEFAULT 12 modbus_read_input_registers 59: 00000000000060d0 490 FUNC GLOBAL DEFAULT 12 modbus_tcp_pi_listen 60: 0000000000005ab0 3 FUNC GLOBAL DEFAULT 12 _modbus_tcp_check_integrity 61: 00000000000059f0 97 FUNC GLOBAL DEFAULT 12 _modbus_tcp_build_request_basis 62: 0000000000005000 69 FUNC GLOBAL DEFAULT 12 modbus_set_bits_from_bytes 63: 0000000000006370 150 FUNC GLOBAL DEFAULT 12 modbus_tcp_pi_accept 64: 0000000000005a90 13 FUNC GLOBAL DEFAULT 12 _modbus_tcp_prepare_response_tid 65: 0000000000004780 24 FUNC GLOBAL DEFAULT 12 modbus_write_bit 66: 00000000000050d0 15 FUNC GLOBAL DEFAULT 12 modbus_set_float 67: 00000000000050f0 6 FUNC GLOBAL DEFAULT 12 _modbus_rtu_prepare_response_tid 68: 0000000000005ae0 13 FUNC GLOBAL DEFAULT 12 _modbus_tcp_recv 70: 0000000000005190 11 FUNC GLOBAL DEFAULT 12 _modbus_rtu_recv 71: 0000000000208ce0 128 OBJECT GLOBAL DEFAULT 19 _modbus_tcp_pi_backend 72: 0000000000005de0 115 FUNC GLOBAL DEFAULT 12 _modbus_tcp_pre_check_confirmation 73: 00000000000042e0 10 FUNC GLOBAL DEFAULT 12 modbus_receive_confirmation 74: 0000000000208c60 128 OBJECT GLOBAL DEFAULT 19 _modbus_rtu_backend 75: 00000000000058e0 258 FUNC GLOBAL DEFAULT 12 modbus_new_rtu 76: 0000000000005b70 26 FUNC GLOBAL DEFAULT 12 _modbus_tcp_close 77: 0000000000004df0 4 FUNC GLOBAL DEFAULT 12 modbus_set_debug 78: 0000000000002dd0 9 FUNC GLOBAL DEFAULT 12 modbus_set_response_timeout 80: 0000000000006410 205 FUNC GLOBAL DEFAULT 12 modbus_new_tcp 81: 0000000000002730 261 FUNC GLOBAL DEFAULT 12 modbus_strerror 82: 00000000000028d0 78 FUNC GLOBAL DEFAULT 12 modbus_flush 83: 0000000000005c20 209 FUNC GLOBAL DEFAULT 12 _modbus_tcp_select 84: 0000000000002dc0 9 FUNC GLOBAL DEFAULT 12 modbus_get_response_timeout 85: 00000000000051a0 31 FUNC GLOBAL DEFAULT 12 _modbus_rtu_close 86: 0000000000002de0 9 FUNC GLOBAL DEFAULT 12 modbus_get_byte_timeout 87: 0000000000005aa0 12 FUNC GLOBAL DEFAULT 12 _modbus_tcp_send_msg_pre 88: 0000000000006f30 4 OBJECT GLOBAL DEFAULT 14 libmodbus_version_micro 89: 0000000000005ac0 3 FUNC GLOBAL DEFAULT 12 _modbus_tcp_filter_request 90: 0000000000002db0 4 FUNC GLOBAL DEFAULT 12 modbus_get_socket 91: 00000000000042d0 7 FUNC GLOBAL DEFAULT 12 modbus_receive 92: 0000000000005a60 34 FUNC GLOBAL DEFAULT 12 _modbus_tcp_build_response_basis 93: 0000000000004e00 296 FUNC GLOBAL DEFAULT 12 modbus_mapping_new 94: 0000000000002e00 8 FUNC GLOBAL DEFAULT 12 modbus_get_header_length 95: 0000000000002d50 48 FUNC GLOBAL DEFAULT 12 _modbus_init_common 96: 0000000000004620 101 FUNC GLOBAL DEFAULT 12 modbus_read_registers 97: 00000000000051d0 209 FUNC GLOBAL DEFAULT 12 _modbus_rtu_select 98: 0000000000002e10 7 FUNC GLOBAL DEFAULT 12 modbus_connect 99: 0000000000002df0 9 FUNC GLOBAL DEFAULT 12 modbus_set_byte_timeout 101: 0000000000004ad0 526 FUNC GLOBAL DEFAULT 12 modbus_write_and_read_registers 102: 0000000000002da0 4 FUNC GLOBAL DEFAULT 12 modbus_set_socket 103: 0000000000002d90 12 FUNC GLOBAL DEFAULT 12 modbus_set_error_recovery 104: 0000000000005fc0 260 FUNC GLOBAL DEFAULT 12 modbus_tcp_listen 106: 0000000000005ad0 16 FUNC GLOBAL DEFAULT 12 _modbus_tcp_send 107: 0000000000004990 320 FUNC GLOBAL DEFAULT 12 modbus_write_registers 108: 0000000000005180 11 FUNC GLOBAL DEFAULT 12 _modbus_rtu_send 109: 0000000000006f34 4 OBJECT GLOBAL DEFAULT 14 libmodbus_version_minor 110: 00000000000052b0 54 FUNC GLOBAL DEFAULT 12 _modbus_rtu_filter_request 111: 0000000000004f30 66 FUNC GLOBAL DEFAULT 12 modbus_mapping_free 113: 0000000000006f38 4 OBJECT GLOBAL DEFAULT 14 libmodbus_version_major 114: 00000000000058a0 49 FUNC GLOBAL DEFAULT 12 modbus_rtu_get_serial_mode 115: 0000000000003b50 231 FUNC GLOBAL DEFAULT 12 modbus_reply_exception 116: 0000000000005af0 126 FUNC GLOBAL DEFAULT 12 _modbus_tcp_flush 117: 00000000000064e0 328 FUNC GLOBAL DEFAULT 12 modbus_new_tcp_pi 118: 00000000000062c0 164 FUNC GLOBAL DEFAULT 12 modbus_tcp_accept 119: 0000000000005100 121 FUNC GLOBAL DEFAULT 12 _modbus_rtu_send_msg_pre 120: 0000000000002d80 7 FUNC GLOBAL DEFAULT 12 modbus_set_slave 121: 0000000000208d60 128 OBJECT GLOBAL DEFAULT 19 _modbus_tcp_backend 122: 0000000000002f60 209 FUNC GLOBAL DEFAULT 12 modbus_send_raw_request 123: 0000000000002e20 18 FUNC GLOBAL DEFAULT 12 modbus_close 124: 00000000000050b0 23 FUNC GLOBAL DEFAULT 12 modbus_get_float 125: 00000000000051c0 13 FUNC GLOBAL DEFAULT 12 _modbus_rtu_flush 129: 0000000000004dc0 34 FUNC GLOBAL DEFAULT 12 modbus_free |
이름은 libmodbus5 인데 왜 버전은 3.0.6이 나오냐 -_-
[링크 : https://ubuntu.pkgs.org/18.04/ubuntu-universe-amd64/libmodbus5_3.0.6-2_amd64.deb.html]
[링크 : https://github.com/stephane/libmodbus/blob/v3.0.6/tests/unit-test-server.c]
[링크 : https://github.com/stephane/libmodbus/blob/master/tests/unit-test-server.c]
libmodbus poll 적용 (0) | 2022.05.04 |
---|---|
modbus tcp (0) | 2022.05.04 |
libmodbus tcp 예제 (0) | 2022.05.04 |
libmodbus (0) | 2022.05.03 |
modbus tcp 테스트 툴 (0) | 2022.05.03 |
유닛 테스트 하는 프로그램을 뜯어 보면 서비스 초기화 하는 코드를 분석하기 유리할 듯
[링크 : https://github.com/stephane/libmodbus/blob/master/tests/unit-test-server.c]
[링크 : https://github.com/stephane/libmodbus/blob/master/tests/unit-test-client.c]
modbus tcp (0) | 2022.05.04 |
---|---|
libmodbus 예제 프로그램 (0) | 2022.05.04 |
libmodbus (0) | 2022.05.03 |
modbus tcp 테스트 툴 (0) | 2022.05.03 |
modbus tcp library (0) | 2022.04.25 |
$ apt-cache search libmodbus libmodbus5 - library for the Modbus protocol libmodbus-dev - development files for the Modbus protocol library |
libmodbus에서 기본으로 제공하는 예제인데
127.0.0.1의 1502번 포트로 접속을 해서 0번 address에 5바이트를 읽어 오도록 하는 명령이다
modbus로는 0x03(read holding register) 명령으로 5바이트 읽는 건데..
이게 modbus tcp의 master 라고 해야하나?
#include <stdio.h> #include <modbus.h> int main(void) { modbus_t *mb; uint16_t tab_reg[32]; mb = modbus_new_tcp("127.0.0.1", 1502); modbus_connect(mb); /* Read 5 registers from the address 0 */ modbus_read_registers(mb, 0, 5, tab_reg); modbus_close(mb); modbus_free(mb); } |
[링크 : https://libmodbus.org/documentation/]
[링크 : https://libmodbus.org/]
ClientThe Modbus protocol defines different data types and functions to read and write them from/to remote devices. The following functions are used by the clients to send Modbus requests:
Read data
modbus_read_bits(3) modbus_read_input_bits(3) modbus_read_registers(3) modbus_read_input_registers(3) modbus_report_slave_id(3) Write data modbus_write_bit(3) modbus_write_register(3) modbus_write_bits(3) modbus_write_registers(3) Write and read data modbus_write_and_read_registers(3) Raw requests modbus_send_raw_request(3) modbus_receive_confirmation(3) Reply an exception modbus_reply_exception(3) ServerThe server is waiting for request from clients and must answer when it is concerned by the request. The libmodbus offers the following functions to handle requests:
Data mapping: modbus_mapping_new(3) modbus_mapping_free(3)
|
[링크 : https://libmodbus.org/docs/v3.0.8/]
SYNOPSISint modbus_receive(modbus_t *ctx, uint8_t *req);
DESCRIPTIONThe modbus_receive() function shall receive an indication request from the socket of the context ctx. This function is used by Modbus slave/server to receive and analyze indication request sent by the masters/clients.
If you need to use another socket or file descriptor than the one defined in the context ctx, see the function modbus_set_socket(3).
|
[링크 : https://libmodbus.org/docs/v3.0.8/modbus_receive.html]
SYNOPSIS*int modbus_reply(modbus_t *ctx, const uint8_t *req, int req_length, modbus_mapping_t *mb_mapping);
DESCRIPTIONThe modbus_reply() function shall send a response to received request. The request req given in argument is analyzed, a response is then built and sent by using the information of the modbus context ctx.
If the request indicates to read or write a value the operation will done in the modbus mapping mb_mapping according to the type of the manipulated data.
If an error occurs, an exception response will be sent.
This function is designed for Modbus server.
|
[링크 : https://libmodbus.org/docs/v3.0.8/modbus_reply.html]
MODBUS-TCP 통신규격에는 마스터(Client)와 슬레이브(Server)의 역할이 나누어져 있습니다. 슬레이브(Server)는 마스터(Client)가 요청하는 데이터에 대해 응답을 해줍니다. 주로 마스터(Client)에는 산업용터치 HMI 기기, 또는 PC 와 같은 상위 기기가 위치합니다. 그리고 슬레이브(Server)에는 TCPPORT 나 PLC 등이 위치합니다. 슬레이브(Server)는 상위기기에서 요청하는 동작만을 하는 수동적인 위치에 있습니다. 반면 마스터(Client)쪽에서는 원하는 데이터를 읽어오거나, 원하는 데이터를 기입하는 등 적극적으로 슬레이브(Server) 기기를 다루어 주어야 합니다. |
[링크 : http://comfilewiki.co.kr/ko/doku.php?id=tcpport:modbus-tcp_프로토콜이란:index]
[링크 : https://gosuway.tistory.com/374]
+
int main(void) { int i; int s = -1; modbus_t *ctx; modbus_mapping_t *mb_mapping; ctx = modbus_new_tcp("127.0.0.1", 1502); // modbus_set_debug(ctx, TRUE); mb_mapping = modbus_mapping_new(0, 0, 500, 500); if (mb_mapping == NULL) { fprintf(stderr, "Failed to allocate the mapping: %s\n", modbus_strerror(errno)); modbus_free(ctx); return -1; } s = modbus_tcp_listen(ctx, 1); modbus_tcp_accept(ctx, &s); for (;;) { uint8_t query[MODBUS_TCP_MAX_ADU_LENGTH]; int rc; rc = modbus_receive(ctx, query); printf("SLAVE: regs[] =\t"); for(i = 1; i != 11; i++) { // looks like 1..n index printf("%d ", mb_mapping->tab_registers[i]); } printf("\n"); if (rc > 0) { /* rc is the query size */ modbus_reply(ctx, query, rc, mb_mapping); } else if (rc == -1) { /* Connection closed by the client or error */ break; } } printf("Quit the loop: %s\n", modbus_strerror(errno)); if (s != -1) { close(s); } modbus_mapping_free(mb_mapping); modbus_close(ctx); modbus_free(ctx); return 0; } |
[링크 : https://github.com/pjmaker/libmodbus-wee-example/blob/master/slave.c]
libmodbus 예제 프로그램 (0) | 2022.05.04 |
---|---|
libmodbus tcp 예제 (0) | 2022.05.04 |
modbus tcp 테스트 툴 (0) | 2022.05.03 |
modbus tcp library (0) | 2022.04.25 |
modbus 프로토콜 (0) | 2015.09.16 |