Skip to content

Instantly share code, notes, and snippets.

@jossef
Last active September 24, 2016 21:19
Show Gist options
  • Select an option

  • Save jossef/d0d94724f8138a30f17f to your computer and use it in GitHub Desktop.

Select an option

Save jossef/d0d94724f8138a30f17f to your computer and use it in GitHub Desktop.
arduino modbus function code 16
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0x4E, 0xFB, 0xDD, 0x13, 0x06, 0x28 };
IPAddress ip(10, 0, 0, 50);
byte server[] = { 10, 0, 0, 17 };
EthernetClient client;
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
client.connect(server, 502);
}
int i = 0;
void loop()
{
// Write tanks
byte writeModbus[17] = {0x00, 0x01, 0x00, 0x00, 0x00, 0x0b, 0x01, 0x10, 0x13, 0x8a, 0x00, 0x02, 0x04, 0x00, i++ % 100, 0x00, 0x38};
client.write(writeModbus, 17);
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment