yozik04 / nextion

Nextion serial client
GNU Lesser General Public License v3.0
25 stars 10 forks source link

setting numeric values in Nextion with .set #16

Closed oldtimerflyer closed 3 years ago

oldtimerflyer commented 3 years ago

When setting values to xx.val objects in Nextion an error " 1C" occurs.

In .set routine in client.py the value is converted to a string format. Could it be that .val objects in Nextion need a number format ?

And how do i change it in the class client.py in my program then?

async def set(self, key, value, timeout=IO_TIMEOUT): if isinstance(value, str): out_value = '"%s"' % value elif isinstance(value, float): logger.warning("Float is not supported. Converting to string") out_value = '"%s"' % str(value) elif isinstance(value, int): out_value = str(value)

yozik04 commented 3 years ago

Example code please.

yozik04 commented 3 years ago

Check Instruction set documentation as well. https://nextion.tech/instruction-set/

oldtimerflyer commented 3 years ago

example code :+1: async def run(): global client client = Nextion('/dev/ttyAMA0', 9600, event_handler) await client.connect()

client.connect()

#await client.sleep()
#await client.wakeup()
#await client.command('sendxy=0')
#print(await client.get('sleep'))
temp = await client.get('Slider.val')
print ('slider = %d' % temp) #
name = 'Hoogte'
await client.set('t0.txt', "%s" % name)
await client.set('ALT100.val', "%d" % 4)                    <----------- generates 2020-11-22 15:44:17,556 - DEBUG - received: b'1c'
print('finished')
yozik04 commented 3 years ago

And why not?

await client.set('ALT100.val', 4)
oldtimerflyer commented 3 years ago

hmmmmm..... thanks. I have a lot to learn. But i will get there step by step.

oldtimerflyer commented 3 years ago

Get the same " 1c" error if put it in like this. temp is an int.

await client.set('ALT100.val', (temp / 10))

oldtimerflyer commented 3 years ago

await client.set('ALT100.val', int(temp / 10))

did the trick.

yozik04 commented 3 years ago

because temp was actually not an int =)

oldtimerflyer commented 3 years ago

temp = await client.get('Slider.val')

it should be an int but not sure

yozik04 commented 3 years ago

put a breakpoint and check =)