05.05.2014 Views

csmstr - Omega Engineering

csmstr - Omega Engineering

csmstr - Omega Engineering

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

USING RAW PORTS<br />

CRIMSON USER MANUAL - MODULAR CONTROLLER<br />

The On Update property is configured as described above, while the Port property should be<br />

configured to indicate which TCP port you want the driver to monitor. The driver will accept<br />

connections on this port, and then call the On Update program to handle communications.<br />

READING CHARACTERS<br />

To read data from a raw port a character at a time, use the PortRead function, as documented<br />

in the Function Reference section of this manual. As with all raw port functions, the port<br />

argument for this function is calculated by counting down the list of ports in the left-hand<br />

pane of the Communications window, with the programming port being port 1.<br />

The example below shows to use PortRead to accept characters…<br />

int Data;<br />

for(;;) {<br />

if( (Data := PortRead(2, 100)) >= 0 ) {<br />

}<br />

/* Add code to process data */<br />

}<br />

Note that by passing a non-zero value for the period argument, the need to call the Sleep<br />

function is removed. If you use a zero value for this argument, you must make sure that you<br />

suspend the communications task at some point, or you will disrupt system operation.<br />

READING ENTIRE FRAMES<br />

To read an entire frame from a raw port, use the PortInput function, as documented in the<br />

Function Reference section of this manual. This function allows you to specify frame<br />

delimiters, the required frame length and a frame timeout, thereby removing the need to write<br />

your own receive state machine. As sample program is shown below…<br />

cstring input;<br />

int value;<br />

for(;;) {<br />

input := PortInput(5, 42, 13, 3, 0);<br />

if( value := TextToInt(input, 10) ) {<br />

Speed := value;<br />

}<br />

PortPrint(5, "Value is ");<br />

PortPrint(5, IntToText(value,10,5));<br />

PortPrint(5, "\r\n");<br />

}<br />

PAGE 272<br />

http://www.redlion.net/controller

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!