added some set/get examples with return code checking

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@139 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.1.0
Frank Singleton, VK3FCS 2000-09-23 02:17:12 +00:00
rodzic 7afd8f88ff
commit 581aceeac3
1 zmienionych plików z 59 dodań i 6 usunięć

Wyświetl plik

@ -1,4 +1,3 @@
/* /*
* Hamlib sample program * Hamlib sample program
*/ */
@ -11,16 +10,21 @@
int main () int main ()
{ {
RIG *my_rig; RIG *my_rig; /* handle to rig (nstance) */
freq_t freq; /* frequency */
rmode_t rmode; /* radio mode of operation */
vfo_t vfo; /* vfo selection */
int retcode; /* generic return code from functions */
/* /*
* allocate memory, setup & open port * allocate memory, setup & open port
*/ */
my_rig = rig_init(RIG_MODEL_FT847); my_rig = rig_init(RIG_MODEL_FT847);
if (!my_rig) if (!my_rig)
exit(1); /* whoops! something went wrong (mem alloc?) */ exit(1); /* whoops! something went wrong (mem alloc?) */
strncpy(my_rig->state.rig_path,SERIAL_PORT,MAXRIGPATHLEN); strncpy(my_rig->state.rig_path,SERIAL_PORT,FILPATHLEN);
if (rig_open(my_rig)) if (rig_open(my_rig))
exit(2); exit(2);
@ -28,14 +32,63 @@ int main ()
printf("Port %s opened ok\n", SERIAL_PORT); printf("Port %s opened ok\n", SERIAL_PORT);
/* /*
* Example of setting rig Main VFO to 439.700 Mhz FM -- FS * Below are examples of set/get routines.
* Must add checking of functionality map prior to command execution -- FS
* *
*/ */
rig_set_vfo(my_rig, RIG_VFO_MAIN);
rig_set_freq(my_rig, 439700000); /*
* Example of setting rig Main VFO to 439.700 Mhz FM -- FS
* and some error checking on the return code.
*/
retcode = rig_set_vfo(my_rig, RIG_VFO_MAIN);
if (retcode != RIG_OK ) {
printf("rig_set_vfo: error = %i \n", retcode);
}
rig_set_freq(my_rig, 439700000); /* cq de vk3fcs */
if (retcode != RIG_OK ) {
printf("rig_set_freq: error = %i \n", retcode);
}
rig_set_mode(my_rig, RIG_MODE_FM); rig_set_mode(my_rig, RIG_MODE_FM);
if (retcode != RIG_OK ) {
printf("rig_get_mode: error = %i \n", retcode);
}
/*
* Simple examples of getting rig information -- FS
*
*/
retcode = rig_get_vfo(my_rig, &vfo); /* try to get vfo info */
if (retcode == RIG_OK ) {
printf("rig_get_vfo: vfo = %i \n", vfo);
} else {
printf("rig_get_vfo: error = %i \n", retcode);
}
retcode = rig_get_freq(my_rig, &freq);
if (retcode == RIG_OK ) {
printf("rig_get_freq: freq = %Li \n", freq);
} else {
printf("rig_get_vfo: error = %i \n", retcode);
}
rig_get_mode(my_rig, &rmode);
if (retcode == RIG_OK ) {
printf("rig_get_mode: mode = %i \n", rmode);
} else {
printf("rig_get_mode: error = %i \n", retcode);
}
rig_close(my_rig); /* close port */ rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */ rig_cleanup(my_rig); /* if you care about memory */