Ciao a tutti,
stò impazzendo con dei comandi da inviare via porta seriale ad una bilancia.

Giusto come esercizio triviale, devo collegarmi ad una bilancia prodotta
dall'azienda dove lavoro, con un protocollo binario proprietario in seriale.
Questo protocollo prevede l'invio di comandi in notazione esadecimale, di
seguito un esempio di comando per richiedere il peso lordo:
04 01 09 20 2E
di seguito riporto il codice che stò utilizzando:

#! /usr/bin/env python3
> import time
> import serial
>
> # configure the serial connections (the parameters differs on the device
> you are connecting to)
> ser = serial.Serial(
>     port='/dev/ttyUSB0',
>     baudrate=9600,
>     parity=serial.PARITY_ODD,
>     stopbits=serial.STOPBITS_ONE,
>     bytesize=serial.SEVENBITS
> )
>
> ser.close()
> ser.open()
> ser.isOpen()
>
> print('Request gross value:04 01 09 20 2E')
> while 1 :
>     # Python 3 users
>     input = bytes.fromhex('04 01 09 20 2E')
>
>     if input == 'exit':
>         ser.close()
>         exit()
>     else:
>         # send the character to the device
>         ser.write(input)
>         out = ''
>         # let's wait one second before reading output (let's give device
> time to answer)
>         time.sleep(1)
>
>         while ser.inWaiting() > 0:
>             out += ser.read(1)
>
>         if out != '':
>             print (out)
>         else:
>             print(input)
>

Con questo codice a terminale vedo sempre la stringa passata alla variabile
input perchè effettivamente la bilancia non mi risponde.
Sono convinto che i caratteri che gli mando non siano corretti nella
formattazione.

Qualcuno ha qualche suggerimento???


Grazie
-- 

---
We love BrigX
brigx.it


Gianfranco Genna
mail:        [email protected]
mobile:    +39 346.6124389
skype:      soldiesis7
_______________________________________________
BrigX Linux Users Group
[email protected]
http://brigx.it/mailman/listinfo/ml_brigx.it

Rispondere a