Comunicação Modbus entre Arduino e E3

Boa tarde pessoal

Gostaria de uma ajuda

Estou tentando comunicar o Arduino Leonardo com o Elipse E3, através de Modbus RTU, porem não estou tendo sucesso.

a principio é uma aplicação bem simples, apenas para trocar informações entre um led e botão com o E3, para depois realmente montar o projeto.

Já tentei umas 3 bibliotecas Modbus diferentes do Arduino mais ainda não consegui estabelecer a comunicação.
SimpleModbusSlaveV10
ModbusSlave
MODBUS

Uso o driver Modbus.dll no E3

Eu consigo descarregar programas normalmente pelo Arduino.
Uso um cabo USB / Micro USB entre o pc e o Arduino.

Deixo o E3 e o Arduino ma mesma COM e qnd abro a aplicação o E3, o led Rx do Arduino chega ficar piscando (pelo que percebi, de acordo do valor do TimeOut configurado do E3), porem o Tx não pisca, e os valores das tags do E3 ficam sempre nulos.

Quando uso o simulador Modbus Simulator Demo, e ajusto a configuração, porem através do Modbus TCP, eu consigo fazer a aplicação estabelecer a comunicação com o simulador e receber/enviar valores para as tags

Não sei se é o driver, a bliblioteca, o programa… pois ja tentei o que eu sabia

Se alguem puder me ajudar fico agradecido

o Log gerado pelo E3 é esse:

07/11/2020 13:08:52.718 (257C) DRIVER Driver name: Driver Modicon Modbus v4.0.4 (IOKitLib v2.0.117)
07/11/2020 13:08:52.718 (257C) DRIVER IOKitLib version 2.0.117 of Jun 22 2020 13:13:55
07/11/2020 13:08:52.718 (257C) DEBUG CModbusHost CREATED
07/11/2020 13:08:52.718 (257C) DRIVER Selected RTU mode!
07/11/2020 13:08:52.719 (257C) DRIVER User Types file compiled successfully!
07/11/2020 13:08:52.719 (257C) DRIVER drvStartComm(0,0,0,0)
07/11/2020 13:08:52.719 (257C) DRIVER Current configuration (78 parameters):
07/11/2020 13:08:52.719 (257C) DRIVER - IO.Ethernet.BackupIP = ‘’
07/11/2020 13:08:52.719 (257C) DRIVER - IO.Ethernet.BackupIP2 = ‘’
07/11/2020 13:08:52.719 (257C) DRIVER - IO.Ethernet.BackupIP3 = ‘’
07/11/2020 13:08:52.719 (257C) DRIVER - IO.Ethernet.IPFilter = ‘’
07/11/2020 13:08:52.719 (257C) DRIVER - IO.Ethernet.ListenIP = ‘’
07/11/2020 13:08:52.719 (257C) DRIVER - IO.Ethernet.MainIP = ‘127.0.0.1’
07/11/2020 13:08:52.719 (257C) DRIVER - IO.Ethernet.MainPort = 502
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Ethernet.PingTimeoutMs = 4000
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Ethernet.PingTries = 1
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Ethernet.Transport = ‘TCP’
07/11/2020 13:08:52.720 (257C) DRIVER - IO.GiveUpTries = 1
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Log.Enable = 1
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Log.Filename = ‘C:\eeLogs\Modbus_%DATE%.log’
07/11/2020 13:08:52.720 (257C) DRIVER - IO.RAS.ATCommand = ‘’
07/11/2020 13:08:52.720 (257C) DRIVER - IO.RecoverEnable = 1
07/11/2020 13:08:52.720 (257C) DRIVER - IO.RecoverPeriodSec = 20
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Serial.Baudrate = 9600
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Serial.DataBits = 8
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Serial.InterframeDelayMs = 200
07/11/2020 13:08:52.720 (257C) DRIVER - IO.Serial.Port = 43
07/11/2020 13:08:52.720 (257C) DRIVER - IO.TAPI.ModemID = 4294967295
07/11/2020 13:08:52.720 (257C) DRIVER - IO.TAPI.PhoneNumber = ‘’
07/11/2020 13:08:52.721 (257C) DRIVER - IO.TimeoutMs = 1000
07/11/2020 13:08:52.721 (257C) DRIVER - IO.Type = ‘Serial’
07/11/2020 13:08:52.721 (257C) DRIVER - ModiconModbus.ConfigFile = '[Functions]
Function: 1
Read: 3
Write: 16
Type: word
Size: 2
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 2
Read: 3
Write: 16
Type: dword
Size: 4
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 3
Read: 3
Write: 16
Type: int16
Size: 2
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 4
Read: 3
Write: 16
Type: int32
Size: 4
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 5
Read: 3
Write: 16
Type: float
Size: 4
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 6
Read: 1
Write: 15
Type: bit
Size: 0
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 7
Read: 2
Write: 0
Type: bit
Size: 0
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 8
Read: 1
Write: 5
Type: bit
Size: 0
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
[End]

07/11/2020 13:08:52.721 (257C) DRIVER - ModiconModbus.DefaultSlaveAddress = 1
07/11/2020 13:08:52.721 (257C) DRIVER - ModiconModbus.EnableGenSOERegGrouping = 1
07/11/2020 13:08:52.721 (257C) DRIVER - ModiconModbus.MaxPDUSize = 253
07/11/2020 13:08:52.721 (257C) DRIVER - ModiconModbus.Olderaddr = 1
07/11/2020 13:08:52.721 (257C) DRIVER - ModiconModbus.UserTypesConfigFile = '// USER DEFINED TYPES SAMPLE CONFIG FILE

// The samples below illustrate how to create user defined structs, using the driver built-in types (note the built-in
// types must be entered with the same keywords used in the Data combobox of the operations).
// The new user types can afterwards be used in the same way as the other built-in types in the Data combobox.

/* Sample types entirely commented by default

struct TYPE1 // TYPE 1 - declares struct with elements with no name, and no timestamp
{
int16;
word;
dword;
int32;
}

// TYPE2 declares named elements, and includes a timestamp of GenTime type. The named elements can then be
// loaded to the user application using E3 Tag Browser.

// NOTE: the timestamp value will not be returned on a block element, but rather returned on the timestamp property
// of the block type tag. The order in which the timestamp appears within the structure is related to the order
// in which this field appears within the data area of the received protocol frame (usually the first field).

struct TYPE2
{
timestamp = GenTime; // this time field will be returned in the block’s timestamp field
GenTime timeField; // this time field will be returned in the block’s first element
dword dwordField;
}

struct TYPE3 // this type has a timestamp of type UTC32 and some named elements
{
DefaultAddress = 0x101;
timestamp = UTC32;
float Va;
float Vb;
float Vc;
float Ia;
float Ib;
float Ic;
}

*/’
07/11/2020 13:08:52.721 (257C) DRIVER - ModiconModbus.WaitSilenceOnError = 1
07/11/2020 13:08:52.721 (257C) DRIVER - 47 parameters with value = 0 were omitted
07/11/2020 13:08:52.746 (11E4) IOKIT INITIALIZING…
07/11/2020 13:08:52.746 (11E4) IOKIT INITIALIZED!
07/11/2020 13:08:52.746 (11E4) IOKIT Request handler enabled
07/11/2020 13:08:52.747 (11E4) IOKIT CONNECTING…
07/11/2020 13:08:52.748 (11E4) SERIAL Opening COM43:9600,8,NONE,1 …
07/11/2020 13:08:52.784 (257C) TAG Tag(1.1.0.2).Validate = SUCCESS (type=10;flags=9)
07/11/2020 13:08:52.784 (257C) SUPERBLOCK Tag(1.1.0.2).Normalize = Linear(1:2) (x1,00000001)
07/11/2020 13:08:52.784 (257C) SUPERBLOCK Linear(1:2).Unnormalize = Tag(1.0.3.2.Blob:0034BF18)
07/11/2020 13:08:52.844 (11E4) SERIAL Port opened!
07/11/2020 13:08:52.844 (11E4) SERIAL Timeouts: Fixed=1000ms ByteMultiplier=2ms MaxInterval=0ms
07/11/2020 13:08:52.844 (11E4) IOKIT CONNECTED!
07/11/2020 13:08:52.849 (11E4) IO TX: 01 03 00 01 00 01 D5 CA
07/11/2020 13:08:53.851 (11E4) IO RX: TIMEOUT
07/11/2020 13:08:53.851 (257C) TAG <== (1.066) Tag(1.0.3.2.Blob:0034BF18[1]).ReadBlock = ERROR (hr=8004E000)
07/11/2020 13:08:53.851 (257C) TAG Tag(1.1.0.7).Validate = SUCCESS (type=10;flags=9)
07/11/2020 13:08:53.851 (257C) SUPERBLOCK Tag(1.1.0.7).Normalize = Linear(1:7) (x1,00000001)
07/11/2020 13:08:53.852 (11E4) IO TX: 01 03 00 01 00 06 94 08
07/11/2020 13:08:54.854 (11E4) IO RX: TIMEOUT
07/11/2020 13:08:54.854 (257C) TAG <== (1.003) Tag(1.0.3.2.Blob:0034BF18[6]).ReadBlock = ERROR (hr=8004E000)
07/11/2020 13:08:54.854 (11E4) IO TX: 01 03 00 01 00 06 94 08
07/11/2020 13:08:55.857 (11E4) IO RX: TIMEOUT
07/11/2020 13:08:55.857 (257C) TAG <== (1.003) Tag(1.0.3.2.Blob:0034BF18[6]).ReadBlock = ERROR (hr=8004E000)
07/11/2020 13:08:55.858 (11E4) IO TX: 01 03 00 01 00 06 94 08
07/11/2020 13:08:56.860 (11E4) IO RX: TIMEOUT
07/11/2020 13:08:56.860 (257C) TAG <== (1.003) Tag(1.0.3.2.Blob:0034BF18[6]).ReadBlock = ERROR (hr=8004E000)
07/11/2020 13:08:56.860 (11E4) IO TX: 01 03 00 01 00 06 94 08
07/11/2020 13:08:57.862 (11E4) IO RX: TIMEOUT
07/11/2020 13:08:57.862 (257C) TAG <== (1.002) Tag(1.0.3.2.Blob:0034BF18[6]).ReadBlock = ERROR (hr=8004E000)
07/11/2020 13:08:57.862 (11E4) IO TX: 01 03 00 01 00 06 94 08
07/11/2020 13:08:58.864 (11E4) IO RX: TIMEOUT
07/11/2020 13:08:58.864 (257C) TAG <== (1.002) Tag(1.0.3.2.Blob:0034BF18[6]).ReadBlock = ERROR (hr=8004E000)
07/11/2020 13:08:58.865 (11E4) IO TX: 01 03 00 01 00 06 94 08
07/11/2020 13:08:59.867 (11E4) IO RX: TIMEOUT
07/11/2020 13:08:59.867 (257C) TAG <== (1.003) Tag(1.0.3.2.Blob:0034BF18[6]).ReadBlock = ERROR (hr=8004E000)
07/11/2020 13:14:41.130 (257C) DRIVER drvStopComm(0,0,0,0)
07/11/2020 13:14:41.130 (257C) IOKIT Stopping physical layer thread…
07/11/2020 13:14:41.130 (257C) IOKIT Waiting for termination of physical layer thread…
07/11/2020 13:14:41.168 (11E4) SERIAL Port closed!
07/11/2020 13:14:41.170 (11E4) IOKIT Request handler disabled
07/11/2020 13:14:41.170 (11E4) IOKIT Request handler enabled
07/11/2020 13:14:41.170 (11E4) IOKIT TERMINATING…
07/11/2020 13:14:41.170 (11E4) IOKIT TERMINATED! (0 bytes sent, 0 bytes received)
07/11/2020 13:14:41.170 (11E4) IOKIT Request handler disabled
07/11/2020 13:14:41.170 (257C) IOKIT Physical layer thread stopped!
07/11/2020 13:14:41.170 (257C) DEBUG CModbusHost DELETED

Olá Paulo!

O driver está conseguindo estabelecer a conexão (através da porta COM43) porém as tentativas de leitura não estão obtendo resposta (TIMEOUT).

Experimenta desabilitar a propriedade EnableReadGrouping do objeto IODriver.

Boa noite Paulo

fiz a alteração que vc sugeriu, porém não funcionou ainda…

aparentemente manteve o mesmo log

11/11/2020 21:54:09.669 (1CDC) DRIVER Driver name: Driver Modicon Modbus v4.0.4 (IOKitLib v2.0.117)
11/11/2020 21:54:09.669 (1CDC) DRIVER IOKitLib version 2.0.117 of Jun 22 2020 13:13:55
11/11/2020 21:54:09.669 (1CDC) DEBUG CModbusHost CREATED
11/11/2020 21:54:09.669 (1CDC) DRIVER Selected RTU mode!
11/11/2020 21:54:09.669 (1CDC) DRIVER User Types file compiled successfully!
11/11/2020 21:54:09.669 (1CDC) DRIVER drvStartComm(0,0,0,0)
11/11/2020 21:54:09.669 (1CDC) DRIVER Current configuration (78 parameters):
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.BackupIP = ‘’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.BackupIP2 = ‘’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.BackupIP3 = ‘’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.IPFilter = ‘’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.ListenIP = ‘’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.MainIP = ‘127.0.0.1’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.MainPort = 502
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.PingTimeoutMs = 4000
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.PingTries = 1
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Ethernet.Transport = ‘TCP’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.GiveUpTries = 1
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Log.Enable = 1
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Log.Filename = ‘C:\eeLogs\Modbus_%DATE%.log’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.RAS.ATCommand = ‘’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.RecoverEnable = 1
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.RecoverPeriodSec = 20
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Serial.Baudrate = 9600
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Serial.DataBits = 8
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Serial.InterbyteDelayUs = 100
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Serial.Port = 43
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.TAPI.ModemID = 4294967295
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.TAPI.PhoneNumber = ‘’
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.TimeoutMs = 1000
11/11/2020 21:54:09.669 (1CDC) DRIVER - IO.Type = ‘Serial’
11/11/2020 21:54:09.669 (1CDC) DRIVER - ModiconModbus.ConfigFile = '[Functions]
Function: 1
Read: 3
Write: 16
Type: word
Size: 2
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 2
Read: 3
Write: 16
Type: dword
Size: 4
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 3
Read: 3
Write: 16
Type: int16
Size: 2
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 4
Read: 3
Write: 16
Type: int32
Size: 4
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 5
Read: 3
Write: 16
Type: float
Size: 4
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 6
Read: 1
Write: 15
Type: bit
Size: 0
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 7
Read: 2
Write: 0
Type: bit
Size: 0
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
Function: 8
Read: 1
Write: 5
Type: bit
Size: 0
FrameOrder: 0
ByteOrder: 0
WordOrder: 0
DWordOrder: 0
[End]

11/11/2020 21:54:09.669 (1CDC) DRIVER - ModiconModbus.DefaultSlaveAddress = 1
11/11/2020 21:54:09.669 (1CDC) DRIVER - ModiconModbus.EnableGenSOERegGrouping = 1
11/11/2020 21:54:09.669 (1CDC) DRIVER - ModiconModbus.MaxPDUSize = 253
11/11/2020 21:54:09.669 (1CDC) DRIVER - ModiconModbus.Olderaddr = 1
11/11/2020 21:54:09.669 (1CDC) DRIVER - ModiconModbus.UserTypesConfigFile = '// USER DEFINED TYPES SAMPLE CONFIG FILE

// The samples below illustrate how to create user defined structs, using the driver built-in types (note the built-in
// types must be entered with the same keywords used in the Data combobox of the operations).
// The new user types can afterwards be used in the same way as the other built-in types in the Data combobox.

/* Sample types entirely commented by default

struct TYPE1 // TYPE 1 - declares struct with elements with no name, and no timestamp
{
int16;
word;
dword;
int32;
}

// TYPE2 declares named elements, and includes a timestamp of GenTime type. The named elements can then be
// loaded to the user application using E3 Tag Browser.

// NOTE: the timestamp value will not be returned on a block element, but rather returned on the timestamp property
// of the block type tag. The order in which the timestamp appears within the structure is related to the order
// in which this field appears within the data area of the received protocol frame (usually the first field).

struct TYPE2
{
timestamp = GenTime; // this time field will be returned in the block’s timestamp field
GenTime timeField; // this time field will be returned in the block’s first element
dword dwordField;
}

struct TYPE3 // this type has a timestamp of type UTC32 and some named elements
{
DefaultAddress = 0x101;
timestamp = UTC32;
float Va;
float Vb;
float Vc;
float Ia;
float Ib;
float Ic;
}

*/’
11/11/2020 21:54:09.669 (1CDC) DRIVER - ModiconModbus.WaitSilenceOnError = 1
11/11/2020 21:54:09.669 (1CDC) DRIVER - 47 parameters with value = 0 were omitted
11/11/2020 21:54:09.685 (10D0) IOKIT INITIALIZING…
11/11/2020 21:54:09.685 (10D0) IOKIT INITIALIZED!
11/11/2020 21:54:09.685 (10D0) IOKIT Request handler enabled
11/11/2020 21:54:09.685 (10D0) IOKIT CONNECTING…
11/11/2020 21:54:09.685 (10D0) SERIAL Opening COM43:9600,8,NONE,1 …
11/11/2020 21:54:09.716 (1CDC) TAG Tag(1.1.0.2).Validate = SUCCESS (type=10;flags=9)
11/11/2020 21:54:09.716 (10D0) SERIAL Port opened!
11/11/2020 21:54:09.716 (10D0) SERIAL Timeouts: Fixed=1000ms ByteMultiplier=2ms MaxInterval=0ms
11/11/2020 21:54:09.716 (10D0) IOKIT CONNECTED!
11/11/2020 21:54:09.778 (10D0) IO TX: 01 03 00 01 00 01 D5 CA
11/11/2020 21:54:10.792 (10D0) IO RX: TIMEOUT
11/11/2020 21:54:10.792 (1CDC) TAG <== (1.067) Tag(1.1.0.2).ReadValue = ERROR (hr=8004E000)
11/11/2020 21:54:10.792 (1CDC) TAG Tag(1.1.0.7).Validate = SUCCESS (type=10;flags=9)
11/11/2020 21:54:10.839 (10D0) IO TX: 01 03 00 01 00 01 D5 CA
11/11/2020 21:54:11.853 (10D0) IO RX: TIMEOUT
11/11/2020 21:54:11.853 (1CDC) TAG <== (1.060) Tag(1.1.0.2).ReadValue = ERROR (hr=8004E000)
11/11/2020 21:54:11.900 (10D0) IO TX: 01 03 00 06 00 01 64 0B
11/11/2020 21:54:12.914 (10D0) IO RX: TIMEOUT
11/11/2020 21:54:12.914 (1CDC) TAG <== (1.061) Tag(1.1.0.7).ReadValue = ERROR (hr=8004E000)
11/11/2020 21:54:12.961 (10D0) IO TX: 01 03 00 01 00 01 D5 CA
11/11/2020 21:54:13.975 (10D0) IO RX: TIMEOUT
11/11/2020 21:54:13.975 (1CDC) TAG <== (1.061) Tag(1.1.0.2).ReadValue = ERROR (hr=8004E000)
11/11/2020 21:54:14.021 (10D0) IO TX: 01 03 00 06 00 01 64 0B
11/11/2020 21:54:15.037 (10D0) IO RX: TIMEOUT
11/11/2020 21:54:15.037 (1CDC) TAG <== (1.063) Tag(1.1.0.7).ReadValue = ERROR (hr=8004E000)

estou seguindo esse KB sobre comunicação com arduino

Paulo,

Continua dando timeout. Tem certeza que a configuração da porta e a parametrização dos Tags estão corretas?

Poderia testar com um tempo de timeout maior.

eu fiz o teste com 5000 de timout e continuou igual, inclusive o led RX do arduino piscou em sincronia com o tempo do timeout

Procurei seguir o KB que citei acima

Na aba Modbus selecionei RTU, default slave adress em 1, porta COM deixo igual entre o E3 e Arduino, baud rate 9600, valor de N2 de Operations ja testei com 03 e 16 word, 01 e 15 bit, 02 e None bit, 01 e 05 bit

N4 uso 7 para Input e 2 para output, enquanto no arduino ja usei o registrador regBank.add(10007), regBank.add(10006) e regBank.add(10008) para vincular com o input e regBank.add(2), regBank.add(1) e regBank.add(3) para output, similar ao programa sugerido no KB

Verifiquei a associação do value do objeto Display na tela do programa com a variável, assim como o script do botão para o output

Alguma outro ponto que devo checar?

Obrigado novamente

Paulo,

Você consegue comunicar com outro software?

No E3 parece que está tudo certo. Teria que checar o Arduino.