beautypg.com

ProSoft Technology MVI56E-LDM User Manual

Page 52

background image

Understanding the MVI56-LDM API

ControlLogix Platform ♦ "C" Programmable

Developer's Manual

Linux Application Development Module

Page 46 of 264

ProSoft Technology, Inc.

March 12, 2014

4.11 Ethernet Sample

The Ethernet sample comes as two programs; a client, and a server. The server
waits for a client to request a connection, replies with the local time, and closes
the connection. The client is run with the IP4 address of the server. The client
opens a connection to the server, receives the response message, and prints the
message (the time on the server) to the console.
It is recommended that the server be run on one MVI56E-LDM module and the
client on another. Alternately, either of the programs could be ported to another
Linux environment. Attempting to run both programs on the same MVI56E-LDM
is not advised due to the complexity of IP routing.

Server Enet Sample
To run the Server Enet sample:
Open a command window using telnet or a similar terminal software on the PC
through a serial (P1) or Ethernet port.
Login as user: root, password: password.
The Ethernet port E1 is used to communicate with the client device. The server
and client devices must both be connected on the same IPv4 subnet.
Set the IPv4 address and mask of the first Ethernet port using the ifconfig
command.
To execute the sample:
From the default home directory

/psft

, type the command

./Server_Sample&

.

The program runs as a background task. The server will wait forever processing
requests from clients.
While looking at the sample source, you'll see that the following occurs:

register

sigquit_handler

for four signals

check command line and print usage message if required

open the backplane using open_backplane()

initialize the LEDs on the front panel

call the function

socket()

to create a unnamed socket inside the kernel.

socket()

returns an integer know as socket descriptor.

o

The function takes domain/family as its first argument. For Internet family
of IPv4 addresses, use

AF_INET

.

o

The second argument

SOCK_STREAM

specifies the type of connection to

use. In this case, a sequential, reliable two-way connection is desired

o

The third argument selects the protocol to use. Generally, this is zero as
the system normally only has one protocol for each type of connection,
although it is possible to have multiple protocols for a connection type.
Zero tells the system to use the default protocol for the specified
connection. In this case, the default is TCP.

The

send_buff

and

serv_addr

variables are zeroed.

In preparation for the call to

bind()

,

serv_addr

is then set to the well known

port address

SERVER_PORT_NUMBER

, and any IP address. This allows a

connection to be accepted from any IP address as long as the well known
port is specified.