IEC 61131-3 C Tools User Manual


Add to my manuals
501 Pages

advertisement

IEC 61131-3 C Tools User Manual | Manualzz

IEC 61131-3 C Tools Function Specifications

install_handler

Install Serial Port Handler

Syntax

#include <ctools.h> void install_handler(FILE *stream, void *function(unsigned, unsigned));

Description

The install_handler function installs a serial port character handler function. The serial port driver calls this function each time it receives a character. If stream does not point to a valid serial port the function has no effect.

function specifies the handler function, which takes two arguments. The first argument is the received character. The second argument is an error flag. A nonzero value indicates an error. If function is NULL, the default handler for the port is installed. The default handler does nothing.

Notes

The install_handler function can be used to write custom communication protocols.

The handler is called at the completion of the receiver interrupt handler. RTOS calls (see functions listed in the section Real Time Operating System Functions at the start of this chapter) may not be made within the interrupt handler, with one exception. The interrupt_signal_event RTOS call can be used to signal events.

To optimize performance, minimize the length of messages on com3 and com4.

Examples of recommended uses for com3 and com4 are for local operator display terminals, and for programming and diagnostics using the IEC 61131-3 program.

Example

#include <ctools.h>

#define CHAR_RECEIVED 11

/* --------------------------------------------

signal

This routine signals an event when a character

is received on com1. If there is an error, the

character is ignored.

-------------------------------------------- */ void signal(unsigned character, unsigned error)

{ if (error == 0) interrupt_signal_event( CHAR_RECEIVED );

Document (Version 2.50) 5/12/2011 234 234

IEC 61131-3 C Tools Function Specifications

} character;

}

/* --------------------------------------------

main

This program displays all characters received

on com1 using an installed handler to signal

the reception of a character.

-------------------------------------------- */ void main(void)

{ struct prot_settings protocolSettings; int character;

/* Disable protocol */ get_protocol(com1, &protocolSettings); protocolSettings.type = NO_PROTOCOL; request_resource(IO_SYSTEM); set_protocol(com1, &protocolSettings); release_resource(IO_SYSTEM);

/* Enable character handler */ install_handler(com1, signal);

/* Print each character as it is recevied */ while (TRUE)

{

} wait_event(CHAR_RECEIVED); character = fgetc(com1); fputs("character: ", com1); fputc(character, com1); fputs("\r\n", com1);

Document (Version 2.50) 5/12/2011 235 235

advertisement

Was this manual useful for you? Yes No
Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Related manuals

advertisement

Table of contents