44 questions
0
votes
1
answer
132
views
Python serial send byte array with byte values
I would like to send such array for example via pyserial:
[49, 56, 48] or [82]
I tried such solution before sending:
print(list(str(180).encode()))
And it gives me array as I want. But when I tried ...
0
votes
1
answer
53
views
How can I manipulate the syntax of an AT command and assign a method value in Python?
print(bytes(npArray))
print(bytes(npArray).hex())
ser.write(b'AT+DTRX=0,2,16,00003f0101007a00\r')
response = ser.read(100)
print(response.decode())
I have the above snippet in Python, which delivers ...
-1
votes
1
answer
89
views
How to XOR Hex ByteArray Elements [closed]
I'm trying to XOR all the elements in a bytearray, and generate the resulting checksum value in Hex. Finally, l will append the result to form a new bytearray. Sorry, I'm rusty in python now.
XorMath =...
1
vote
0
answers
120
views
Clearing (zeroing) all bytes of a sensitive bytearray in memory
After reading the following answer, I want to make sure a bytearray with sensitive information (password) is correctly cleared in memory prior to garbage collection. I'm assuming garbage collection in ...
0
votes
1
answer
270
views
python slice assignment and memoryview of bytearray
Sorry if my English is bad, I speak Korean as mother tongue.
I was writing code that changes bytearray partially.
And what I was trying to is to give name for memoryview of some sections of bytearray, ...
0
votes
1
answer
676
views
Python Error TypeError: 'bytes' object cannot be interpreted as an integer when concatenating bytes
Here's my code:
with open("SomeFile", mode="rb") as file:
byte = file.read(1)
count = 0
previous = []
while byte != b"":
if len(previous) >= 2:...
0
votes
0
answers
112
views
Sharing Bytearray in multiprocessing
I have two functions.
One variable bytearray type - data.
First function – Reads a file and adds bytes to ‘data’, second takes and deletes these bytes from ‘data’. Those functions should work at the ...
0
votes
1
answer
103
views
Trouble decoding malformed bytes to integer
I have a simple python socket server receiving "command" code that is encoded in ASCII. Most bytes are decoded properly with utf-8 by doing data.decode("utf-8"), but for some of ...
1
vote
1
answer
20
views
Compare every 3rd value inside a python dictionary and slice them
I have the following python dictionary with bytearray as values
test_bytearray_dict=
{'test_array0': bytearray(b'0000000000000000'),
'test_array1': bytearray(b'0000000001000000'),
'test_array2': ...
1
vote
0
answers
85
views
Python decode bytearray
I need send some data over serialport, but I have problem with bytearray
I wrote simple script, like this:
msg = bytearray([255,1,134,0,0,0,0,121])
print(msg)
But output from this looks like this:
...
1
vote
1
answer
119
views
python string decode displayed as byte array in list context
Why is this string printing as a byte array in the context of a list, printing as expected in a print statement, and the type is of string, not bytearray?
stringList = []
# Comparing a string, and a ...
0
votes
1
answer
262
views
How to convert a cython char* filled with 0x00 to non-empty byte array
Here is a cython fonction:
cdef struct my_struct_t:
unsigned int a
short b
unsigned char[6] c
cdef void f_my_struct_t(int buff_size, const unsigned char* buf, list output):
cdef:
...
0
votes
0
answers
566
views
Expected type to be one of bytes, bytearray but got str in Python
I'm having the small Python problem. I'm not used to this Python coding so my mistake might be silly one. I'm trying to call API using the Python requests module.
Here I tried 2 methods but both ...
0
votes
0
answers
66
views
Unable to convert bytes to hex
I have a serial device (loadcell) connected to pc which is constantly sending data in a fixed format. It has 2 stop bits (0x40 and 0x0b). I am trying to read until 1 stop bit so I can start reading ...
2
votes
2
answers
5k
views
Numpy array: get the raw bytes without copying
I am trying to concatenate the bytes of multiple Numpy arrays into a single bytearray to send it in an HTTP post request.
The most efficient way of doing this, that I can think of, is to create a ...