简体   繁体   中英

How to declare a variable of type “uint8_t”* in Python

What is the best way to declare a variable of type "uint8_t"* in Python?

uint8_t pipe_num;

line 182 of

https://github.com/maniacbug/RF24/blob/master/examples/starping/starping.pde

The ctypes library will help you to interface Python with C libraries, see ctypes library documentation . You probably want to use c_ubyte or c_ushort type.

It is not clear as to your goal. However, I guess you want Python to send a byte to the Arduino, perhaps over a serial port or such. Python does not have an equivalent type. Where the "write" method will send just the byte ,for the effect you are looking for.

import serial
arduino = serial.Serial(port,speed)
time.sleep(2) # may need 5s
byte = chr(0x31)
arduino.write(byte) # byte0<=i<=255
time.sleep(2)
arduino.close()

Note that you need to have brief pause after opening the port and before the byte is sent, as the Arduino is reseting.

You can also send sections of arrays or strings...

mystring = "1234"
ser.write(mystring[0:1])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM