source: trunk/Simulator/libmodbusWrapper.h @ 5

Last change on this file since 5 was 5, checked in by mansoux, 14 years ago

Ajout librairie Modbus base MacOSX

File size: 2.5 KB
Line 
1/*
2 *  libmodbusWrapper.h
3 *  ModBusKit
4 */
5//Created by Matthew Butch on 03/02/08.
6//  Copyright 2008 Volitans Software and R Engineering, Inc.
7/*
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version.
12 
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
21 
22 These library of functions are designed to enable a program send and
23 receive data from a device that communicates using the Modbus protocol.
24 */
25//
26//  This is an C++ wrapper for libmodbus
27#ifndef _LIBMODBUSWRAPPER_H_
28#define _LIBMODBUSWRAPPER_H_
29
30#include <string.h>
31#include <stdio.h>
32#include "modbus.h"
33using namespace std;
34
35enum {k_unknown=0, k_none, k_odd, k_even};
36enum {k_5=5, k_6, k_7, k_8};
37enum {k_1=1, k_2};
38
39class libmodbusWrapper
40{
41        modbus_param_t mb_param;
42        int errorCode;
43        bool debug;
44       
45        public:
46                bool lmbInitSerial(const char* device, int baud, int parity, int data_bit, int stop_bit);
47                bool lmbInitTCP(const char* device, int port);
48                int lmbConnect();
49                void lmbDisconnect();
50                bool lmbReadDiscreteInput(int slaveID, int startAddress, int inputCount, uint8_t *data);
51                bool lmbReadCoil(int slaveID, int startAddress, int coilCount, uint8_t *data);
52                bool lmbWriteSingleCoil(int slaveID, int coilAddress, bool state);
53                bool lmbWriteMultipleCoils(int slaveID, int startAddress, int coilCount, uint8_t *states);
54                bool lmbReadInputRegisters(int slaveID, int startAddress, int registerCount, uint16_t *data);
55                bool lmbReadHoldingRegisters(int slaveID, int startAddress, int registerCount, uint16_t *data);
56                bool lmbWriteSingleHoldingRegister(int slaveID, int registerAddress, uint16_t value);
57                bool lmbWriteMultipleHoldingRegisters(int slaveID, int startAddress, int registerCount, uint16_t *values);
58                int lmbErrorCode();
59                void lmbSetDebug(bool state);
60                void lmbSetRawDataSave(bool state);
61                int lmbLastRawQuery(uint8_t *rawQuery);
62                int lmbLastRawResponse(uint8_t *rawResponse);
63                int libmodbusWrapper::lmbLastRawQueryLength();
64                int libmodbusWrapper::lmbLastRawResponseLength();
65};
66
67#endif
Note: See TracBrowser for help on using the repository browser.