Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

# mbtcp.h

Go to the documentation of this file.

    00001 /*---------------------------------------------------------------------------*/
    00015 /*---------------------------------------------------------------------------*/
    00016
    00017 #ifndef MBTCP_H
    00018 #define MBTCP_H
    00019
    00020 #include "socket.h"
    00021 #include "modbus_defs.h"
    00022 #include "modbus_utils.h"
    00023
    00024 #define MAX_SERVER_SIZE                 256
    00025
    00026 typedef struct _MBAP_Struct {
    00027         u16     TransactionIdentifier;
    00028         u16     ProtocolIdentifier;
    00029         u16     Length;
    00030         u8      UnitIdentifier;
    00031 } MBAPStruct, *pMBAPStruct;
    00032
    00034 int     MBTCPServerInit( int port, int *serverfd);
    00035 int     MBTCPServerWaitConnection( const int serverfd, int *clientfd, char *client_addr);
    00036 int     MBTCPClientInit( int *clientfd);
    00037 int     MBTCPClientConnect( const int clientfd, const char *addr, int port);
    00038 int     MBTCPBlockRead(int fd, u8 *buf, int len);
    00039 int     MBTCPNonBlockRead(int fd, u8 *buf, int len);
    00040 int     MBTCPWrite(int fd, u8 *pdu, int len, pMBAPStruct mbap);
    00041 int     MBTCPServerClose(int fd);
    00042 int     MBTCPClientClose(int fd);
    00043 int     MBTCPSetTimeout(int fd, u32 timeout);
    00044 int     MBTCPGetTimeout(int fd, u32 *timeout);
    00045 int     MBTCPGetMBAP(u8 *adu, pMBAPStruct mbap);
    00046 int     MBTCPMakeMBAP( pMBAPStruct mbap, u16 tid, u16 len, u8 uid);
    00047 int     MBTCPWriteMBAP( char *buf, pMBAPStruct mbap);
    00048 int     MBTCPGetPDU(u8 *buf, u8 *adu, int len);
    00049 int     MBTCPSendAndWaitResponse(int fd, u8 *buf, u8 *pdu, int len, pMBAPStruct mbap);
    00050
    00052 int     MBTCPReadDecreteInputs(int fd, u16 startdec, u16 no, u8 *value, pMBAPStruct mbap);
    00053 int     MBTCPReadCoils(int fd, u16 startcoils, u16 no, u8 *value, pMBAPStruct mbap);
    00054 int     MBTCPWriteSingleCoil(int fd, u16 coilreg, u16 onoff, pMBAPStruct mbap);
    00055 int     MBTCPWriteMultipleCoils(int fd, u16 startcoils, u16 no, u8 *value, pMBAPStruct mbap);
    00056
    00057 int     MBTCPReadInputRegisters(int fd, u16 startreg, u16 no, u16 *value, pMBAPStruct mbap);
    00058 int     MBTCPReadHoldingRegisters(int fd, u16 startreg, u16 no, u16 *value, pMBAPStruct mbap);
    00059 int     MBTCPWriteSingleRegister(int fd, u16 devicereg, u16 value, pMBAPStruct mbap);
    00060 int     MBTCPWriteMultipleRegisters(int fd, u16 startdevreg, u16 noreg, u8 count, u16 *value, pMBAPStruct mbap);
    00061 int     MBTCPReadWriteMultipleRegisters(int fd, u16 rsreg, u16 rno, u16 *rv, u16 wsreg, u16 wno, u8 count, u16 *wv, pMBAPStruct mbap);
    00062 int     MBTCPMaskwWriteRegister(int fd, u16 reg, u16 andmask,u16 ormask, pMBAPStruct mbap);
    00063 int     MBTCPReadFIFOQueue(int fd, u16 FIFOAddr, u16 *FIFOCount, u16 *FIFOValue, pMBAPStruct mbap);
    00064
    00066 int     MBTCPSendReadDecreteInputs(int fd, u16 no, u8 *value, pMBAPStruct mbap);
    00067 int     MBTCPSendReadCoils(int fd, u16 no, u8 *value, pMBAPStruct mbap);
    00068 int     MBTCPSendReadInputRegisters(int fd, u16 no, u16 *value, pMBAPStruct mbap);
    00069 int     MBTCPSendReadHoldingRegisters(int fd, u16 no, u16 *value, pMBAPStruct mbap);
    00070 int     MBTCPSendWriteMultipleRegisters(int fd, u16 startdevreg, u16 noreg, u8 count, u16 *value, pMBAPStruct mbap);
    00071 int     MBTCPSendWriteSingleCoil(int fd, u16 coilreg, u16 onoff, pMBAPStruct mbap);
    00072 int     MBTCPSendWriteSingleRegister(int fd, u16 reg, u16 value, pMBAPStruct mbap);
    00073 int     MBTCPSendReadFIFOQueue(int fd, u16 no, u16 count, u16 *value, pMBAPStruct mbap);
    00074
    00075 #endif
    00076