B&B Electronics VFG3000 - Manual User Manual
Page 202

R
EADING
C
HARACTERS
V
LINX
F
IELDBUS
G
ATEWAY
M
ANAGER
U
SER
M
ANUAL
P
AGE
186
The On Update property is configured as described above, while the Port property should be
configured to indicate which TCP port you want the driver to monitor. The driver will accept
connections on this port, and then call the On Update program to handle communications.
R
EADING
C
HARACTERS
To read data from a raw port a character at a time, use the
PortRead
function, as documented
in the Function Reference section of this manual. As with all raw port functions, the
port
argument for this function is calculated by counting down the list of ports in the left-hand
pane of the Communications window, with the programming port being port 1.
The example below shows to use
PortRead
to accept characters…
int Data;
for(;;) {
if( (Data := PortRead(2, 100)) >= 0 ) {
/* Add code to process data */
}
}
Note that by passing a non-zero value for the
period
argument, the need to call the
Sleep
function is removed. If you use a zero value for this argument, you must make sure that you
suspend the communications task at some point, or you will disrupt system operation.
R
EADING
E
NTIRE
F
RAMES
To read an entire frame from a raw port, use the
PortInput
function, as documented in the
Function Reference section of this manual. This function allows you to specify frame
delimiters, the required frame length and a frame timeout, thereby removing the need to write
your own receive state machine. As sample program is shown below…
cstring input;
int value;
for(;;) {
input := PortInput(5, 42, 13, 3, 0);
if( value := TextToInt(input, 10) ) {
Speed := value;
PortPrint(5, "Value is ");
PortPrint(5, IntToText(value,10,5));
PortPrint(5, "\r\n");
}
}