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

# mbserial.h

Go to the documentation of this file.

    00001 /*---------------------------------------------------------------------------*/
    00016 /*---------------------------------------------------------------------------*/
    00017
    00018 #ifndef MBSERIAL_H
    00019 #define MBSERIAL_H
    00020
    00021 #include "serial.h"
    00022 #include "modbus_defs.h"
    00023 #include "modbus_utils.h"
    00024
    00025 #define GETCLOCKMS(x) {                                 \
    00026                 struct timeval tv;                      \
    00027                 gettimeofday( &tv, NULL);               \
    00028                 x= tv.tv_usec>>10;                      \
    00029         }
    00030
    00031 #define GETCLOCKSECOND(x) {                             \
    00032                 x= time(NULL);                          \
    00033         }
    00034
    00035 struct MB_SERIAL_INFO
    00036 {
    00037         u8      Protocol;
    00038         u32     FrameTimeout;
    00039         u32     CharTimeout;
    00040         u32     Timeout;
    00041 };
    00042
    00044 void    MBSerialInit(void);
    00045 int     MBSerialOpen(int port, int protocol);
    00046 int     MBSerialBlockRead(int port, u8 *buf, int len);
    00047 int     MBSerialNonBlockRead(int port, u8 *buf, int len);
    00048 int     MBSerialWrite(int port, u8 *pdu, int len, u8 address);
    00049 int     MBSerialClose(int port);
    00050 int     MBSerialFlowCtrl(int port, int control);
    00051 int     MBSerialSendAndWaitResponse(int port, u8 *buf, u8 *pdu, int len, u8 address);
    00052
    00053 u32     MBSerialGetFrameTimeout(int port);
    00054 void    MBSerialSetFrameTimeout(int port, u32 timeout);
    00055 u32     MBSerialGetCharTimeout(int port);
    00056 void    MBSerialSetCharTimeout(int port, u32 timeout);
    00057 u32     MBSerialGetTimeout(int port);
    00058 void    MBSerialSetTimeout(int port, u32 timeout);
    00059
    00060 int     MBSerialReadRTU( int port, u8 *buf, int len);
    00061 int     MBSerialReadASCII( int port, u8 *buf, int len);
    00062
    00063 u8      MBSerialGetAddress( const u8 *adu);
    00064 int     MBSerialGetPDU( u8 *buf, u8 *adu, int len);
    00065
    00066 int     MBSerialSetMode( int port, unsigned int mode);
    00067 int     MBSerialSetSpeed( int port, unsigned int speed);
    00068 int     MBSerialSetParam( int port, int parity, int databits, int stopbit);
    00069
    00071 int     MBSerialReadDecreteInputs(int port,u8 address, u16 startdec, u16 no, u8 *value);
    00072 int     MBSerialReadCoils(int port, u8 address, u16 startcoils, u16 no, u8 *value);
    00073 int     MBSerialWriteSingleCoil(int port, u8 address, u16 coilreg, u16 onoff);
    00074 int     MBSerialWriteMultipleCoils(int port, u8 address, u16 startcoils, u16 no, u8 *value);
    00075
    00076 int     MBSerialReadInputRegisters(int port, u8 address, u16 startreg, u16 no, u16 *value);
    00077 int     MBSerialReadHoldingRegisters(int port, u8 address, u16 startreg, u16 no, u16 *value);
    00078 int     MBSerialWriteSingleRegister(int port, u8 address, u16 devicereg, u16 value);
    00079 int     MBSerialWriteMultipleRegisters(int port, u8 address, u16 startdevreg, u16 noreg, u8 count, u16 *value);
    00080 int     MBSerialReadWriteMultipleRegisters(int port, u8 address, u16 rsreg, u16 rno, u16 *rv, u16 wsreg, u16 wno, u8 count, u16 *wv);
    00081 int     MBSerialMaskWriteRegister(int port,u8 address, u16 reg, u16 andmask,u16 ormask);
    00082 int     MBSerialReadFIFOQueue(int port, u8 address, u16 FIFOAddr, u16 *FIFOCount, u16 *FIFOValue);
    00083
    00085 int     MBSerialReadExceptionStatus(int port, u8 address, u8 *status);
    00086 int     MBSerialDiagnostic(int port, u8 address, u16 subfunc, u16 data);
    00087 int     MBSerialGetCommEventCounter(int port, u8 address, u16 *status, u16 *eventcount);
    00088 int     MBSerialGetCommEventLog(int port, u8 address, u16 *status, u16 *eventcount, u16 *messagecount, u8 *events);
    00089 int     MBSerialReportSlaveID(int port, u8 address, u8 *slave_id, u8 *status);
    00090
    00092 int     MBSerialSendReadDecreteInputs(int port, u8 address, u16 no, u8 *value);
    00093 int     MBSerialSendReadCoils(int port, u8 address, u16 no, u8 *value);
    00094 int     MBSerialSendReadInputRegisters(int port, u8 address, u16 no, u16 *value);
    00095 int     MBSerialSendReadHoldingRegisters(int port, u8 address, u16 no, u16 *value);
    00096 int     MBSerialSendWriteMultipleRegisters(int port, u8 address, u16 startdevreg, u16 noreg);
    00097 int     MBSerialSendWriteSingleCoil(int port, u8 address, u16 coilreg, u16 onoff);
    00098 int     MBSerialSendWriteSingleRegister(int port, u8 address, u16 addr, u16 value);
    00099 int     MBSerialSendReadFIFOueue(int port, u8 address, u16 no, u16 count, u16 *value);
    00100 int     MBSerialSendReadExecptionStatus(int port, u8 address, u8 status);
    00101 int     MBSerialSendDiagnostic(int port, u8 address, u16 subfunc, u16 data);
    00102 int     MBSerialSendGetCommEventCounter(int port, u8 address, u16 status, u16 eventcount);
    00103 int     MBSerialSendGetCommEventLog(int port, u8 address, u8 no, u16 status, u16 eventcount, u16 messagecount, u8 *events);
    00104
    00105 #endif