655 |
655 |
656 |
656 |
657 |
657 |
658 |
658 |
659 /* FUNCTION 0x03 - Read Holding Registers */ |
659 /* FUNCTION 0x03 - Read Holding Registers */ |
660 inline int read_output_words(u8 slave, |
660 int read_output_words(u8 slave, |
|
661 u16 start_addr, |
|
662 u16 count, |
|
663 u16 *dest, |
|
664 int dest_size, |
|
665 int ttyfd, |
|
666 int send_retries, |
|
667 u8 *error_code, |
|
668 const struct timespec *response_timeout, |
|
669 pthread_mutex_t *data_access_mutex) { |
|
670 if( count > MAX_READ_REGS ) { |
|
671 count = MAX_READ_REGS; |
|
672 #ifdef DEBUG |
|
673 fprintf( stderr, "Too many registers requested.\n" ); |
|
674 #endif |
|
675 } |
|
676 |
|
677 return read_registers(0x03 /* function */, |
|
678 slave, start_addr, count, dest, dest_size, ttyfd, |
|
679 send_retries, error_code, response_timeout, data_access_mutex); |
|
680 } |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 /* FUNCTION 0x03 - Read Holding Registers |
|
686 * u16 registers are stored in array of u32, two registers per u32. |
|
687 * Unused bits of last u32 element are set to 0. |
|
688 */ |
|
689 int read_output_words_u32(u8 slave, |
|
690 u16 start_addr, |
|
691 u16 count, |
|
692 u32 *dest, |
|
693 int ttyfd, |
|
694 int send_retries, |
|
695 u8 *error_code, |
|
696 const struct timespec *response_timeout) { |
|
697 if( count > MAX_READ_REGS ) { |
|
698 count = MAX_READ_REGS; |
|
699 #ifdef DEBUG |
|
700 fprintf( stderr, "Too many registers requested.\n" ); |
|
701 #endif |
|
702 } |
|
703 |
|
704 return read_registers_u32(0x03 /* function */, |
|
705 slave, start_addr, count, dest, ttyfd, |
|
706 send_retries, error_code, response_timeout); |
|
707 } |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 /* FUNCTION 0x03 - Read Holding Registers |
|
713 * return the array with the data to the calling function |
|
714 */ |
|
715 int read_output_words_u16_ref(u8 slave, |
|
716 u16 start_addr, |
|
717 u16 count, |
|
718 u16 **dest, |
|
719 int ttyfd, |
|
720 int send_retries, |
|
721 u8 *error_code, |
|
722 const struct timespec *response_timeout) { |
|
723 if( count > MAX_READ_REGS ) { |
|
724 count = MAX_READ_REGS; |
|
725 #ifdef DEBUG |
|
726 fprintf( stderr, "Too many registers requested.\n" ); |
|
727 #endif |
|
728 } |
|
729 |
|
730 return read_registers_u16_ref(0x03 /* function */, |
|
731 slave, start_addr, count, dest, ttyfd, send_retries, |
|
732 error_code, response_timeout); |
|
733 } |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 /* FUNCTION 0x04 - Read Input Registers */ |
|
739 int read_input_words(u8 slave, |
|
740 u16 start_addr, |
|
741 u16 count, |
|
742 u16 *dest, |
|
743 int dest_size, |
|
744 int ttyfd, |
|
745 int send_retries, |
|
746 u8 *error_code, |
|
747 const struct timespec *response_timeout, |
|
748 pthread_mutex_t *data_access_mutex) { |
|
749 if( count > MAX_READ_REGS ) { |
|
750 count = MAX_READ_REGS; |
|
751 #ifdef DEBUG |
|
752 fprintf( stderr, "Too many input registers requested.\n" ); |
|
753 #endif |
|
754 } |
|
755 |
|
756 return read_registers(0x04 /* function */, |
|
757 slave, start_addr, count, dest, dest_size, ttyfd, send_retries, |
|
758 error_code, response_timeout, data_access_mutex); |
|
759 } |
|
760 |
|
761 |
|
762 /* FUNCTION 0x04 - Read Input Registers |
|
763 * u16 registers are stored in array of u32, two registers per u32. |
|
764 * Unused bits of last u32 element are set to 0. |
|
765 */ |
|
766 int read_input_words_u32(u8 slave, |
|
767 u16 start_addr, |
|
768 u16 count, |
|
769 u32 *dest, |
|
770 int ttyfd, |
|
771 int send_retries, |
|
772 u8 *error_code, |
|
773 const struct timespec *response_timeout) { |
|
774 if( count > MAX_READ_REGS ) { |
|
775 count = MAX_READ_REGS; |
|
776 #ifdef DEBUG |
|
777 fprintf( stderr, "Too many input registers requested.\n" ); |
|
778 #endif |
|
779 } |
|
780 |
|
781 return read_registers_u32(0x04 /* function */, |
|
782 slave, start_addr, count, dest, ttyfd, send_retries, |
|
783 error_code, response_timeout); |
|
784 } |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 /* FUNCTION 0x04 - Read Input Registers |
|
790 * return the array with the data to the calling function |
|
791 */ |
|
792 int read_input_words_u16_ref(u8 slave, |
661 u16 start_addr, |
793 u16 start_addr, |
662 u16 count, |
794 u16 count, |
663 u16 *dest, |
795 u16 **dest, |
664 int dest_size, |
|
665 int ttyfd, |
796 int ttyfd, |
666 int send_retries, |
797 int send_retries, |
667 u8 *error_code, |
798 u8 *error_code, |
668 const struct timespec *response_timeout, |
799 const struct timespec *response_timeout) { |
669 pthread_mutex_t *data_access_mutex) { |
|
670 if( count > MAX_READ_REGS ) { |
|
671 count = MAX_READ_REGS; |
|
672 #ifdef DEBUG |
|
673 fprintf( stderr, "Too many registers requested.\n" ); |
|
674 #endif |
|
675 } |
|
676 |
|
677 return read_registers(0x03 /* function */, |
|
678 slave, start_addr, count, dest, dest_size, ttyfd, |
|
679 send_retries, error_code, response_timeout, data_access_mutex); |
|
680 } |
|
681 |
|
682 |
|
683 |
|
684 |
|
685 /* FUNCTION 0x03 - Read Holding Registers |
|
686 * u16 registers are stored in array of u32, two registers per u32. |
|
687 * Unused bits of last u32 element are set to 0. |
|
688 */ |
|
689 inline int read_output_words_u32(u8 slave, |
|
690 u16 start_addr, |
|
691 u16 count, |
|
692 u32 *dest, |
|
693 int ttyfd, |
|
694 int send_retries, |
|
695 u8 *error_code, |
|
696 const struct timespec *response_timeout) { |
|
697 if( count > MAX_READ_REGS ) { |
|
698 count = MAX_READ_REGS; |
|
699 #ifdef DEBUG |
|
700 fprintf( stderr, "Too many registers requested.\n" ); |
|
701 #endif |
|
702 } |
|
703 |
|
704 return read_registers_u32(0x03 /* function */, |
|
705 slave, start_addr, count, dest, ttyfd, |
|
706 send_retries, error_code, response_timeout); |
|
707 } |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 /* FUNCTION 0x03 - Read Holding Registers |
|
713 * return the array with the data to the calling function |
|
714 */ |
|
715 inline int read_output_words_u16_ref(u8 slave, |
|
716 u16 start_addr, |
|
717 u16 count, |
|
718 u16 **dest, |
|
719 int ttyfd, |
|
720 int send_retries, |
|
721 u8 *error_code, |
|
722 const struct timespec *response_timeout) { |
|
723 if( count > MAX_READ_REGS ) { |
|
724 count = MAX_READ_REGS; |
|
725 #ifdef DEBUG |
|
726 fprintf( stderr, "Too many registers requested.\n" ); |
|
727 #endif |
|
728 } |
|
729 |
|
730 return read_registers_u16_ref(0x03 /* function */, |
|
731 slave, start_addr, count, dest, ttyfd, send_retries, |
|
732 error_code, response_timeout); |
|
733 } |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 /* FUNCTION 0x04 - Read Input Registers */ |
|
739 inline int read_input_words(u8 slave, |
|
740 u16 start_addr, |
|
741 u16 count, |
|
742 u16 *dest, |
|
743 int dest_size, |
|
744 int ttyfd, |
|
745 int send_retries, |
|
746 u8 *error_code, |
|
747 const struct timespec *response_timeout, |
|
748 pthread_mutex_t *data_access_mutex) { |
|
749 if( count > MAX_READ_REGS ) { |
|
750 count = MAX_READ_REGS; |
|
751 #ifdef DEBUG |
|
752 fprintf( stderr, "Too many input registers requested.\n" ); |
|
753 #endif |
|
754 } |
|
755 |
|
756 return read_registers(0x04 /* function */, |
|
757 slave, start_addr, count, dest, dest_size, ttyfd, send_retries, |
|
758 error_code, response_timeout, data_access_mutex); |
|
759 } |
|
760 |
|
761 |
|
762 /* FUNCTION 0x04 - Read Input Registers |
|
763 * u16 registers are stored in array of u32, two registers per u32. |
|
764 * Unused bits of last u32 element are set to 0. |
|
765 */ |
|
766 inline int read_input_words_u32(u8 slave, |
|
767 u16 start_addr, |
|
768 u16 count, |
|
769 u32 *dest, |
|
770 int ttyfd, |
|
771 int send_retries, |
|
772 u8 *error_code, |
|
773 const struct timespec *response_timeout) { |
|
774 if( count > MAX_READ_REGS ) { |
|
775 count = MAX_READ_REGS; |
|
776 #ifdef DEBUG |
|
777 fprintf( stderr, "Too many input registers requested.\n" ); |
|
778 #endif |
|
779 } |
|
780 |
|
781 return read_registers_u32(0x04 /* function */, |
|
782 slave, start_addr, count, dest, ttyfd, send_retries, |
|
783 error_code, response_timeout); |
|
784 } |
|
785 |
|
786 |
|
787 |
|
788 |
|
789 /* FUNCTION 0x04 - Read Input Registers |
|
790 * return the array with the data to the calling function |
|
791 */ |
|
792 inline int read_input_words_u16_ref(u8 slave, |
|
793 u16 start_addr, |
|
794 u16 count, |
|
795 u16 **dest, |
|
796 int ttyfd, |
|
797 int send_retries, |
|
798 u8 *error_code, |
|
799 const struct timespec *response_timeout) { |
|
800 if( count > MAX_READ_REGS ) { |
800 if( count > MAX_READ_REGS ) { |
801 count = MAX_READ_REGS; |
801 count = MAX_READ_REGS; |
802 #ifdef DEBUG |
802 #ifdef DEBUG |
803 fprintf( stderr, "Too many input registers requested.\n" ); |
803 fprintf( stderr, "Too many input registers requested.\n" ); |
804 #endif |
804 #endif |