Skip to content

Instantly share code, notes, and snippets.

@InfiniteCoder01
Last active October 3, 2024 14:22
Show Gist options
  • Save InfiniteCoder01/332426c37822f097e27e51f089b30c01 to your computer and use it in GitHub Desktop.
Save InfiniteCoder01/332426c37822f097e27e51f089b30c01 to your computer and use it in GitHub Desktop.
RoboIntellect python wrapper
from risdk import *
def main():
# Создание компонента i2c адаптера модели ch341
i2c = I2CAdapter("ch341")
# Создание компонента ШИМ модели pca9685
pwm = PWM("pca9685")
# Создание компонента сервопривода модели mg90s
servo = Servodrive("mg90s")
# Связывание i2c с ШИМ
pwm.link(i2c, 0x40)
# Связывание ШИМ с сервоприводом
servo.link(pwm, 0)
# Моментальный поворот сервопривода к значению угла, соответствующему 80 шагам
servo.turn_by_duty_cycle(80)
# Моментальный поворот сервопривода к значению угла, соответствующему 500 шагам
servo.turn_by_duty_cycle(500)
# Моментальный поворот сервопривода к значению угла, соответствующему 300 шагам
servo.turn_by_duty_cycle(300)
print("Success")
main()
from ctypes import *
import platform
# ------------------------------------- SDK library ------------------------------------ #
_platform = platform.system()
if _platform == "Windows":
_lib = "./librisdk.dll"
elif _platform == "Linux":
_lib = "./librisdk.so"
_lib = cdll.LoadLibrary(_lib)
# ----------------------------------- Argument types ----------------------------------- #
_lib.RI_SDK_InitSDK.argtypes = [c_int, c_char_p]
_lib.RI_SDK_Device_ModelList.argtypes = [c_char_p, c_char_p, c_char_p]
# Component
_lib.RI_SDK_CreateBasic.argtypes = [POINTER(c_int), c_char_p]
_lib.RI_SDK_CreateGroupComponent.argtypes = [
c_char_p, POINTER(c_int), c_char_p]
_lib.RI_SDK_CreateDeviceComponent.argtypes = [
c_char_p, c_char_p, POINTER(c_int), c_char_p]
_lib.RI_SDK_CreateModelComponent.argtypes = [
c_char_p, c_char_p, c_char_p, POINTER(c_int), c_char_p]
# Linking
_lib.RI_SDK_LinkPWMToController.argtypes = [c_int, c_int, c_uint8, c_char_p]
_lib.RI_SDK_LinkServodriveToController.argtypes = [
c_int, c_int, c_int, c_char_p]
_lib.RI_SDK_LinkRServodriveToController.argtypes = [
c_int, c_int, c_int, c_char_p]
_lib.RI_SDK_LinkLedToController.argtypes = [
c_int, c_int, c_int, c_int, c_int, c_char_p]
_lib.RI_SDK_LinkVoltageSensorToController.argtypes = [
c_int, c_int, c_uint8, c_char_p]
# Shutdown
_lib.RI_SDK_DestroySDK.argtypes = [c_bool, c_char_p]
_lib.RI_SDK_DestroyComponent.argtypes = [c_int, c_char_p]
# Connectors
_lib.RI_SDK_connector_i2c_SetBus.argtypes = [
c_int, c_int, POINTER(c_int), POINTER(c_int), c_char_p]
_lib.RI_SDK_connector_i2c_Open.argtypes = [c_int, c_uint8, c_char_p]
_lib.RI_SDK_connector_i2c_Close.argtypes = [c_int, c_uint8, c_char_p]
_lib.RI_SDK_connector_i2c_CloseAll.argtypes = [c_int, c_char_p]
_lib.RI_SDK_connector_i2c_State.argtypes = [c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_connector_i2c_ReadByte.argtypes = [
c_int, c_uint8, POINTER(c_ulonglong), c_char_p]
_lib.RI_SDK_connector_i2c_WriteByte.argtypes = [
c_int, c_uint8, c_ulonglong, c_char_p]
_lib.RI_SDK_connector_i2c_ReadBytes.argtypes = [
c_int, c_uint8, POINTER(c_ulonglong), c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_connector_i2c_WriteBytes.argtypes = [
c_int, c_uint8, POINTER(c_ulonglong), c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_sigmod_PWM_GetResolution.argtypes = [
c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_sigmod_PWM_GetFreq.argtypes = [c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_sigmod_PWM_SetFreq.argtypes = [c_int, c_int, c_char_p]
_lib.RI_SDK_sigmod_PWM_WriteRegBytes.argtypes = [
c_int, c_uint8, POINTER(c_ulonglong), c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_sigmod_PWM_ReadRegBytes.argtypes = [
c_int, c_uint8, POINTER(c_ulonglong), c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_sigmod_PWM_WriteByte.argtypes = [
c_int, c_uint8, POINTER(c_ulonglong), c_char_p]
_lib.RI_SDK_sigmod_PWM_GetPortFreq.argtypes = [
c_int, c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_sigmod_PWM_SetPortFreq.argtypes = [
c_int, c_int, c_int, c_char_p]
_lib.RI_SDK_sigmod_PWM_ResetPort.argtypes = [
c_int, c_int, c_char_p]
_lib.RI_SDK_sigmod_PWM_ResetAll.argtypes = [
c_int, c_char_p]
_lib.RI_SDK_sigmod_PWM_GetPortDutyCycle.argtypes = [
c_int, c_int, POINTER(c_int), POINTER(c_int), c_char_p]
_lib.RI_SDK_sigmod_PWM_SetPortDutyCycle.argtypes = [
c_int, c_int, c_int, c_int, c_char_p]
_lib.RI_SDK_sigmod_PWM_Close.argtypes = [c_int, c_char_p]
# Executors
_lib.RI_SDK_executor_State.argtypes = [c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_exec_ServoDrive_CustomDeviceInit.argtypes = [
c_int, c_int, c_int, c_int, c_int, c_char_p]
_lib.RI_SDK_exec_ServoDrive_TurnByDutyCycle.argtypes = [c_int, c_int, c_char_p]
_lib.RI_SDK_exec_ServoDrive_TurnByPulse.argtypes = [c_int, c_int, c_char_p]
_lib.RI_SDK_exec_ServoDrive_GetCurrentAngle.argtypes = [
c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_exec_ServoDrive_GetState.argtypes = [
c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_exec_ServoDrive_MinStepRotate.argtypes = [
c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_ServoDrive_Turn.argtypes = [
c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_ServoDrive_Rotate.argtypes = [
c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_ServoDrive_TurnWithRelativeSpeed.argtypes = [
c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_ServoDrive_RotateWithRelativeSpeed.argtypes = [
c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_ServoDrive_Stop.argtypes = [c_int, c_char_p]
_lib.RI_SDK_exec_ServoDrive_SetPositionToMidWorkingRange.argtypes = [
c_int, c_char_p]
_lib.RI_SDK_exec_RServoDrive_CustomDeviceInit.argtypes = [
c_int, c_int, c_int, c_int, c_int, c_char_p]
_lib.RI_SDK_exec_RServoDrive_GetState.argtypes = [
c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_exec_RServoDrive_RotateByPulse.argtypes = [
c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_RServoDrive_RotateByPulseOverTime.argtypes = [
c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_RServoDrive_RotateWithRelativeSpeed.argtypes = [
c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_RServoDrive_RotateWithRelativeSpeedOverTime.argtypes = [
c_int, c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_RServoDrive_Stop.argtypes = [c_int, c_char_p]
_lib.RI_SDK_exec_RGB_LED_SinglePulse.argtypes = [
c_int, c_int, c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_RGB_LED_FlashingWithFrequency.argtypes = [
c_int, c_int, c_int, c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_RGB_LED_FlashingWithPause.argtypes = [
c_int, c_int, c_int, c_int, c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_RGB_LED_Flicker.argtypes = [
c_int, c_int, c_int, c_int, c_int, c_int, c_bool, c_char_p]
_lib.RI_SDK_exec_RGB_LED_Stop.argtypes = [c_int, c_char_p]
_lib.RI_SDK_exec_RGB_LED_GetState.argtypes = [c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_exec_RGB_LED_GetColor.argtypes = [
c_int, POINTER(c_int), POINTER(c_int), POINTER(c_int), c_char_p]
# Sensors
_lib.RI_SDK_sensor_VoltageSensor_CustomDeviceInit.argtypes = [
c_int, c_float, c_float, c_float, c_char_p]
_lib.RI_SDK_sensor_VoltageSensor_Voltage.argtypes = [
c_int, POINTER(c_float), c_char_p]
_lib.RI_SDK_sensor_VoltageSensor_VoltageShunt.argtypes = [
c_int, POINTER(c_float), c_char_p]
_lib.RI_SDK_sensor_VoltageSensor_Sense.argtypes = [c_int, POINTER(
c_float), POINTER(c_float), POINTER(c_float), POINTER(c_float), c_char_p]
_lib.RI_SDK_sensor_VoltageSensor_Power.argtypes = [
c_int, POINTER(c_float), c_char_p]
_lib.RI_SDK_sensor_VoltageSensor_Current.argtypes = [
c_int, POINTER(c_float), c_char_p]
_lib.RI_SDK_sensor_VoltageSensor_ReadRegBytes.argtypes = [
c_int, c_uint8, POINTER(c_ulonglong), c_int, POINTER(c_int), c_char_p]
_lib.RI_SDK_sensor_VoltageSensor_WriteRegBytes.argtypes = [
c_int, c_uint8, POINTER(c_ulonglong), c_int, POINTER(c_int), c_char_p]
# ----------------------------------- Error handling ----------------------------------- #
class RISDKError(Exception):
def __init__(self, function: str, code: int, message: str) -> None:
super().__init__(
format("{0} exited with code {1}:\n{2}".format(function, code, message)))
def _call(*args):
error_text = create_string_buffer(1000)
error_code = args[0](*args[1:], error_text)
if error_code != 0:
raise RISDKError(args[0].__name__, error_code, error_text.raw.decode())
# ----------------------------------- Initialization ----------------------------------- #
log_level = 3 # TODO: Open this parameter
class _SDK:
def __init__(self) -> None:
_call(_lib.RI_SDK_InitSDK, log_level)
def __del__(self) -> None:
_call(_lib.RI_SDK_DestroySDK, True)
_sdk = _SDK()
def device_model_list(device: str) -> str:
model_list = create_string_buffer(200)
_call(_lib.RI_SDK_Device_ModelList, device.encode(), model_list)
return model_list.raw.decode()
# ------------------------------------- Components ------------------------------------- #
# TODO: RI_SDK_CreateBasic, RI_SDK_CreateGroupComponent, RI_SDK_CreateDeviceComponent
class _Component:
__slots__ = ("descriptor")
def __init__(self, *args) -> None:
self.descriptor = c_int()
_call(*args, self.descriptor)
def __del__(self) -> None:
_call(_lib.RI_SDK_DestroyComponent, self.descriptor)
class BasicComponent(_Component):
def __init__(self) -> None:
super().__init__(_lib.RI_SDK_CreateBasic)
class GroupComponent(_Component):
def __init__(self, group: str) -> None:
super().__init__(_lib.RI_SDK_CreateGroupComponent, group.encode())
class DeviceComponent(_Component):
def __init__(self, group: str, device_name: str) -> None:
super().__init__(_lib.RI_SDK_CreateDeviceComponent,
group.encode(), device_name.encode())
class ModelComponent(_Component):
def __init__(self, group: str, device_name: str, model_name: str) -> None:
super().__init__(_lib.RI_SDK_CreateModelComponent,
group.encode(), device_name.encode(), model_name.encode())
# ------------------------------------- Connectors ------------------------------------- #
class I2CAdapter(ModelComponent):
def __init__(self, model_name: str) -> None:
super().__init__("connector", "i2c_adapter", model_name)
def set_bus(self, bus: int) -> int:
next_bus, prev_bus = c_int(), c_int()
_call(_lib.RI_SDK_connector_i2c_SetBus, bus, next_bus, prev_bus)
return prev_bus.value
def open(self, address: int) -> None:
_call(_lib.RI_SDK_connector_i2c_Open, address)
def close(self, address: int) -> None:
_call(_lib.RI_SDK_connector_i2c_Close, address)
def close_all(self) -> None:
_call(_lib.RI_SDK_connector_i2c_CloseAll)
def state(self) -> int:
state = c_int()
_call(_lib.RI_SDK_connector_i2c_State, self.descriptor, state)
return state.value
def read_byte(self, address: int) -> int:
value = c_ulonglong()
_call(_lib.RI_SDK_connector_i2c_ReadByte,
self.descriptor, address, value)
return value.value
def write_byte(self, address: int, value: int) -> None:
_call(_lib.RI_SDK_connector_i2c_WriteByte,
self.descriptor, address, value)
def read_bytes(self, address: int, target_len: int) -> bytes:
data = c_ulonglong()
len = c_int()
_call(_lib.RI_SDK_connector_i2c_ReadBytes,
self.descriptor, address, data, target_len, len)
return data.value.to_bytes(len.value, "little")
def write_bytes(self, address: int, data: bytes) -> int:
data = c_ulonglong()
wrote = c_int()
buffer = c_ulonglong(int.from_bytes(data, "little"))
_call(_lib.RI_SDK_connector_i2c_WriteBytes,
self.descriptor, address, buffer, len(data), wrote)
return wrote.value
class PWM(ModelComponent):
def __init__(self, model_name: str) -> None:
super().__init__("connector", "pwm", model_name)
def link(self, controller: I2CAdapter, address: int):
_call(_lib.RI_SDK_LinkPWMToController,
self.descriptor, controller.descriptor, address)
def get_resolution(self) -> int:
resolution = c_int()
_call(_lib.RI_SDK_sigmod_PWM_GetResolution, self.descriptor, resolution)
return resolution.value
def get_freq(self) -> int:
freq = c_int()
_call(_lib.RI_SDK_sigmod_PWM_GetFreq, self.descriptor, freq)
return freq.value
def set_freq(self, freq: int) -> None:
_call(_lib.RI_SDK_sigmod_PWM_SetFreq, self.descriptor, freq)
def write_reg_bytes(self, register: int, data: bytes) -> int:
buffer = c_ulonglong(int.from_bytes(data, "little"))
wrote = c_int()
_call(_lib.RI_SDK_sigmod_PWM_WriteRegBytes,
self.descriptor, register, buffer, len(data), wrote)
def read_reg_bytes(self, register: int, len: int) -> bytes:
buffer = c_ulonglong()
got = c_int()
_call(_lib.RI_SDK_sigmod_PWM_ReadRegBytes,
self.descriptor, register, buffer, len, got)
return buffer.value.to_bytes(got.value, "little")
def write_byte(self, register: int, value: int) -> None:
_call(_lib.RI_SDK_sigmod_PWM_WriteByte,
self.descriptor, register, value)
def read_byte(self, register: int) -> int:
value = c_ulonglong()
_call(_lib.RI_SDK_sigmod_PWM_ReadByte,
self.descriptor, register, value)
return value.value
def get_port_freq(self, port: int) -> int:
freq = c_int()
_call(_lib.RI_SDK_sigmod_PWM_GetPortFreq, self.descriptor, port, freq)
return freq.value
def set_port_freq(self, port: int, freq: int) -> None:
_call(_lib.RI_SDK_sigmod_PWM_SetPortFreq, self.descriptor, port, freq)
def reset_port(self, port: int) -> None:
_call(_lib.RI_SDK_sigmod_PWM_ResetPort, self.descriptor, port)
def reset_all(self) -> None:
_call(_lib.RI_SDK_sigmod_PWM_ResetAll, self.descriptor)
def get_port_duty_cycle(self, port: int) -> (int, int):
on, off = c_int(), c_int()
_call(_lib.RI_SDK_sigmod_PWM_GetPortDutyCycle,
self.descriptor, port, on, off)
return on.value, off.value
def set_port_duty_cycle(self, port: int, on: int, off: int) -> None:
_call(_lib.RI_SDK_sigmod_PWM_SetPortDutyCycle,
self.descriptor, port, on, off)
def close(self) -> None:
_call(_lib.RI_SDK_sigmod_PWM_Close, self.descriptor)
# -------------------------------------- Executors ------------------------------------- #
class _Executor(ModelComponent):
def state(self) -> int:
state = c_int()
_call(_lib.RI_SDK_executor_State, self.descriptor, state)
return state.value
class Servodrive(_Executor):
def __init__(self, model_name: str) -> None:
super().__init__("executor", "servodrive", model_name)
def link(self, controller: PWM, port: int) -> None:
_call(_lib.RI_SDK_LinkServodriveToController,
self.descriptor, controller.descriptor, port)
def custom_init(self, max_impulse: int, min_impulse: int, max_speed: int, range_angle: int) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_CustomDeviceInit,
max_impulse, min_impulse, max_speed, range_angle)
def turn_by_duty_cycle(self, steps: int) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_TurnByDutyCycle, self.descriptor, steps)
def turn_by_pulse(self, pulse: int) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_TurnByPulse, self.descriptor, pulse)
def get_current_angle(self) -> int:
angle = c_int()
_call(_lib.RI_SDK_exec_ServoDrive_GetCurrentAngle, self.descriptor, angle)
return angle.value
# TODO: Same as state?
def get_state(self) -> int:
state = c_int()
_call(_lib.RI_SDK_exec_ServoDrive_GetState, self.descriptor, state)
return state.value
def min_step_rotate(self, direction: int, speed: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_MinStepRotate,
self.descriptor, direction, speed, is_async)
def turn(self, angle: int, speed: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_Turn,
self.descriptor, angle, speed, is_async)
def rotate(self, direction: int, speed: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_Rotate,
self.descriptor, direction, speed, is_async)
def turn_with_relative_speed(self, angle: int, speed: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_TurnWithRelativeSpeed,
self.descriptor, angle, speed, is_async)
def rotate_with_relative_speed(self, direction: int, speed: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_RotateWithRelativeSpeed,
self.descriptor, direction, speed, is_async)
def stop(self) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_Stop)
def set_position_to_mid_working_range(self) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_SetPositionToMidWorkingRange)
class ServodriveRotate(_Executor):
def __init__(self, model_name: str) -> None:
super().__init__("executor", "servodrive_rotate", model_name)
def link(self, controller: PWM, port: int) -> None:
_call(_lib.RI_SDK_LinkRServodriveToController,
self.descriptor, controller.descriptor, port)
def custom_init(self, min_pulse_clockwise: int, max_pulse_clockwise: int, min_pulse_counter_clockwise: int, max_pulse_counter_clockwise: int) -> None:
_call(_lib.RI_SDK_exec_ServoDrive_CustomDeviceInit,
min_pulse_clockwise, max_pulse_clockwise, min_pulse_counter_clockwise, max_pulse_counter_clockwise)
# TODO: Same as state?
def get_state(self) -> int:
state = c_int()
_call(_lib.RI_SDK_exec_RServoDrive_GetState, self.descriptor, state)
return state.value
def rotate_by_pulse(self, pulse: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_RServoDrive_RotateByPulse,
self.descriptor, pulse, is_async)
def rotate_by_pulse(self, pulse: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_RServoDrive_RotateByPulse,
self.descriptor, pulse, is_async)
def rotate_by_pulse_over_time(self, pulse: int, timeout: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_RServoDrive_RotateByPulseOverTime,
self.descriptor, pulse, timeout, is_async)
def rotate_with_relative_speed(self, direction: int, speed: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_RServoDrive_RotateWithRelativeSpeed,
self.descriptor, direction, speed, is_async)
def rotate_with_relative_speed_over_time(self, direction: int, speed: int, timeout: int, is_async: bool) -> None:
_call(_lib.RI_SDK_exec_RServoDrive_RotateWithRelativeSpeedOverTime,
self.descriptor, direction, speed, timeout, is_async)
def stop(self) -> None:
_call(_lib.RI_SDK_exec_RServoDrive_Stop)
class LED(_Executor):
def __init__(self, model_name: str) -> None:
super().__init__("executor", "led", model_name)
def link(self, controller: PWM, rport: int, gport: int, bport: int):
_call(_lib.RI_SDK_LinkLedToController,
self.descriptor, controller.descriptor, rport, gport, bport)
def single_pulse(self, r: int, g: int, b: int, duration: int, is_async: int):
_call(_lib.RI_SDK_exec_RGB_LED_SinglePulse,
self.descriptor, r, g, b, duration, is_async)
def flashing_with_frequency(self, r: int, g: int, b: int, frequency: int, qty: int, is_async: int):
_call(_lib.RI_SDK_exec_RGB_LED_FlashingWithFrequency,
self.descriptor, r, g, b, frequency, qty, is_async)
def flashing_with_pause(self, r: int, g: int, b: int, duration: int, pause: int, qty: int, is_async: int):
_call(_lib.RI_SDK_exec_RGB_LED_FlashingWithPause,
self.descriptor, r, g, b, duration, pause, qty, is_async)
def flicker(self, r: int, g: int, b: int, duration: int, qty: int, is_async: int):
_call(_lib.RI_SDK_exec_RGB_LED_Flicker,
self.descriptor, r, g, b, duration, qty, is_async)
def stop(self) -> None:
_call(_lib.RI_SDK_exec_RGB_LED_Stop)
# TODO: Same as state?
def get_state(self) -> int:
state = c_int()
_call(_lib.RI_SDK_exec_RGB_LED_GetState, self.descriptor, state)
return state.value
def get_color(self) -> (int, int, int):
r, g, b = c_int(), c_int(), c_int()
_call(_lib.RI_SDK_exec_RGB_LED_GetColor, self.descriptor, r, g, b)
return r.value, g.value, b.value
# --------------------------------------- Sensors -------------------------------------- #
class VoltageSensor(ModelComponent):
def __init__(self, model_name: str) -> None:
super().__init__("sensor", "voltage_sensor", model_name)
def link(self, controller: I2CAdapter, address: int):
_call(_lib.RI_SDK_LinkPWMToController,
self.descriptor, controller.descriptor, address)
def custom_init(self, lsb_bus: float, lsb_shunt: float, shunt_resist: float, reg_voltage_shunt: int, reg_voltage_bus: int) -> None:
_call(_lib.RI_SDK_sensor_VoltageSensor_CustomDeviceInit,
lsb_bus, lsb_shunt, shunt_resist, reg_voltage_shunt, reg_voltage_bus)
def voltage(self) -> float:
voltage = c_float()
_call(_lib.RI_SDK_sensor_VoltageSensor_Voltage, self.descriptor, voltage)
return voltage.value
def voltage_shunt(self) -> float:
voltage = c_float()
_call(_lib.RI_SDK_sensor_VoltageSensor_VoltageShunt,
self.descriptor, voltage)
return voltage.value
def sense(self) -> (float, float, float, float):
voltage, voltage_shunt, current, power = c_float(), c_float(), c_float(), c_float()
_call(_lib.RI_SDK_sensor_VoltageSensor_Sense,
self.descriptor, voltage, voltage_shunt, current, power)
return voltage.value, voltage_shunt.value, current.value, power.value
def power(self) -> float:
power = c_float()
_call(_lib.RI_SDK_sensor_VoltageSensor_Power, self.descriptor, power)
return power.value
def current(self) -> float:
current = c_float()
_call(_lib.RI_SDK_sensor_VoltageSensor_Current, self.descriptor, current)
return current.value
def read_reg_bytes(self, register: int, len: int) -> bytes:
buffer = c_ulonglong()
got = c_int()
_call(_lib.RI_SDK_sensor_VoltageSensor_ReadRegBytes,
self.descriptor, register, buffer, len, got)
return buffer.value.to_bytes(got.value, "little")
def write_reg_bytes(self, register: int, data: bytes) -> int:
buffer = c_ulonglong(int.from_bytes(data, "little"))
wrote = c_int()
_call(_lib.RI_SDK_sigmod_PWM_WriteRegBytes,
self.descriptor, register, buffer, len(data), wrote)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment