demo.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * File : demo.c
  3. * This file is part of freemodbus in RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-04-04 yi.qiu first version
  13. * 2010-04-07 LiJin
  14. */
  15. /* ----------------------- Platform includes --------------------------------*/
  16. #include <rtthread.h>
  17. #include "port.h"
  18. /* ----------------------- Modbus includes ----------------------------------*/
  19. #include "mb.h"
  20. #include "mbconfig.h"
  21. #include "mbframe.h"
  22. #include "mbproto.h"
  23. #include "mbfunc.h"
  24. #include "varible.h"
  25. void rt_modbus_thread_entry(void* parameter)
  26. {
  27. eMBErrorCode eStatus;
  28. USHORT buf[1];
  29. varible_group_t var_group;
  30. var_group = varible_group_get();
  31. eStatus = eMBInit( MB_RTU, 0x0A, 0, 115200, MB_PAR_EVEN );
  32. /* Enable the Modbus Protocol Stack. */
  33. eStatus = eMBEnable();
  34. rt_thread_delay(50);
  35. while(1)
  36. {
  37. int i = 0;
  38. var_group->table->hash_table[].
  39. if(eMBMReadCoils(0x01, 0x0, 0x6, buf) != MB_ETIMEDOUT)
  40. rt_thread_delay(100);
  41. }
  42. }
  43. int modbus_start(void)
  44. {
  45. rt_thread_t modbus_thread;
  46. modbus_thread = rt_thread_create("modbus",
  47. rt_modbus_thread_entry, RT_NULL,
  48. 2048, 20, 20);
  49. if (modbus_thread != RT_NULL)
  50. rt_thread_startup(modbus_thread);
  51. return 0;
  52. }
  53. eMBErrorCode eMBRegInputCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs )
  54. {
  55. return MB_ENOREG;
  56. }
  57. eMBErrorCode eMBRegHoldingCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNRegs,
  58. eMBRegisterMode eMode )
  59. {
  60. return MB_ENOREG;
  61. }
  62. eMBErrorCode eMBRegCoilsCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNCoils,
  63. eMBRegisterMode eMode )
  64. {
  65. return MB_ENOREG;
  66. }
  67. eMBErrorCode eMBRegDiscreteCB( UCHAR * pucRegBuffer, USHORT usAddress, USHORT usNDiscrete )
  68. {
  69. return MB_ENOREG;
  70. }