News:

To visit MidNite Solar click this link www.midnitesolar.com

Main Menu

rs232 modbus to Classic

Started by dgd, February 05, 2015, 03:48:23 AM

Previous topic - Next topic

dgd

#15
Yes it compiles clean. You have installed the SimpleModbusMaster library? And you are using ide 1.5.8
When I upload executable to the uno I seperate it from other shields as it gets the not synced error because the USB port get confused with the rs232 port.

Dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

mtdoc

Well I did have a old version of the Arduino IDE so I upgraded to the newest version 1.6 but still no go.

Here is the error message:
Quote
Arduino: 1.6.0 (Windows 7), Board: "Arduino Uno"

Build options changed, rebuilding all

Using library LiquidCrystal in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal

Using library Simplemodbusmaster in folder: C:\Users\jmp\Documents\Arduino\libraries\Simplemodbusmaster (legacy)



C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10600 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\standard -IC:\Program Files (x86)\Arduino\libraries\LiquidCrystal\src -IC:\Users\jmp\Documents\Arduino\libraries\Simplemodbusmaster C:\Users\jmp\AppData\Local\Temp\build8728361313426657017.tmp\sketch_feb09a.cpp -o C:\Users\jmp\AppData\Local\Temp\build8728361313426657017.tmp\sketch_feb09a.cpp.o

sketch_feb09a.ino:126:1: error: 'packetPointer' does not name a type
sketch_feb09a.ino: In function 'void setup()':
sketch_feb09a.ino:173:20: error: 'packet1' was not declared in this scope
sketch_feb09a.ino:203:119: 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*)'
In file included from sketch_feb09a.ino:4:0:
C:\Users\jmp\Documents\Arduino\libraries\Simplemodbusmaster/SimpleModbusMaster.h:134:6: note: declared here
void modbus_configure(HardwareSerial* SerialPort,

      ^
sketch_feb09a.ino: In function 'void loop()':
sketch_feb09a.ino:332:6: error: expected '}' before 'else'
Error compiling.

Thanks again for the help.
Array 1: Sanyo HIT225 X 8 on Wattsun tracker. Array 2: Evergreen ES-E-225 X 12 on shed roof. Midnite e-panel with Outback GVFX3648, FNDC and Classic 150 X 2. 436 AH AGMs. Honda eu2000i X 2.

dgd

Mtdoc,

I don't understand how you are compiling the sketch.
On my Win8 laptop I have installed the Arduino ide window system (or whatever it is called) and I never see any c:\ prompt for compiling.
The packet and packetpointer data types are defined in SimpleModbusMaster.h
See the screenshot below.
I just pressed the verify key which compiles the sketch and the results are at bottom of the window

dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

mtdoc

I'm doing the same as you. The error text i posted is what shows up in the Arduino IDE lower message box after i push the verify button and it fails to compile. Perhaps it's an issue with the simplemodbuslibrary I'm using?  I'll look into it more tomorrow.
Array 1: Sanyo HIT225 X 8 on Wattsun tracker. Array 2: Evergreen ES-E-225 X 12 on shed roof. Midnite e-panel with Outback GVFX3648, FNDC and Classic 150 X 2. 436 AH AGMs. Honda eu2000i X 2.

dgd

#19
Ok, When you look at the examples directory do you see the simplemodbusmaster example?
I simply copied and modifies that example as a start to my sketch and that is where the packetpointer variables were created and defined

dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

mtdoc

Thanks for the quick reply! I'm not at my computer now (ipad). It's late here (yawn..) so i'll get back to you tomorrow once i have a chance to check some things.
Array 1: Sanyo HIT225 X 8 on Wattsun tracker. Array 2: Evergreen ES-E-225 X 12 on shed roof. Midnite e-panel with Outback GVFX3648, FNDC and Classic 150 X 2. 436 AH AGMs. Honda eu2000i X 2.

mtdoc

dgd,

I've looked in both the SimpleModbusMaster.h library file and also in the SimpleModbusMasterArduino example (which compiles fine).

I see some packet definitions but no packetpointer.

I'm using V2r2 of SimpleModbusMaster.h   Is that the same version you are using?
Array 1: Sanyo HIT225 X 8 on Wattsun tracker. Array 2: Evergreen ES-E-225 X 12 on shed roof. Midnite e-panel with Outback GVFX3648, FNDC and Classic 150 X 2. 436 AH AGMs. Honda eu2000i X 2.

dgd

My example sketch has packet pointer in it.
I'm not home right now so can't look at version, have a look for a later version

Dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

mtdoc

#23
dgd - have you had a chance to look at the version of SimpleModbusmaster library you're running?

Below is the code from the SimpleModbusMaster example which compiles fine for me. I don't see the "packetPointer" from line 126 of your code defined there or in the library. That is were the compiler seems to be first hanging up.

#include <SimpleModbusMaster.h>

/*
   The example will use packet1 to read a register from address 0 (the adc ch0 value)
   from the arduino slave (id=1). It will then use this value to adjust the brightness
   of an led on pin 9 using PWM.
   It will then use packet2 to write a register (its own adc ch0 value) to address 1
   on the arduino slave (id=1) adjusting the brightness of an led on pin 9 using PWM.
*/

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

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

#define LED 9

// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 1

// 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,
  TOTAL_NO_OF_PACKETS // leave this last entry
};

// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];

// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];

void setup()
{
  // Initialize each packet
  modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 0, 1, 0);
  modbus_construct(&packets[PACKET2], 1, PRESET_MULTIPLE_REGISTERS, 1, 1, 0);
 
  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial, baud, SERIAL_8N2, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
 
  pinMode(LED, OUTPUT);
}

void loop()
{
  modbus_update();
 
  regs[0] = analogRead(0); // update data to be written to arduino slave
 
  analogWrite(LED, regs[0]>>2); // constrain adc value from the arduino slave to 255
}
Array 1: Sanyo HIT225 X 8 on Wattsun tracker. Array 2: Evergreen ES-E-225 X 12 on shed roof. Midnite e-panel with Outback GVFX3648, FNDC and Classic 150 X 2. 436 AH AGMs. Honda eu2000i X 2.

dgd

The simple modbus master zip file I downloaded is called

SimpleModbusMasterV2rev2_DUE.zip

and is 20.4k in size

dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

mtdoc

Quote from: dgd on February 13, 2015, 10:38:01 PM
The simple modbus master zip file I downloaded is called

SimpleModbusMasterV2rev2_DUE.zip

and is 20.4k in size

dgd

Well, still not working.

I was using the non DUE version so I downloaded and tried the DUE version.

I downloaded both from the google drive files referenced from THIS google code site which is what comes up in a google search.

To use the DUE version I had to change the first line in your code from  #include <SimpleModbusMaster.h>  to # include SimpleModbusMaster_DUE.h  (for obvious reasons) - but still the same failure to compile with the same errors as I listed in my previous post.

I'm not sure what the issue is - there must be a difference between the code you have running and what I copied and pasted from your earlier posts here (which I've done over a few times just to be sure).

Is there any chance you can open your running Arduino sketch and copy and paste the code directly to a post here again?  Maybe the SimpleModbusMaster.h file as well?  There must be a difference in there someplace.

Had anyone else been able to get this to compile?

Thanks again dgd. It's awesone that you're working on and sharing this stuff.

BTW you can use the inert code function ( the button with the # sign on it brings it up) to put the code in a scrollable box like this
Array 1: Sanyo HIT225 X 8 on Wattsun tracker. Array 2: Evergreen ES-E-225 X 12 on shed roof. Midnite e-panel with Outback GVFX3648, FNDC and Classic 150 X 2. 436 AH AGMs. Honda eu2000i X 2.

dgd

#26
I am at a complete loss to understand what is happening with your attemps to compile this.
Forget my code and just load the example program supplied with the SimpleModbusMaster library
Does it compile cleanly?
Look in the example code and you should see a line that is

packetPointer  packet1 = &packets[PACKET1]

This means that a pointer called packet1 is pointing to the address of the PACKET1 element of the packets array and the pointer packet1 is of the type packetPointer.
packetPointer is a datatype that is part of the library file SimpleModbusMaster.h
if you do not have the above line in your example program then probably try v10 library.

If you cannot compile the example program they supply then there is a problem with your library (or environment or something else)

Also I did download v10 of the library but I downloaded the v22 shortly after. Maybe I actually have v10 so maybe you could try downloading that version too, if you cannot find the packetPointer data type defined in you .h file

Last, if you look in the arduino forum you will find lots of stuff about SimpleModbusMaster and Slave and I see the packetpointer line in all the examples they quote.

Do you get the same error when trying to compile my SImple webserver code?

dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand

mtdoc

#27
Quote from: dgd on February 14, 2015, 01:16:43 AM
I am at a complete loss to understand what is happening with your attemps to compile this.

Me too! :(

Quote
Forget my code and just load the example program supplied with the SimpleModbusMaster library
Does it compile cleanly?

Yes, it does

QuoteLook in the example code and you should see a line that is

packetPointer  packet1 = &packets[PACKET1]

No that line is not in the example code. What line are you seeing it?

Quote
This means that a pointer called packet1 is pointing to the address of the PACKET1 element of the packets array and the pointer packet1 is of the type packetPointer.
packetPointer is a datatype that is part of the library file SimpleModbusMaster.h
if you do not have the above line in your example program then probably try v10 library.

I just replied to your other thread about the same issue. The v22 SimpleModbusMaster.h library I have does not have a packetPointer definition in it.

I'll look at the  v10 library.

Array 1: Sanyo HIT225 X 8 on Wattsun tracker. Array 2: Evergreen ES-E-225 X 12 on shed roof. Midnite e-panel with Outback GVFX3648, FNDC and Classic 150 X 2. 436 AH AGMs. Honda eu2000i X 2.

mtdoc

Success!

That was the issue. The V22 library does not have that packetPointer definition but the V12 library does! (there was no V10 library that I could find on that google drive site).

I did have to add one } before else on line 326 of your original posted code - otherwise it compiled cleanly.

OK - now that it compiles I just need to make a cable and hook up some hardware!

Thanks again.
Array 1: Sanyo HIT225 X 8 on Wattsun tracker. Array 2: Evergreen ES-E-225 X 12 on shed roof. Midnite e-panel with Outback GVFX3648, FNDC and Classic 150 X 2. 436 AH AGMs. Honda eu2000i X 2.

dgd

thats good, look forward to seeing a pic of your lcd display  :)

dgd
Classic 250, 150,  20 140w, 6 250w PVs, 2Kw turbine, MN ac Clipper, Epanel/MNdc, Trace SW3024E (1997), Century 1050Ah 24V FLA (1999). Arduino power monitoring and web server.  Off grid since 4/2000
West Auckland, New Zealand