portevent.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * FreeModbus Libary: Linux Port
  3. * Copyright (C) 2006 Christian Walter <wolti@sil.at>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. * File: $Id: portevent.c,v 1.1 2006/08/01 20:58:49 wolti Exp $
  20. */
  21. /* ----------------------- Modbus includes ----------------------------------*/
  22. #include "mb.h"
  23. #include "mbport.h"
  24. #include "mbctx.h"
  25. #include "mbtcp.h"
  26. /* ----------------------- Variables ----------------------------------------*/
  27. static eMBEventType eQueuedEvent;
  28. static BOOL xEventInQueue;
  29. /* ----------------------- Start implementation -----------------------------*/
  30. BOOL
  31. xMBPortEventInit( fmodbus_t* ctx )
  32. {
  33. ctx->xEventInQueue = FALSE;
  34. return TRUE;
  35. }
  36. BOOL
  37. xMBPortEventPost(fmodbus_t* ctx, eMBEventType eEvent )
  38. {
  39. ctx->xEventInQueue = TRUE;
  40. ctx->eQueuedEvent = eEvent;
  41. return TRUE;
  42. }
  43. BOOL
  44. xMBPortEventGet(fmodbus_t* ctx, eMBEventType * eEvent )
  45. {
  46. BOOL xEventHappened = FALSE;
  47. if( ctx->xEventInQueue )
  48. {
  49. *eEvent = ctx->eQueuedEvent;
  50. ctx->xEventInQueue = FALSE;
  51. xEventHappened = TRUE;
  52. }
  53. else
  54. {
  55. if( ctx->ucMBAddress == MB_TCP_PSEUDO_ADDRESS)
  56. {
  57. /* We can't do anything with errors from the pooling module. */
  58. ( void )xMBPortTCPPool( ctx );
  59. }
  60. else
  61. {
  62. /* Poll the serial device. The serial device timeouts if no
  63. * characters have been received within for t3.5 during an
  64. * active transmission or if nothing happens within a specified
  65. * amount of time. Both timeouts are configured from the timer
  66. * init functions.
  67. */
  68. ( void )xMBPortSerialPoll( ctx );
  69. /* Check if any of the timers have expired. */
  70. vMBPortTimerPoll( ctx );
  71. }
  72. }
  73. return xEventHappened;
  74. }