salve a tutti vi chiedo aiuto dato che sto' sbattendo la testa e mi sono arenato per far comunicare un semplice energy miter e un arduino
allora l'energy miter utilizza per comunicare il protocollo modbus 485 rtu,
utilizzando il programma modpoll riesco a leggere i parametri che mi interessano, uso questi parametri
modpoll -1 -f -b9600 -s1 -p none -m rtu -a 5 -c2 -r 20 COM13
utilizzo un semplice adattatore usb-485 cinese da 6 euro e tutto è ok, ho acquistato uno shield per arduino
http://www.ebay.it/itm/Shield-Arduino-RS485-Interface-/261261382544?pt=Attrezzature_e_strumentazione&hash=item3cd4645390
ora faccio questo scretck per arduino
#include <SimpleModbusMaster.h>
#include <LiquidCrystal.h>
//////////////////// 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 3
enum
{
PACKET1,
//PACKET2, // non voglio scrivere ma leggere i dati dal energy miter
TOTAL_NO_OF_PACKETS // leave this last entry
};
// Create an array of Packets to be configured
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];
// Data read from the arduino slave will be stored in this array
// if the array is initialized to the packet.
unsigned int readRegs[2];
LiquidCrystal lcd(12, 11, 9, 8, 7, 6); // PER LCD
void setup()
{
// da manuale mi interessa leggere solo da l'indirizzo 20 per 2 word
// nb 2 sono le word
modbus_construct(packet1, 1, READ_HOLDING_REGISTERS, 20, 2, readRegs);
// write 1 register starting at address 1
// modbus_construct(packet2, 1, PRESET_MULTIPLE_REGISTERS, 1, 1, writeRegs);
// configurazione
modbus_configure(&Serial, baud, SERIAL_8N1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS);
pinMode(LED, OUTPUT);
}
void loop()
{
//devo leggere solo i dati dal energy miter
modbus_update();
ld.print("requests:");
lcd.print(packet1->requests);
lcd.print("successful_requests: ");
lcd.print(packet1->successful_requests);
lcd.print("failed_requests: ");
lcd.print(packet1->failed_requests);
lcd.print("R1:");
lcd.print(readRegs[0]);
lcd.print("R2:");
lcd.print(readRegs[1]);
delay(2000);
}
collego tutto ma ho sempre errore e R1 e R2 mi danno come valore 0, mi potete aiutare?
grazie mille
J.