poll_interval and callbacks ...
Sagaert Johan <sagaert.johan <at> skynet.be>
2012-07-20 12:37:33 GMT
Hi
I downloaded the sources via GIT and looked into the ts950.c, the callbacks are simply not used, neither is
the poll_interval of any
use.
It was a bit misleading I thought hamlib had an internal thread polling for data and invoking the callback
when something changed.
(maybe this is something for V3 ?)
So I will create a background thread with a mutexlock on the rig structure pointer in case I send some command
via one of the
functions.
I don't think hamlib is thread safe as it is.
I once wrote a server that was command based, so the number of exported functions would be greatly reduced.
(eg Set(rig,"SELECT VFOA"); ...Set(rig,"VFOA_FREQUENCY,14350500"); in .NET these commands could be
put in a Queue and then processed
in a background thread ).
With the ascii commands, there is the advantage that these commands could be put in a file so a user could
easely finetune things to
do when a certain command is invoked. (behaving like macro functions)
Johan
-----Oorspronkelijk bericht-----
Van: james.patterson.m1dst <at> gmail.com [mailto:james.patterson.m1dst <at> gmail.com] Namens James Patterson
Verzonden: vrijdag 20 juli 2012 12:51
Aan: Sagaert Johan
CC: hamlib-developer <at> lists.sourceforge.net
Onderwerp: Re: [Hamlib-developer] NET interop
I very briefly looked into the callbacks and couldn't get them working. I also think they only relate to
radios with a cat
interface which reports changes EG: Kenwood.
At the time I was using a Yaesu rig and decided not to spend any real time on it when I would have to poll for the
other rigs
anyway. I may have misunderstood something but decided against persuiing it further.
If you do get it working, please let me know so I can look at building that functionality into my wrapper when I
get back into
it..... (I'm hacking hardware at the moment)
James
On 20 July 2012 00:48, Sagaert Johan <sagaert.johan <at> skynet.be> wrote:
>
> Hi James
>
> I can use hamlib now, but cant get the callbacks to wordk, they reurn 0 (OK) but are not fired when I change
mode or freq.
>
> //my c wrapper
>
> HAMLIBNET_API int HamlibSetFreqCallBack(RIG *my_rig, freq_cb_t cb,void
> * dta) {
> return rig_set_freq_callback(my_rig,cb,dta);
> }
>
>
> //my pinvoveke decl
> [DllImport("HamlibNet.dll", CallingConvention =
> CallingConvention.Cdecl, CharSet = CharSet.Ansi)] public static extern
> int HamlibSetModeCallBack(IntPtr my_rig, mode_cb_t cb, IntPtr dta);
>
>
>
> //my c# useage
> int i = Hamlib.HamlibSetModeCallBack(p,
> mymode_cb_t,(IntPtr)1234567898); // returns 0(OK)
>
>
> private int mymode_cb_t(IntPtr r, Hamlib.vfo_t vfo, Hamlib.RigMode
> rm, long pbw, IntPtr b) {
> Console.WriteLine();
> return 0;
> }
>
> It does not get fired when I manually control my rig.
>
>
>
>
> -----Oorspronkelijk bericht-----
> Van: james.patterson.m1dst <at> gmail.com
> [mailto:james.patterson.m1dst <at> gmail.com] Namens James Patterson
> Verzonden: donderdag 19 juli 2012 13:24
> Aan: Sagaert Johan
> CC: hamlib-developer <at> lists.sourceforge.net
> Onderwerp: Re: [Hamlib-developer] NET interop
>
> I've used Hamlib with VB.NET and C#. Here are the signatures I use
> for C#. I've written an entire .net wrapper for this stuff which I
> will eventually release but this extract should help you along the way.
>
> James
> M1DST
>
>
> public static class HamLibStatic
> {
> #region DLL References
>
> /// <summary>
> /// Allocates a new RIG handle and initializes the associated
> data for model.
> /// </summary>
> /// <param name=" model">The rig model.</param>
> /// <returns>A pointer to the RIG handle otherwise NULL if
> memory allocation failed or model is unknown (e.g. backend autoload
> failed).</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_init(int model);
>
> /// <summary>
> /// Opens communication to a radio which RIG handle has been passed by argument.
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured (in which case, cause is set appropriately).</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_open(int RIGptr);
>
> /// <summary>
> /// Closes communication to a radio which RIG handle has been
> passed by argument that was previously open with open().
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_close(int RIGptr);
>
> /// <summary>
> /// Release a rig handle and free associated memory
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_cleanup(int RIGptr);
>
> /// <summary>
> /// Set the frequency of the target VFO
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="vfo">The target VFO</param>
> /// <param name="freq">The frequency to set to</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_set_freq(int RIGptr, int vfo,
> double freq);
>
> /// <summary>
> /// Retrieves the frequency of the target VFO. The value
> stored at freq location equals FREQ_NONE when the current frequency
> of the VFO is not defined (e.g. blank memory).
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="vfo">The target VFO</param>
> /// <param name="freq">The location where to store the current frequency</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_get_freq(int RIGptr, int vfo,
> ref double freq);
>
> /// <summary>
> /// Sets the mode and associated passband of the target VFO.
> The passband width must be supported by the backend of the rig.
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="vfo">The target VFO</param>
> /// <param name="mode">The mode to set to</param>
> /// <param name="width">The passband width to set to</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_set_mode(int RIGptr, int vfo,
> RigMode mode, long width);
>
> /// <summary>
> /// Retrieves the mode and passband of the target VFO. If the
> backend is unable to determine the width, the width will be set to PASSBAND_NORMAL as a default. The value
stored at mode location
equals
> MODE_NONE when the current mode of the VFO is not defined (e.g.
> blank memory).
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="vfo">The target VFO</param>
> /// <param name="mode">The location to store the current mode</param>
> /// <param name="width">The location to store the current passband width</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_get_mode(int RIGptr, int vfo,
> ref RigMode mode, ref long width);
>
> /// <summary>
> /// Sets the current VFO. The VFO can be VFO_A, VFO_B,
> VFO_C for VFOA, VFOB, VFOC respectively or VFO_MEM for Memory
> mode. Supported VFOs depends on rig capabilities.
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="vfo">The VFO to set to</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_set_vfo(int RIGptr, int vfo);
>
> /// <summary>
> /// Retrieves the current VFO. The VFO can be VFO_A,
> VFO_B, VFO_C for VFOA, VFOB, VFOC respectively or VFO_MEM for
> Memory mode. Supported VFOs depends on rig capabilities.
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="vfo">The location where to store the current VFO</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_get_vfo(int RIGptr, ref int
> vfo);
>
> /// <summary>
> /// Simple lookup returning token id assicated with name.
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="name">The name of the configuration parameter</param>
> /// <returns>the token id if found, otherwise CONF_END</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_token_lookup(int RIGptr, string
> name);
>
> /// <summary>
> /// Set a radio configuration parameter
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="token">The parameter</param>
> /// <param name="value">The value to set the parameter to</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured (in which case, cause is set appropriately).</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_set_conf(int RIGptr, int token,
> string value);
>
> /// <summary>
> /// Retrieves the value of a configuration paramter associated
> with token. The location pointed to by val must be large enough to hold the value of the config.
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <param name="token">The parameter</param>
> /// <param name="value">The value of the setting</param>
> /// <returns> OK if the operation has been sucessful,
> otherwise a negative value if an error occured (in which case, cause is set appropriately).</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern int rig_get_conf(int RIGptr, int token,
> string value);
>
> /// <summary>
> /// Retrieves some general information from the radio. This
> can include firmware revision, exact model name, or just nothing.
> /// </summary>
> /// <param name="RIGptr">The rig handle</param>
> /// <returns>A string if the operation has been sucessful,
> otherwise NULL if an error occured or get_info not part of capabilities.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern string rig_get_info(int RIGptr);
>
> /// <summary>
> /// Returns a string describing the error code passed in the argument errnum.
> /// </summary>
> /// <param name="errnum">The error code</param>
> /// <returns>The appropriate description string, ortherwise a NULL pointer if the error code is unknown.</returns>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern string rig_rigerror(int errnum);
>
> [DllImport("libhamlib-2.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
> internal static extern string rig_strrmode(RigMode mode);
>
> #endregion
>
> }
>
>
>
>
>
>
>
>
>
>
>
> On 19 July 2012 09:31, Sagaert Johan <sagaert.johan <at> skynet.be> wrote:
>> Hi
>>
>> Is there an p/invoke interface for using the DLL in a c# project ?
>>
>>
>> 73 johan on5di
>>
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> -
>> --------
>> Live Security Virtual Conference
>> Exclusive live event will cover all the ways today's security and
>> threat landscape has changed and how IT managers can respond.
>> Discussions will include endpoint security, mobile security and the
>> latest in malware threats.
>> http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>> _______________________________________________
>> Hamlib-developer mailing list
>> Hamlib-developer <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/hamlib-developer
>>
>
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/