Page 1 of 1

MODBUS

Posted: Tue May 05, 2020 10:14 pm
by MOCUELSL
BUENAS TARDES BENJ,

ESTOY INTENTANDO CREAR UN ESCLAVO CON MODBUS, COMO PUEDO DEVOLVER DESDE ESTE ESCLAVO UN DATO STRING.

Re: MODBUS

Posted: Wed May 06, 2020 3:06 pm
by Benj
Hola,

Cadena a través de Modbus puede ser complicado. Básicamente, cada ubicación puede contener un valor de 16 bits. Las cadenas están formadas por caracteres de 8 bits, por lo que cada valor de 16 bits puede contener dos caracteres.

Comencemos con esto.

StrVal = "Hello"

Ok, empacaríamos los dos primeros caracteres en la primera ubicación.

Address0 = StrVal[0] + ( StrVal[1] << 8 )

La siguiente ubicación tendría los caracteres tercero y cuarto.

Address1 = StrVal[2] + ( StrVal[3] << 8 )

Y la ubicación final tendría los caracteres quinto y sexto. No hay sexto carácter, por lo que contendrá un byte nulo que significa el final de los datos de la cadena.

Address2 = StrVal[4] + ( StrVal[5] << 8 )

En el otro extremo, necesitaría construir la cadena hasta que llegue al byte nulo que significa el final de la cadena.

StrValIn[0] = Address0
StrValIn[1] = Address0 >> 8
StrValIn[2] = Address1
StrValIn[3] = Address1 >> 8
StrValIn[4] = Address2
StrValIn[5] = Address2 >> 8



Hello,

String via Modbus can be tricky. Basically each location can hold a 16-bit value. Strings are made up of 8-bit characters and so each 16-bit value can hold two characters.

Lets start with this.

StrVal = "Hello"

Ok we would pack the first two characters into the first location.

Address0 = StrVal[0] + ( StrVal[1] << 8 )

The next location would have the third and fourth characters.

Address1 = StrVal[2] + ( StrVal[3] << 8 )

And the final location would have the fifth and sixth characters. There is no sixth character so this will contain a null byte signifying the end of the string data.

Address2 = StrVal[4] + ( StrVal[5] << 8 )

At the other end you would need to build up the string until you hit the null byte signifying the end of the string.

StrValIn[0] = Address0
StrValIn[1] = Address0 >> 8
StrValIn[2] = Address1
StrValIn[3] = Address1 >> 8
StrValIn[4] = Address2
StrValIn[5] = Address2 >> 8

Re: MODBUS

Posted: Sat May 09, 2020 7:46 pm
by MOCUELSL
gracias Benj.

lo que he podido comprobar es que la regla 1 = 40002 no se cumple.
es un error o se ha cambiado los criterios.

un abrazo