Python Forum
Read Byte Array from Zigbee coordinator using python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read Byte Array from Zigbee coordinator using python
#1
Hey, to interface Zigbee coordinator with python, I have used the mentioned below program. I was able to read the Byte array
import serial
ser = serial.Serial('COM6',115200)
read_byte = ser.read()
while read_byte is not None:
    read_byte = ser.read()    
    print ('%x' % ord(read_byte))
Result in hexadecimal format:

7E 00 32 90 00 13 A2 00 41 91 25 D4 FF FE C2 7F 00 01 03 FF BC 00 08 00 01 52 55 00 BE 6B 01 89 DC 00 00 00 00 CB 4D 00 00 00 FE A4 04 00 00 00 FE 58 3E 00 1B 46
but when I am trying to read the data from the byte array then I am facing some problem using mentioned below code.

import time
import serial

# Change this serial port to the serial port you are using.
s = serial.Serial('COM6', 115200)

while True:
    packet_ready = s.read(1)
    if(ord(packet_ready) == 126):
        while s.inWaiting() < 28:
            time.sleep(.001)
        bytes_back = s.read(28)
        if(ord(bytes_back[15]) == 127):
            print('The packet has a data payload: ' + str(ord(bytes_back[15])))
            print('The packet is for sensor type: '+str(ord(bytes_back[22])))
Error:

Error:
Traceback (most recent call last): File "C:/Users/Misha/Desktop/test/Xbee Test/Test2.py", line 13, in <module> if(ord(bytes_back[15]) == 127): TypeError: ord() expected string of length 1, but int found
and I am not able to understand the error problem
please suggest the best way to make it work so that I'll be able to read data from Byte Array
Reply


Messages In This Thread
Read Byte Array from Zigbee coordinator using python - by jenkins43 - Mar-25-2019, 06:40 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 2,928 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 7,107 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 11,526 Sep-18-2020, 10:10 PM
Last Post: tienttt
  convert array of numbers to byte array adetheheat 3 2,797 Aug-13-2020, 05:09 PM
Last Post: bowlofred
  Convert even byte array to odd medatib531 1 2,206 Mar-17-2020, 02:48 AM
Last Post: scidam
  Python crypto byte plaintext to hexint Mangaz90 2 2,851 Feb-21-2020, 07:42 PM
Last Post: Mangaz90
  'utf-8' codec can't decode byte 0xda in position 184: invalid continuation byte karkas 8 31,657 Feb-08-2020, 06:58 PM
Last Post: karkas
  How to read a text file into a list or an array musouka 2 2,877 Oct-07-2019, 01:54 PM
Last Post: musouka
  Byte array is sorted when sending via USB daviddlc68 1 2,820 Aug-16-2019, 10:11 AM
Last Post: wavic
  Reading data from serial port as byte array vlad93 1 12,061 May-18-2019, 05:26 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020