-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from TG9541/C0135-FC03-FC04
fixes #25: mbread supports bitfield and register operations
- Loading branch information
Showing
6 changed files
with
108 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
\ Minimal MODBUS server with FC04 "Read Input Registers" handler | ||
\ Features: | ||
\ - prints debug infos to the console | ||
\ - interactive tests from the console, e.g. set inputs manually "7 inputs !" | ||
|
||
\ check if the MODBUS protocol core is already present | ||
\ hint: the development cycle will be faster if you PERSIST it | ||
#require MBPROTO | ||
|
||
\ Resetting the FC handler table can be helpful for development | ||
#require WIPE | ||
#require MBRESET | ||
MBRESET \ Reset the MODBUS Function Code table | ||
|
||
#require ALIAS | ||
#require :NVM | ||
#require 'IDLE | ||
#require .OK | ||
|
||
NVM | ||
|
||
#require MBDUMP | ||
#require BF! | ||
#require BF@ | ||
|
||
4 CONSTANT INPUTCELLS | ||
VARIABLE inputs INPUTCELLS 1- 2* ALLOT | ||
|
||
\ --- FC04 "Read Input Registers" | ||
|
||
\ FC04 input register iterated transfer | ||
:NVM ( i -- 1 ) | ||
DUP . | ||
2* inputs + @ tx+ | ||
;NVM ( xt ) | ||
|
||
\ FC04 handler | ||
:NVM ( -- ) | ||
\ write register address and value to the console | ||
." Read input registers: A:" mbp1 . ." Q:" mbp2 . CR | ||
|
||
[ ( xt xth ) SWAP ] LITERAL 16 ( xt bpu ) mbread | ||
;NVM ( xth ) 4 FC>XT ! | ||
|
||
|
||
\ custom default action handler | ||
: showfc ( -- ) | ||
rxbuf C@ ." FC:" . CR | ||
1 MBEC \ set error code | ||
; | ||
|
||
: init ( -- ) | ||
0 UARTISR \ init UART handler w/ default baud rate | ||
1 mbnode ! \ set node address | ||
[ ' showfc ] LITERAL mbdef ! \ FC default action (optional feature) | ||
[ ' MBDUMP ] LITERAL mbact ! \ show buffers (debug demo) | ||
[ ' MBPROTO ] LITERAL 'IDLE ! \ run MB protocol handler as idle task | ||
.OK | ||
; | ||
|
||
' init 'BOOT ! | ||
WIPE RAM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters