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.
Dependencies: mbed
Fork of 2-ComfileHMI_Modbus by
SimpleModbus.h@2:f0fc57045b3d, 2016-09-09 (annotated)
- Committer:
- hyx2001
- Date:
- Fri Sep 09 04:07:37 2016 +0000
- Revision:
- 2:f0fc57045b3d
Comfile_HMI_Modbus
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
hyx2001 | 2:f0fc57045b3d | 1 | #ifndef __SimpleModbus.H__ |
hyx2001 | 2:f0fc57045b3d | 2 | #define __SimpleModbus.H__ |
hyx2001 | 2:f0fc57045b3d | 3 | |
hyx2001 | 2:f0fc57045b3d | 4 | #include "mbed.h" |
hyx2001 | 2:f0fc57045b3d | 5 | |
hyx2001 | 2:f0fc57045b3d | 6 | typedef uint8_t u8; |
hyx2001 | 2:f0fc57045b3d | 7 | typedef uint16_t u16; |
hyx2001 | 2:f0fc57045b3d | 8 | |
hyx2001 | 2:f0fc57045b3d | 9 | #define __ring_buffer_max 255 |
hyx2001 | 2:f0fc57045b3d | 10 | /******************************************************************************* |
hyx2001 | 2:f0fc57045b3d | 11 | ############################################################################### |
hyx2001 | 2:f0fc57045b3d | 12 | # Simple 모드버스 펑션 처리 # |
hyx2001 | 2:f0fc57045b3d | 13 | ############################################################################### |
hyx2001 | 2:f0fc57045b3d | 14 | *******************************************************************************/ |
hyx2001 | 2:f0fc57045b3d | 15 | |
hyx2001 | 2:f0fc57045b3d | 16 | void StartModbus(PinName tx, PinName rx, long baud,u8 addr ,u16 *Register, u8 *Coil ); |
hyx2001 | 2:f0fc57045b3d | 17 | |
hyx2001 | 2:f0fc57045b3d | 18 | class comfileHMI |
hyx2001 | 2:f0fc57045b3d | 19 | { |
hyx2001 | 2:f0fc57045b3d | 20 | public: |
hyx2001 | 2:f0fc57045b3d | 21 | //private: |
hyx2001 | 2:f0fc57045b3d | 22 | u8 __modbusComCh; |
hyx2001 | 2:f0fc57045b3d | 23 | u8 __modbusSlaveAdr; |
hyx2001 | 2:f0fc57045b3d | 24 | u16 * __modbusWordBuffer; |
hyx2001 | 2:f0fc57045b3d | 25 | u8 * __modbusBitBuffer; |
hyx2001 | 2:f0fc57045b3d | 26 | u8 __modbusBroadMode ; |
hyx2001 | 2:f0fc57045b3d | 27 | u8 __modbusFoundFrame ; |
hyx2001 | 2:f0fc57045b3d | 28 | u16 __modbusIntervalCounter; |
hyx2001 | 2:f0fc57045b3d | 29 | u8 uchCRCHi, uchCRCLo; |
hyx2001 | 2:f0fc57045b3d | 30 | u16 uINDEX; |
hyx2001 | 2:f0fc57045b3d | 31 | |
hyx2001 | 2:f0fc57045b3d | 32 | RawSerial* device; |
hyx2001 | 2:f0fc57045b3d | 33 | |
hyx2001 | 2:f0fc57045b3d | 34 | /******************************************************************************* |
hyx2001 | 2:f0fc57045b3d | 35 | Ring buffer Management |
hyx2001 | 2:f0fc57045b3d | 36 | *******************************************************************************/ |
hyx2001 | 2:f0fc57045b3d | 37 | |
hyx2001 | 2:f0fc57045b3d | 38 | u8 __ring_buffer[4][255]; |
hyx2001 | 2:f0fc57045b3d | 39 | u16 __save_pointer[4]; |
hyx2001 | 2:f0fc57045b3d | 40 | u16 __action_pointer[4]; |
hyx2001 | 2:f0fc57045b3d | 41 | u8 __modbusSwitch[4]; |
hyx2001 | 2:f0fc57045b3d | 42 | u16 __modbusBlankCheck; |
hyx2001 | 2:f0fc57045b3d | 43 | |
hyx2001 | 2:f0fc57045b3d | 44 | public: |
hyx2001 | 2:f0fc57045b3d | 45 | void Rx_interrupt(); |
hyx2001 | 2:f0fc57045b3d | 46 | void RunTime_HMI(); |
hyx2001 | 2:f0fc57045b3d | 47 | void init_comfileHMI(RawSerial* Serial, u8 addr, u16 *Register, u8 *Coil); |
hyx2001 | 2:f0fc57045b3d | 48 | void push_ringbuffer(u8 comch, u8 comdt); |
hyx2001 | 2:f0fc57045b3d | 49 | u8 read_ringbuffer(u8 comch); |
hyx2001 | 2:f0fc57045b3d | 50 | u16 comLen(u8 comch); |
hyx2001 | 2:f0fc57045b3d | 51 | short comGet(u8 comch); |
hyx2001 | 2:f0fc57045b3d | 52 | short comGets(u8 comch, u8 * dest, u16 length); |
hyx2001 | 2:f0fc57045b3d | 53 | void comPut(u8 comch, u8 cha); |
hyx2001 | 2:f0fc57045b3d | 54 | void comPuts(u8 comch, u8 * dest, u16 length); |
hyx2001 | 2:f0fc57045b3d | 55 | void comFlush(u8 comch); |
hyx2001 | 2:f0fc57045b3d | 56 | |
hyx2001 | 2:f0fc57045b3d | 57 | |
hyx2001 | 2:f0fc57045b3d | 58 | |
hyx2001 | 2:f0fc57045b3d | 59 | u8 mb_get_byte_rtu(); |
hyx2001 | 2:f0fc57045b3d | 60 | u16 mb_get_word_rtu(); |
hyx2001 | 2:f0fc57045b3d | 61 | void mb_inc_pointer(); |
hyx2001 | 2:f0fc57045b3d | 62 | void mb_put_byte_rtu(u8 dt); |
hyx2001 | 2:f0fc57045b3d | 63 | u8 mb_collectbits(u16 adr); |
hyx2001 | 2:f0fc57045b3d | 64 | void mbcmd_read_bit_rtu(u8 cmd); |
hyx2001 | 2:f0fc57045b3d | 65 | void mbcmd_write_bit_single_rtu(); |
hyx2001 | 2:f0fc57045b3d | 66 | void mbcmd_read_word_rtu(u8 cmd); |
hyx2001 | 2:f0fc57045b3d | 67 | void mbcmd_write_word_single_rtu(); |
hyx2001 | 2:f0fc57045b3d | 68 | void mb_writebits(u16 adr, u8 val, u8 ln); |
hyx2001 | 2:f0fc57045b3d | 69 | void mbcmd_write_bit_multiple_rtu(); |
hyx2001 | 2:f0fc57045b3d | 70 | void mbcmd_write_word_multiple_rtu(); |
hyx2001 | 2:f0fc57045b3d | 71 | void mb_crc_compute(u8 rch); |
hyx2001 | 2:f0fc57045b3d | 72 | u16 getCrc(u8 * targetArray, u16 datalength); |
hyx2001 | 2:f0fc57045b3d | 73 | void startSimpleModbus(u8 comch, u8 modslaveadr, u16 * modbusBufferRegister, u8 * modbusBufferCoil); |
hyx2001 | 2:f0fc57045b3d | 74 | void modbusFrameSearch(u8 comch); |
hyx2001 | 2:f0fc57045b3d | 75 | void modbusMainProcessing(); |
hyx2001 | 2:f0fc57045b3d | 76 | }; |
hyx2001 | 2:f0fc57045b3d | 77 | #endif /*__SimpleModbus.H__*/ |