Differenze
Queste sono le differenze tra la revisione selezionata e la versione attuale della pagina.
| Entrambe le parti precedenti la revisione Revisione precedente Prossima revisione | Revisione precedente | ||
| modbus_code_example [01/10/2024 09:05] – admin | modbus_code_example [01/10/2024 10:06] (versione attuale) – admin | ||
|---|---|---|---|
| Linea 1: | Linea 1: | ||
| ===== Esempi di codice di programmazione Board MODBUS ===== | ===== Esempi di codice di programmazione Board MODBUS ===== | ||
| - | Gli esempi riportati | + | Gli esempi riportati |
| <code python example1.py> | <code python example1.py> | ||
| # | # | ||
| + | """ | ||
| + | Esempio minimale di configurazione della libreria minimalmodbus | ||
| + | """ | ||
| + | import minimalmodbus | ||
| + | import time | ||
| + | import sys | ||
| + | |||
| + | baudrate = 19200 | ||
| + | instrument = minimalmodbus.Instrument('/ | ||
| + | instrument.serial.baudrate = baudrate | ||
| + | instrument.serial.parity = minimalmodbus.serial.PARITY_NONE | ||
| + | instrument.serial.bytesize = 8 | ||
| + | instrument.serial.stopbits = 1 | ||
| + | instrument.serial.timeout = 0.05 # IMPORTANTE altrimenti perde l' | ||
| + | instrument.mode = minimalmodbus.MODE_RTU | ||
| + | instrument.clear_buffers_before_each_transaction = True | ||
| + | |||
| + | data = instrument.read_register(9) # Lettura dell' | ||
| + | print(data) | ||
| + | </ | ||
| + | |||
| + | MODBUS-B controllo dei relè con IO7 / 8 / 9 tramite IO 1 / 2 / 3. | ||
| + | Inoltre lettura: | ||
| + | - tensione 0 - 1.1Vdc su IO4 | ||
| + | - 2 sensori di temperatura con DS18B20 collegati su IO5 e IO6 | ||
| + | - tensione alimentazione BOARD IO98 | ||
| + | - temperatura interna MICRO | ||
| + | |||
| + | |||
| + | <code python example2.py> | ||
| + | # | ||
| """ | """ | ||
| - | Esempio | + | Esempio |
| - | quando gli IO 1, 2, 3 vendono portati a 0V | + | |
| """ | """ | ||
| Linea 25: | Linea 55: | ||
| instrument.clear_buffers_before_each_transaction = True | instrument.clear_buffers_before_each_transaction = True | ||
| + | data = instrument.read_register(9) # Lettura dell' | ||
| + | print(data) | ||
| </ | </ | ||
| + | |||