Php Serial Port Communication Linux Tutorial Pdf
TCP/IP COMMUNICATION
Data link over TCP/IP |
Synchronous Communications; Accessing Serial Ports. Standard MODEM Commands; Common MODEM Communication Problems. Under IRIX®, HP-UX, SunOS®, Solaris®, Digital UNIX®, Linux®, and most other UNIX operating systems.
Information exchange between a program running on the Raspberry Pi and a partner program running on a remote computer systems becomes important when the Raspberry Pi is a front end of a measurement system and transfers sensor data in real-time to a control station or when a remote PC sends commands a RPi based robot (remote control mode). In most situations the data link is established via TCP/IP and the well-established client/server technology based on socket programming is used. In this chapter we show typical programs for simple TCP communication without going into much details (consult other tutorials about socket programming to acquire a full understanding). Most important and somewhat unexpected is the fact that the communication partners, the server and the client, are not symmetrical. Rather, first the server program must be started before the client program can engage a connection to it. In order to identify the two computers on the Internet, their IP address is used. In addition, server and client specify one of 65536 communication channels (IP ports).
|
Experiment 1: Programming with a low-level socket library |
In a client/server application between a Raspberry Pi and a remote PC, the RPi can be server while the PC is a client or the roles may be interchanged. It depends on the specific situation which mode is preferred. In the following example the RPi acts as a measurement server that reports data from an attached sensor to a remote PC client. The programs are written by using the basic Python socket module and thus require a lot of code. Aim: Program:[►] Highlight program codeRemarks: It is recommended to define a simple flag to enter a 'debug mode', where verbose information is written to stdout. Once the program works successfully, the verbose mode can be turned off. Connectify pro activator. The clients just sends a 'go' about every 2 seconds and displays the server reply. Program:[►] Highlight program codeRemarks: |
Experiment 2: Easy coding with an event-driven socket library |
No special knowledge about socket programming is needed, if you use our event-driven tcpcom package (see www.aplu.ch/tcpcom for full information). Download tcpcom.py from here and copy it in the same folder with your program. The code is dramatically simplified while maintaining the same functionality. Program:[►] Highlight program codeRemarks: Program:[►] Highlight program code |
Experiment 3: Accessing a local server from the Internet |
In this experiment we exchange the roles of client and server and run the client on the Raspberry Pi and the server on a PC connected through a WLAN or Ethernet router located anywhere on the Internet.
Aim: If you use the tcpcom library, the programs remain almost the same. The PC server just displays in the console the sensor information received from the client. Program:[►] Highlight program codeThe client code on the Raspberry Pi is simple too. Program:[►] Highlight program codeRemarks: If you do not know the IP address of the router, it is displayed by visiting www.portchecktool.com with a PC browser. As you see, an external server can trace back the route to your router's IP address that is given by your provider and where possibly your name/address is registered. If everything works find, you can move your Raspberry Pi to another place (even far away) and establish an Internet connection from there. You may also acquire an account with no-ip.org, download and run a DUC (Dynamic Update Client) on your PC and access the PC server from the Raspberry Pi with your no-ip IP alias. If you prefer to exchange the roles and use a Raspberry Pi as server and DUC, just do it know. |