Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ICE-Application/src/ModbusMaster/ModbusMasterApi.cpp@1:b2e90cda7a5a, 2017-01-24 (annotated)
- Committer:
- jmarkel44
- Date:
- Tue Jan 24 19:06:45 2017 +0000
- Revision:
- 1:b2e90cda7a5a
- Parent:
- 0:61364762ee0e
Port from IAR F412 project
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jmarkel44 | 0:61364762ee0e | 1 | #include "ModbusMasterApi.h" |
| jmarkel44 | 0:61364762ee0e | 2 | #include "ICELog.h" |
| jmarkel44 | 0:61364762ee0e | 3 | #include <stdio.h> |
| jmarkel44 | 0:61364762ee0e | 4 | |
| jmarkel44 | 0:61364762ee0e | 5 | bool ModbusMasterReadRegister( const std::string &io_tag, ModbusValue *value ) |
| jmarkel44 | 0:61364762ee0e | 6 | { |
| jmarkel44 | 0:61364762ee0e | 7 | if( !(RegisterValueMap.count(io_tag)) ) { |
| jmarkel44 | 0:61364762ee0e | 8 | printf("%s:%d: Key=%s not in Modbus Map\r\n", __func__, __LINE__, io_tag.c_str() ); |
| jmarkel44 | 0:61364762ee0e | 9 | return false; |
| jmarkel44 | 0:61364762ee0e | 10 | } |
| jmarkel44 | 0:61364762ee0e | 11 | |
| jmarkel44 | 0:61364762ee0e | 12 | value->value = RegisterValueMap[io_tag].float_value; |
| jmarkel44 | 0:61364762ee0e | 13 | value->errflag = RegisterValueMap[io_tag].errflag; |
| jmarkel44 | 0:61364762ee0e | 14 | return true; |
| jmarkel44 | 0:61364762ee0e | 15 | } |
| jmarkel44 | 0:61364762ee0e | 16 | |
| jmarkel44 | 0:61364762ee0e | 17 | bool ModbusMasterWriteRegister( const std::string &io_tag, float value ) |
| jmarkel44 | 0:61364762ee0e | 18 | { |
| jmarkel44 | 0:61364762ee0e | 19 | if( !(RegisterValueMap.count(io_tag)) ) { |
| jmarkel44 | 0:61364762ee0e | 20 | printf("%s:%d: Key=%s not in Modbus Map\r\n", __func__, __LINE__, io_tag.c_str() ); |
| jmarkel44 | 0:61364762ee0e | 21 | return false; |
| jmarkel44 | 0:61364762ee0e | 22 | } |
| jmarkel44 | 0:61364762ee0e | 23 | |
| jmarkel44 | 0:61364762ee0e | 24 | logDebug("\r[DEBUG] writing tag %s\n", io_tag.c_str()); |
| jmarkel44 | 0:61364762ee0e | 25 | RegisterValueMap[io_tag].float_value = value; |
| jmarkel44 | 0:61364762ee0e | 26 | return true; |
| jmarkel44 | 0:61364762ee0e | 27 | } |
| jmarkel44 | 0:61364762ee0e | 28 | |
| jmarkel44 | 0:61364762ee0e | 29 | bool ScriptWriteRegister( const char *io_tag, double value ) |
| jmarkel44 | 0:61364762ee0e | 30 | { |
| jmarkel44 | 0:61364762ee0e | 31 | std::string ioString = io_tag; |
| jmarkel44 | 0:61364762ee0e | 32 | if( !(RegisterValueMap.count(ioString)) ) { |
| jmarkel44 | 0:61364762ee0e | 33 | printf("%s:%d: Key=%s not in Register Map\r\n", __func__, __LINE__, ioString.c_str() ); |
| jmarkel44 | 0:61364762ee0e | 34 | return false; |
| jmarkel44 | 0:61364762ee0e | 35 | } |
| jmarkel44 | 0:61364762ee0e | 36 | |
| jmarkel44 | 0:61364762ee0e | 37 | logDebug("\r[DEBUG] reading tag %s\n", io_tag); |
| jmarkel44 | 0:61364762ee0e | 38 | |
| jmarkel44 | 0:61364762ee0e | 39 | RegisterValueMap[ioString].float_value = value; |
| jmarkel44 | 0:61364762ee0e | 40 | return true; |
| jmarkel44 | 0:61364762ee0e | 41 | } |
| jmarkel44 | 0:61364762ee0e | 42 | |
| jmarkel44 | 0:61364762ee0e | 43 | double ScriptReadRegister( const char *io_tag ) |
| jmarkel44 | 0:61364762ee0e | 44 | { |
| jmarkel44 | 0:61364762ee0e | 45 | std::string ioString = io_tag; |
| jmarkel44 | 0:61364762ee0e | 46 | if( !(RegisterValueMap.count(ioString)) ) { |
| jmarkel44 | 0:61364762ee0e | 47 | printf("%s:%d: Key=%s not in Register Map\r\n", __func__, __LINE__, ioString.c_str() ); |
| jmarkel44 | 0:61364762ee0e | 48 | return -1; |
| jmarkel44 | 0:61364762ee0e | 49 | } |
| jmarkel44 | 0:61364762ee0e | 50 | |
| jmarkel44 | 0:61364762ee0e | 51 | return RegisterValueMap[ioString].float_value; |
| jmarkel44 | 0:61364762ee0e | 52 | } |