2021-12-28 16:27:26 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
|
|
import ctypes
|
|
|
|
from ctypes import *
|
|
|
|
import pathlib
|
|
|
|
|
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
|
|
|
class DEBUGLEVEL(Enum):
|
|
|
|
RIG_DEBUG_NONE = 0
|
|
|
|
RIG_DEBUG_BUG = 1
|
|
|
|
RIG_DEBUG_ERR = 2
|
|
|
|
RIG_DEBUG_WARN = 3
|
|
|
|
RIG_DEBUG_VERBOSE = 4
|
|
|
|
RIG_DEBUG_TRACE = 5
|
|
|
|
RIG_DEBUG_CACHE = 6
|
|
|
|
|
2022-05-23 12:26:14 +00:00
|
|
|
|
2021-12-28 16:27:26 +00:00
|
|
|
class RETCODE(Enum):
|
|
|
|
RIG_OK = 0
|
|
|
|
RIG_EINVAL = 1
|
|
|
|
RIG_ECONF = 2
|
|
|
|
RIG_ENOMEM = 3
|
|
|
|
RIG_ENIMPL = 4
|
|
|
|
RIG_ETIMEOUT = 5
|
|
|
|
RIG_EIO = 6
|
|
|
|
RIG_EINTERNAL = 7
|
|
|
|
RIG_EPROTO = 8
|
|
|
|
RIG_ERJCTED = 9
|
|
|
|
RIG_ETRUNC = 10
|
|
|
|
RIG_ENAVAIL = 11
|
|
|
|
RIG_ENTARGET = 12
|
|
|
|
RIG_BUSERROR = 13
|
|
|
|
RIG_BUSBUSY = 14
|
|
|
|
RIG_EARG = 15
|
|
|
|
RIG_EVFO = 16
|
|
|
|
RIG_EDOM = 17
|
|
|
|
|
|
|
|
libname = pathlib.Path("../tnc/lib/hamlib/linux/libhamlib.so")
|
|
|
|
hamlib = ctypes.CDLL(libname)
|
|
|
|
|
|
|
|
class SERIAL(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("data_bits", ctypes.c_int),
|
|
|
|
("stop_bits", ctypes.c_int),
|
|
|
|
("rate", ctypes.c_int),
|
2021-12-28 17:25:52 +00:00
|
|
|
("parity", ctypes.c_int),
|
|
|
|
("handshake", ctypes.c_void_p),
|
2021-12-28 16:27:26 +00:00
|
|
|
]
|
2022-05-23 12:26:14 +00:00
|
|
|
|
|
|
|
|
2021-12-28 16:27:26 +00:00
|
|
|
class PARM(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("serial", SERIAL),
|
|
|
|
]
|
2022-05-23 12:26:14 +00:00
|
|
|
|
|
|
|
|
2021-12-28 17:25:52 +00:00
|
|
|
class TYPE(ctypes.Structure):
|
2021-12-28 16:27:26 +00:00
|
|
|
_fields_ = [
|
2021-12-28 17:25:52 +00:00
|
|
|
("rig", ctypes.c_void_p),
|
2021-12-28 16:27:26 +00:00
|
|
|
]
|
2022-05-23 12:26:14 +00:00
|
|
|
|
|
|
|
|
2021-12-28 17:25:52 +00:00
|
|
|
class MYPORT(ctypes.Structure):
|
2021-12-28 16:27:26 +00:00
|
|
|
_fields_ = [
|
2021-12-28 16:36:50 +00:00
|
|
|
("pathname", ctypes.c_char),
|
2021-12-28 17:25:52 +00:00
|
|
|
("model", ctypes.c_int),
|
|
|
|
("parm", PARM),
|
|
|
|
("type", TYPE),
|
2021-12-28 16:27:26 +00:00
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2022-05-23 12:26:14 +00:00
|
|
|
hamlib.rig_set_debug(9) # 6
|
|
|
|
myrig_model = 3085 # 3085 = ICOM 6 = DUMMY
|
2021-12-28 16:27:26 +00:00
|
|
|
|
2021-12-28 17:25:52 +00:00
|
|
|
myport = MYPORT()
|
|
|
|
myport.parm.serial.data_bits = 7
|
|
|
|
myport.parm.serial.stop_bits = 2
|
|
|
|
myport.parm.serial.rate = 9600
|
2021-12-28 16:27:26 +00:00
|
|
|
|
2021-12-28 17:25:52 +00:00
|
|
|
rig = hamlib.rig_init(myrig_model)
|
2021-12-28 16:27:26 +00:00
|
|
|
|
2021-12-28 20:25:19 +00:00
|
|
|
retcode = hamlib.rig_set_parm(rig, 'stop_bits', 5)
|
2021-12-28 17:25:52 +00:00
|
|
|
print(retcode)
|
2021-12-28 16:27:26 +00:00
|
|
|
|
2021-12-28 20:25:19 +00:00
|
|
|
'''
|
|
|
|
parameter = create_string_buffer(16)
|
|
|
|
retcode = hamlib.rig_get_parm(rig, 0, parameter)
|
|
|
|
print(retcode)
|
|
|
|
print(bytes(parameter))
|
|
|
|
'''
|
2021-12-28 16:27:26 +00:00
|
|
|
|
|
|
|
|
2021-12-28 20:25:19 +00:00
|
|
|
# attempt to access global vars. Maybe we can access structures as well?
|
|
|
|
# https://github.com/Hamlib/Hamlib/blob/f5b229f9dc4b4364d2f40e0b0b415e92c9a371ce/src/rig.c#L95
|
|
|
|
hamlib_version = ctypes.cast(hamlib.hamlib_version, ctypes.POINTER(ctypes.c_char*21))
|
|
|
|
print(hamlib_version.contents.value)
|
2021-12-28 16:27:26 +00:00
|
|
|
|
|
|
|
|
2021-12-28 20:25:19 +00:00
|
|
|
'''
|
|
|
|
retcode = hamlib.rig_has_get_parm(rig, 7)
|
|
|
|
print(retcode)
|
|
|
|
'''
|
2021-12-28 16:27:26 +00:00
|
|
|
|
2021-12-28 20:25:19 +00:00
|
|
|
'''
|
|
|
|
retcode = hamlib.rig_open(rig)
|
|
|
|
print(retcode)
|
|
|
|
hamlib.rig_close(rig)
|
|
|
|
'''
|
2021-12-28 16:27:26 +00:00
|
|
|
|
2022-05-23 12:26:14 +00:00
|
|
|
# riginfo = create_string_buffer(1024)
|
|
|
|
# retcode = hamlib.rig_get_rig_info(rig, riginfo, 1024);
|
2021-12-28 16:27:26 +00:00
|
|
|
|
|
|
|
'''
|
|
|
|
char riginfo[1024];
|
|
|
|
retcode = rig_get_rig_info(rig, riginfo, sizeof(riginfo));
|
|
|
|
'''
|