Revision 04b8cd51
Added ability to read input registers
main.c | ||
---|---|---|
5 | 5 |
#include "tooltron_mb.h" |
6 | 6 |
#include "rfid.h" |
7 | 7 |
|
8 |
eMBErrorCode eMBRegCoilsCB(UCHAR *reg_buf, USHORT addr, USHORT num,
|
|
8 |
eMBErrorCode eMBRegCoilsCB(UCHAR *reg_buf, USHORT addr, USHORT n_coils,
|
|
9 | 9 |
eMBRegisterMode mode) { |
10 |
// TODO implement coils |
|
10 | 11 |
if (mode == MB_REG_WRITE) { |
11 | 12 |
return MB_ENOREG; |
12 | 13 |
} else if (mode == MB_REG_READ) { |
... | ... | |
16 | 17 |
} |
17 | 18 |
} |
18 | 19 |
|
19 |
eMBErrorCode eMBRegDiscreteCB(UCHAR *reg_buf, USHORT addr, USHORT num) {
|
|
20 |
eMBErrorCode eMBRegDiscreteCB(UCHAR *reg_buf, USHORT addr, USHORT n_coils) {
|
|
20 | 21 |
return MB_ENOREG; |
21 | 22 |
} |
22 | 23 |
|
23 |
eMBErrorCode eMBRegInputCB(UCHAR *reg_buf, USHORT addr, USHORT num) { |
|
24 |
int i; |
|
24 |
eMBErrorCode eMBRegInputCB(UCHAR *reg_buf, USHORT addr, USHORT n_regs) { |
|
25 |
char serno[RFID_SERNO_SIZE]; |
|
26 |
|
|
27 |
rfid_get_serno(serno); |
|
28 |
|
|
25 | 29 |
switch (addr) { |
26 |
case 0: |
|
27 |
// TODO test whether the following works as expected (8 or 16 bit buf?) |
|
28 |
for (i = 0; i < 2*num; i++) { |
|
29 |
reg_buf[i] = i; |
|
30 |
|
|
31 |
case MB_INP_SERNOL: |
|
32 |
// TODO check that these (and the ones in SERNOH) are in the right order |
|
33 |
*reg_buf++ = serno[0]; |
|
34 |
*reg_buf++ = serno[1]; |
|
35 |
n_regs--; |
|
36 |
if (n_regs == 0) { |
|
37 |
return MB_ENOERR; |
|
38 |
} |
|
39 |
|
|
40 |
case MB_INP_SERNOH: |
|
41 |
*reg_buf++ = serno[2]; |
|
42 |
*reg_buf++ = serno[3]; |
|
43 |
n_regs--; |
|
44 |
if (n_regs == 0) { |
|
45 |
return MB_ENOERR; |
|
46 |
} |
|
47 |
|
|
48 |
case MB_INP_CURRENT: |
|
49 |
*reg_buf++ = 0; |
|
50 |
*reg_buf++ = 0; |
|
51 |
n_regs--; |
|
52 |
if (n_regs == 0) { |
|
53 |
return MB_ENOERR; |
|
30 | 54 |
} |
31 |
return MB_ENOERR; |
|
55 |
|
|
32 | 56 |
default: |
33 | 57 |
return MB_ENOREG; |
34 | 58 |
} |
35 | 59 |
} |
36 | 60 |
|
37 |
eMBErrorCode eMBRegHoldingCB(UCHAR *reg_buf, USHORT addr, USHORT num,
|
|
61 |
eMBErrorCode eMBRegHoldingCB(UCHAR *reg_buf, USHORT addr, USHORT n_regs,
|
|
38 | 62 |
eMBRegisterMode mode) { |
39 | 63 |
if (mode == MB_REG_WRITE) { |
40 | 64 |
return MB_ENOREG; |
Also available in: Unified diff