MODBUS AND HMI COMMUNICATION HELP
hi,
i trying programind , trying communicate arduino , hmi screen (easy wiev)
when write scada 500 led pin 13 must blinking
#include <modbusmaster.h>
int led = 13;
modbusmaster node(2);
void setup()
{
node.begin(19200);
}
void loop()
{
static uint32_t i;
uint8_t j, result;
uint16_t data[6];
i++;
// set word 0 of tx buffer least-significant word of counter (bits 15..0)
node.settransmitbuffer(0, lowword(i));
// set word 1 of tx buffer most-significant word of counter (bits 31..16)
node.settransmitbuffer(1, highword(i));
// slave: write tx buffer (2) 16-bit registers starting @ register 0
result = node.writemultipleregisters(0, 2);
// slave: read (6) 16-bit registers starting @ register 2 rx buffer
result = node.readholdingregisters(2, 6);
// data if read successful
if (result == node.ku8mbsuccess)
{
(j = 0; j < 6; j++)
{
data[j] = node.getresponsebuffer(j);
}
}
if(word(2)==200)
{
digitalwrite(led, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(led, low); // turn led off making voltage low
delay(1000); // wait second
}
}
is correct 1 if not please tell me how possible
i trying programind , trying communicate arduino , hmi screen (easy wiev)
when write scada 500 led pin 13 must blinking
#include <modbusmaster.h>
int led = 13;
modbusmaster node(2);
void setup()
{
node.begin(19200);
}
void loop()
{
static uint32_t i;
uint8_t j, result;
uint16_t data[6];
i++;
// set word 0 of tx buffer least-significant word of counter (bits 15..0)
node.settransmitbuffer(0, lowword(i));
// set word 1 of tx buffer most-significant word of counter (bits 31..16)
node.settransmitbuffer(1, highword(i));
// slave: write tx buffer (2) 16-bit registers starting @ register 0
result = node.writemultipleregisters(0, 2);
// slave: read (6) 16-bit registers starting @ register 2 rx buffer
result = node.readholdingregisters(2, 6);
// data if read successful
if (result == node.ku8mbsuccess)
{
(j = 0; j < 6; j++)
{
data[j] = node.getresponsebuffer(j);
}
}
if(word(2)==200)
{
digitalwrite(led, high); // turn led on (high voltage level)
delay(1000); // wait second
digitalwrite(led, low); // turn led off making voltage low
delay(1000); // wait second
}
}
is correct 1 if not please tell me how possible
is modbus library using spi? seem recall does. if case, can't use pin 13 led, 1 of spi pins.
Arduino Forum > Using Arduino > Programming Questions > MODBUS AND HMI COMMUNICATION HELP
arduino
Comments
Post a Comment