Data Acquisition (DAQ) and Control from Microstar Laboratories

Knowledge Base: Processing

  • See the list of other topics for category Processing

Q10048 Processing text messages in custom modules

Tags: Help, DAP, DAPL, custom commands, modules, control, text, communications

Applies to: All DAP models, custom processing commands, communication pipes

I want to pass short control messages about status changes, operating mode changes, control events, etc., between my software application and my controller functions running on my DAP board, both directions. How can I do this?

Simple line-oriented text messages between your application and a running custom command task are sometimes a good means to transfer information about operating conditions and events. Line-oriented means that messages are in the form of short character strings, each one terminated with a linefeed (\n), a carriage-return (\r), or a pair of these two characters (\n\r or \r\n) in the manner of a text file in your host operating system.

On the PC host side, the DAPIO32 programming interface provides DapLinePut and DapLineGet functions that help you to send and receive text lines without worrying too much about the details of text line termination.

In the custom processing on your DAP board, you can use variants of Standard C library functions for sending and receiving text lines.

  • The fprintf() function can be used to build your text lines and send them to the PC host through the communications pipe you specify. Since the DAPL system does not have a file system, a pipe handle parameter is substituted for the standard file handle parameter.

  • For receiving text lines into your custom command task from the host system, use the fgets() function. This function also requires a communications pipe handle in place of a standard file handle. Somehow, this function was overlooked in the current Developer's Toolkit for DAPL manual, but it should be listed in the future. It is declared in the DTD header files, so you don't need to do anything special to access it.

    char * fgets(char *mystringbuf, int maxsize, PIPE *texthandle);
       mystringbuf  - storage buffer to receive your incoming text
       maxsize      - number of character storage locations in your buffer
       texthandle   - the opened handle to your communication pipe  

    Be sure to use the pipe_num function to verify that a text line is available first, otherwise your task will "hang" until fgets receives the next text line. When fgets returns, a conventional zero-terminated character string line is present in your input buffer storage area.

L23571

Manuals for DTD and DAPIO interfaces are available at the manuals download page.