Side-connect api plc message handling functions – ProSoft Technology MVI69-ADM User Manual

Page 315

Advertising
background image

MVI-ADM ♦ 'C' Programmable

Side-Connect API Library Functions

'C' Programmable Application Development Module

Developer's Guide

ProSoft Technology, Inc.

Page 315 of 342

February 20, 2013

11.6 Side-connect API PLC Message Handling Functions

The PLC-5 may use the message (MSG) instruction to read or write data to the
MVI. A message handler must be registered using the MVIsc_PLCMsgRead or
MVIsc_PLCMsgWrite functions. The MSG instruction in the PLC-5 ladder
program must be setup for communication port 3A. The command type must be
set to PLC-3 Word Range Read or PLC-3 Word Range Write. The destination
data table address must be set to "00" through "31", for message number 0 to 31.

MVIsc_PLCMsgRead

Syntax

int MVIsc_PLCMsgRead(HANDLE handle, void *buf, WORD datatype, WORD size, BYTE
msgnum, WORD timeout);

Parameters

handle

Handle returned by previous call to MVIsc_Open

buf

Pointer to user buffer containing data to be read by the PLC-5

datatype

Type of data (MVISC_DTYP_WORD or MVISC_DTYP_FLOAT)

size

Number of items of type datatype to be transferred. The total size
cannot exceed 240 bytes.

msgnum

PLC-5 message number (0 to 31)

timeout

Maximum number of milliseconds to wait for message-read

Description
MVIsc_PLCMsgRead handles a PLC-5 message-read instruction. This function
should be called before the PLC-5 issues the message-read instruction.

handle must be a valid handle returned from MVIsc_Open. timeout indicates the
number of milliseconds to wait for the message-read instruction from the PLC-5.
A value of zero will cause the function to register the message handler and return
immediately, without waiting for the message-read instruction. In this case, the
MVIsc_PLCMsgWait function must be used to determine if the instruction has
been completed.

Return Value

MVISC_SUCCESS

The command completed without error (Note: If timeout was set
to zero, this does not mean that the message-read instruction
has completed, but only that the message handler was
successfully registered. See MVIsc_PLCMsgWait).

MVISC_ERR_NOACCESS

handle does not have access

MVISC_ERR_PLCTIMEOUT

The timeout expired before the message read instruction
occurred.

Example

HANDLE Handle;
float flt_array[8];
/* Setup message-read handler for msg 19, wait 5 seconds */
rc = MVIsc_PLCMsgRead(Handle, flt_array, MVISC_DTYP_FLOAT, 8, 19, 5000);
if (rc != MVISC_SUCCESS)
printf("ERROR: MVIsc_PLCMsgRead failed");

Advertising