3

I have been trying to make a communication with my industrial drive. All I want to do is read a few values of drive, like current, voltage etc. For that I am using a library:

I don't understand why it's happening. When the same code I have used before and the sketch was uploaded on the board, very well.

Here's the code from an example:

#include <SimpleModbusMaster.h>

// led to indicate that a communication error is present
#define connection_error_led 13

//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate

// If the packets internal retry register matches
// the set retry count then communication is stopped
// on that packet. To re-enable the packet you must
// set the "connection" variable to true.
#define retry_count 10 

// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 2 

// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
  PACKET2,
  // leave this last entry
  TOTAL_NO_OF_PACKETS
};

// Create an array of Packets for modbus_update()
Packet packets[TOTAL_NO_OF_PACKETS];

// Create a packetPointer to access each packet
// individually. This is not required you can access
// the array explicitly. E.g. packets[PACKET1].id = 2;
// This does become tedious though...
packetPointer packet1 = &packets[PACKET1];
packetPointer packet2 = &packets[PACKET2];

// The data from the PLC will be stored
// in the regs array
unsigned int regs[9];

void setup()
{
  // read 3 registers starting at address 0
  packet1->id = 2;
  packet1->function = READ_HOLDING_REGISTERS;
  packet1->address = 0;
  packet1->no_of_registers = 3;
  packet1->register_array = regs;

  // write the 9 registers to the PLC starting at address 3
  packet2->id = 2;
  packet2->function = PRESET_MULTIPLE_REGISTERS;
  packet2->address = 3;
  packet2->no_of_registers = 9;
  packet2->register_array = regs;

  // P.S. the register_array entries above can be different arrays

  // Initialize communication settings etc...
  modbus_configure(baud, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);

  pinMode(connection_error_led, OUTPUT);
}

void loop()
{
  unsigned int connection_status = modbus_update(packets);

  if (connection_status != TOTAL_NO_OF_PACKETS)
  {
    digitalWrite(connection_error_led, HIGH);
    // You could re-enable the connection by:
    //packets[connection_status].connection = true;
  }
  else
    digitalWrite(connection_error_led, LOW);

  // update the array with the counter data
  regs[3] = packet1->requests;
  regs[4] = packet1->successful_requests;
  regs[5] = packet1->total_errors;
  regs[6] = packet2->requests;
  regs[7] = packet2->successful_requests;
  regs[8] = packet2->total_errors; 
}

Also, here is the error I am receiving upon uploading the sketch

This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.
Arduino: 1.0.6 (Windows 7), Board: "Arduino Uno"
SimpleModbusMasterExample:110: error: 'packetPointer' does not name a type
SimpleModbusMasterExample:111: error: 'packetPointer' does not name a type
SimpleModbusMasterExample.ino: In function 'void setup()':
SimpleModbusMasterExample:120: error: 'packet1' was not declared in this scope
SimpleModbusMasterExample:127: error: 'packet2' was not declared in this scope
SimpleModbusMasterExample:136: error: invalid conversion from 'int' to 'HardwareSerial*'
SimpleModbusMasterExample:136: error: invalid conversion from 'Packet*' to 'unsigned char'
C:\Users\xyz\Documents\Arduino\libraries\SimpleModbusMasterV2rev2/SimpleModbusMaster.h:143: error: too few arguments to function 'void modbus_configure(HardwareSerial*, long int, unsigned char, long int, long int, unsigned char, unsigned char, Packet*, unsigned int, unsigned int*)'
SimpleModbusMasterExample:136: error: at this point in file
C:\Users\xyz\Documents\Arduino\libraries\SimpleModbusMasterV2rev2/SimpleModbusMaster.h: In function 'void loop()':
C:\Users\xyz\Documents\Arduino\libraries\SimpleModbusMasterV2rev2/SimpleModbusMaster.h:125: error: too many arguments to function 'void modbus_update()'
SimpleModbusMasterExample:143: error: at this point in file
SimpleModbusMasterExample:143: error: void value not ignored as it ought to be
SimpleModbusMasterExample:155: error: 'packet1' was not declared in this scope
SimpleModbusMasterExample:158: error: 'packet2' was not declared in this scope
  • 1
    I would guess that it's not your code that has changed but the library you are using. Are you sure you have the right version of the right library? – Majenko Jan 24 '16 at 11:31
1

The code you are using is the example provided with the SimpleModbusMaster library found on GitHub: https://github.com/angeloc/simplemodbusng

It appears that the SimpleModbusMaster library isn't installed. This can happen if you install a new version of the Arduino IDE.

To install this library:

  1. Go to the link above and download the zip of the code.
  2. Extract the contents and then copy the folder "SimpleModbusMaster".
  3. Paste the folder into the Arduino/libraries folder located on your computer. (On my computer it is: C:\Program Files (x86)\Arduino\libraries).
  4. Restart the Arduino IDE. You can go straight to the example code by selecting: File > Examples > SimpleModbusMaster > SimpleModbusMasterExample

This procedure compiled for me with no errors.

  • Was the answer helpful? If so, please accept it by clicking on the "tick" icon next to the answer, and also possibly upvote it. This indicates to other users that you found the answer useful, and it also stops Stack Exchange from periodically "bumping" your question in the hope of getting an accepted answer. Thanks for your understanding and cooperation! – sa_leinad Aug 19 '16 at 0:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.