MODBUS

Foro para hablantes de español que deseen escribir en su lengua materna.

Moderator: Benj

Post Reply
MOCUELSL
Posts: 59
Joined: Fri Jun 01, 2018 12:52 pm
Has thanked: 8 times
Been thanked: 5 times
Contact:

MODBUS

Post by MOCUELSL »

BUENAS TARDES BENJ,

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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: MODBUS

Post 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

MOCUELSL
Posts: 59
Joined: Fri Jun 01, 2018 12:52 pm
Has thanked: 8 times
Been thanked: 5 times
Contact:

Re: MODBUS

Post 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

Post Reply