Halcon10-C語言打印消息
#include "HalconC.h"
#include <stdio.h>
/* ignore automatic error handling */
void no_exit()
{
? (void)set_check("~give_error");
}
/* activate automatic error handling (default) */
void do_exit()
{
? (void)set_check("give_error");
}
/*?
?* handling of errors:
?*? ?a: user defined error handling
?*? ?b: exit on error
?*/
void test_errors()
{
? Herror? ? err;? ? ? ? ? ? ? ? ? ?/* message number */
? char? ? ? message[MAX_STRING];? ?/* error text */
? long? ? ? WrongWindowHandle = 0; /* no window available */
??
? (void)printf("Ignore automatic exit on error:\n");
? no_exit();
? (void)printf("- Trying to display a circle ... But because there's\n");
? (void)printf("? no valid graphics window, an error will occur!\n");
? err = disp_circle(WrongWindowHandle,100.0,100.0,100.0);
? if (err != H_MSG_TRUE)
? {
? ? (void)get_error_text(err,(char*)message);
? ? (void)printf("My error message: (%d) \n%s\n",err,message);
? ? (void)printf("... we should have opened a window!\n\n");
? }
? (void)printf("Switch on automatic exit on error:\n");
? do_exit();
? (void)printf("- Trying to display a circle ... But because there's\n");
? (void)printf("? no valid graphics window, the program will terminate!\n");
? (void)disp_circle(WrongWindowHandle,100.0,100.0,100.0);
}
/*
?* Types of messages:
?* Attention: Messages are no error and do not cause runtime errors!
?*? ? ? ? ? ? They are always returned.
?*
?*? ?H_MSG_TRUE:? everything is perfect
?*? ?H_MSG_FAIL:? something failed (try again)
?*? ?H_MSG_VOID:? you can't continue with this result
?*/
void test_messages()
{
? ?Herror? ? err;
? ?Hobject? ?Image,Circle,Empty,Result;
? ?long? ? ? WindowHandle;
? ?Htuple? ? task, value;
? ?
? ?(void)printf("Provoking a success message (H_MSG_TRUE):\n");
? ?err = open_window(1,1,100,100,0,"visible","",&WindowHandle);
? ?if (err == H_MSG_TRUE)
? ? ?(void)printf("- open_window:? H_MSG_TRUE (%d)\n",err);
? ?(void)printf("We wait until the mouse is inside the graphics window ...\n\n");
? ?do
? ?{
? ? ?err = get_mposition(WindowHandle,_,_,_);
? ?} while (err == H_MSG_FAIL);
? ?(void)close_window(WindowHandle);
? ?
? ?(void)printf("Now provoking a failure message (H_MSG_FAIL):\n");
? ?err = read_image(&Image,"this_image_does_not_exist");
? ?if (err == H_MSG_FAIL)
? ? ?(void)printf("- read_image (file not found): H_MSG_FAIL (%d)\n\n",err);
? ?else
? ? ?(void)printf("This is really funny! (%d)\n\n", err);
? ?
? ?(void)printf("Now provoking a void message (H_MSG_VOID):\n");
? ?/* create circle with radius 1.0 */
? ?(void)gen_circle(&Circle,100.0,100.0,1.0);? ? ?
? ?/* select large segments */
? ?(void)select_shape(Circle,&Empty,"area","and",1000.0,1000000.0);
? ?/* now we have an empty list! */
? ?create_tuple(&task,1);
? ?set_s(task,"empty_region_result",0);
? ?create_tuple(&value,1);
? ?set_d(value,H_MSG_FAIL,0);
? ?set_system("no_object_result","void");
? ?destroy_tuple(task);
? ?destroy_tuple(value);
? ?/* contour of nothing -> VOID message */
? ?err = boundary(Empty,&Result,"inner");
? ?if (err == H_MSG_VOID)
? ? ?(void)printf("- contour1 (no objects):? H_MSG_VOID (%d)\n\n",err);
? ?else
? ? ?(void)printf("That is really funny! (%d)\n\n", err);
}
main()
{
? (void)printf("-----------------------------\n");
? (void)printf("Example program for HALCON/C:\n");
? (void)printf("-----------------------------\n");
? (void)printf("- error handling\n");
? (void)printf("- H_MSG_TRUE, H_MSG_FAIL, and H_MSG_VOID\n\n");
? test_messages();
? test_errors();
? return(0);
}