How do I control a serial port using PHP? Typically PHP is used to generate web pages by interrogating a database and files. However PHP can also be used to control and communicate with other devices. This article explains how to configure PHP in order to send and receive data over a serial port on a unix system or a windows system. Prerequisites. PHP installed on your computer. An installed Brainboxes Serial port product.
Steps In Brief. Install PHP Direct IO extension. Configure PHP to use the extension. Use PHP file provided in the downloads. Open terminal program at other end of serial connection. Configure PHP file with correct local serial port settings. Go! In- depth. Install PHP Direct IOPHP by default does not offer good COM port support however a PHP extension called Direct IO does offers low level access to IO. Back to RPi Advanced Setup. The serial port is a low-level way to send data between the Raspberry Pi and another computer system. There are two main ways in which it. The Raspberry Pi is an amazing 35 dollars mini-computer. It allows you to do everything you could do with a regular Linux computer (Connecting to the internet. Project Moved. New home (starting with V3.0): moved to github: https://github.com/pyserial/pyserial; docs: https://pyserial.readthedocs.org/en/latest/. Serial Communication – RS232 Basics. In the previous post, we discussed about the basics of serial communication. In this post, we will learn about the RS-232. A detailed step by step tutorial guide to PHP HTML5 video streaming with definitive instructions and complete PHP code references with Amazon S3 support. Nero Platinum Suite combines dozens of programs in an ingenious package - burn, copy, edit, stream, rip and convert. We will use this extension for serial port communication. On unix system install the extension using PECL, open a terminal and type: sudo pecl install dio- 0. On windows download the latest php direct io extension dll from: http: //pecl. The dll file should be copied into your php. To the bottom of the php. Simple circuits and examples to describe how to use PC parallel port as general purpose output port. Unix: extension=dio. Windows: extension=php. Navigate to the file the a web browser to confirm that an error is not produced which tells you to install PHP Direct IO. Open terminal program at other end of serial connection. In order to test sending and receiving serial data in PHP, the other end of the serial port should be open. On a windows system we recommend using Putty and on Mac OSX Cool. Term (see this FAQ for more details) to configure a serial for for transmitting and recieving data. We also recommend opening the other side of the serial connection in the terminal initially to confirm that data is definitely able to be sent and received across the connection. Configure PHP file with correct local serial port settings. The sample script has some settings to be configured at the top, most importantly the port name. Windows the port name should be 'com. X: ' (X being the port number assigned name must be lower case and a colon at the end) this can be found by opening Device Manager. Unix systems the port name is '/dev/cu. XXXXXXXXX' where 'X' is a randomly assigned id. To find all the names of Brainboxes serial ports installed on UNIX type ls /dev/cu. Go! In a Web Browser open the file, the other end of the serial port should show 'HELLO WORLD!'. Then type into the terminal on the other end of the connection, this will be echoed back onto the web browser window. Important note: PHP Direct IO does not currently implement a timeout on reads and is blocking. What this means is that if there is no data present when the read method is called then PHP will block (halt) until data is received or the PHP execution time is reached. Links. PHP Direct IO manual - http: //www. Serial Communication - RS2. Basics » max. Embedded. Serial Communication – RS2. Basics. In the previous post, we discussed about the basics of serial communication. In this post, we will learn about the RS- 2. This is the protocol you will be using the most when involving microcontrollers like AVR. As we proceed ahead in this post, we will deal with the concept of level conversion and towards the end, we have something interesting and practical for you – the loopback test! Contents. RS- 2. 32 Basics. RS- 2. 32 (Recommended Standard – 2. Electronic Industries Association (EIA) for connecting serial devices. In other words, RS- 2. RS- 2. 32 is the interface that your computer uses to “talk” to and exchange data with your modem and other serial devices. The serial ports on most computers use a subset of the RS- 2. C standard. RS- 2. DB9 port (commonly known as serial port), however earlier it was used over the DB2. We will have a look at both of them here. RS- 2. 32 over DB- 9. The pin configuration of DB- 9 port is as follows. Yes, it looks exactly like (in fact it is) the serial port you would find in older computers. RS2. 32 DB9 Connector. DB9 Connector Pins. The pin description for the RS- 2. DTR (data terminal ready): When terminal is turned on, it sends out signal DTR to indicate that it is ready for communication. DSR (data set ready): When DCE is turned on and has gone through the self- test, it assert DSR to indicate that it is ready to communicate. RTS (request to send): When the DTE device has byte to transmit, it assert RTS to signal the modem that it has a byte of data to transmit. CTS (clear to send): When the modem has room for storing the data it is to receive, it sends out signal CTS to DTE to indicate that it can receive the data now. DCD (data carrier detect): The modem asserts signal DCD to inform the DTE that a valid carrier has been detected and that contact between it and the other modem is established. RI (ring indicator): An output from the modem and an input to a PC indicates that the telephone is ringing. It goes on and off in synchronous with the ringing sound. Rx. D (Received data): The Rx. D pin is the Data Receive pin. This is the pin where the receiver receives data. Tx. D (Transmitted data): The Tx. D pin is the Data Transmit pin. This is the pin through which data is transmitted to the receiver. RS- 2. 32 over DB- 2. The pin configuration of DB- 2. Yes, it looks exactly like the parallel (printer) port that you would find in older computers! It is however worth noting that the DB- 2. RS- 2. 32) or parallely. The pinouts are different in each case. The pinout for RS- 2. DB- 2. 5 is shown below (thanks Thomas and Aaron for clarification). RS2. 32 DB2. 5 Connector. DB2. 5 Connector Pins. As we can see, most of the pins are similar to that of a DB9 port. If you notice, we see that in DB2. Tx. D and Rx. D pairs of pins. Now what does this mean? In simple words, it means that serial communication through the DB- 2. Thomas!). NOTE: Another important thing to note is that the simplest way to in which a microcontroller can communicate to a PC is through Rx. D, Tx. D, and Ground Pins. And this is what we will be doing here and hence forth in upcoming posts. The other pins are not of much use to us, for now. Now this was something about RS- 2. Our next topic is level conversion. Btw, have you heard of TTL? Sounds familiar, but what is TTL? Lets read on! Logic Level Families. By . Various logic levels have been standardized, out of which the most popular ones are: 1. TTLTTL stands for Transistor- Transistor Logic. These days TTL is the most widely used logic. TTL is mostly used in ICs and gates, like 7. A major drawback of the TTL logic is that most of the devices working on the TTL Logic consume a lot of current, even individual gates may draw up to 3- 4 m. A. In TTL Logic, a HIGH (or 1) is +5 volts, whereas a LOW (or 0) is 0 volts. LVTTLLVTTL stands for Low Voltage Transistor- Transistor Logic. LVTTL is increasingly becoming popular these days, because of the nominal HIGH voltages, and hence lesser power consumption. By lowering the power supply from 5v to 3. There are several transistors and gates, which work on LVTTL logic. Atmel’s Atmega microcontrollers are designed to work on both, LVTTL and TTL, depending upon the VCC supplied to the IC. In LVTTL Logic, a LOW is defined for voltages 0. V ~ 1. 2. V, and High for voltages 2. V ~ 3. 3. V, making 1. V~2. 2. V undefined. RS- 2. 32. RS2. 32 is also one of the most popular logic. Though now quite old, it is still in use. In RS- 2. 32 logic, a HIGH (1) is represented within - 3. V ~ - 2. 5 V, whereas a LOW (0) is in between +3. V ~ +2. 5 V, making - 3. V to +3. V undefined. Weird isn’t it? Apart from these, there are many other logic families like ECL, RTL, CMOS, LVCMOS, etc. At present, we are not much concerned about them. You can refer to this article to know more about them. Level Conversion – TTL/RS2. So what is (logic) level conversion?? To interconnect any two logic level families, their respective HIGHs and LOWs must be same else they wouldn’t work. For example, when we want to interconnect two devices, one of which works over TTL and the other over RS2. HIGH of TTL (which is 3. HIGH of RS2. 32 (which is - 3v ~ - 2. LOW of TTL (0v~0. RS2. 32 (which is +3v ~ +2. So you see, here lies the problem! If we do not convert the logic levels (in this case) then the LOW signal of TTL would be interpreted as a HIGH in RS2. The Solution. One solution is to use additional pull- up resistors, or to use Zener diodes. A better solution is the use of ICs that directly converts logic levels. Luckily logic level conversion is quite simple these days with the use of ICs like MAX2. CP2. 01. 2! We would talk about all these solutions one by one. Zener Diodes. Zener diodes are widely used to regulate voltage between two points. When Zener diode is used in reverse bias in series with a suitable resistor, and a voltage > breakdown voltage is applied across the terminals of the Zener- resistor pair, then a voltage V = Zener Voltage appears across the terminals of the Zener diode, while the rest of the voltage appears across the terminals of the resistor. The simple circuit below shows how to use Zener diodes to convert logic levels from TTL to LVTTL (Note that this circuit is only applicable for high to low logic level conversions): Bidirectional Logic level converters are easily available in the market. Some of the websites selling them are: Adafruit, Freetronics, Sparkfun, Embedded Market etc. IC MAX2. 32. MAX2. ICs were invented by Maxim. These IC packages are used to convert TTL/CMOS logics to RS2. All we need are some passive components, and we are done! Below is the circuit diagram of the MAX2. IC. Level Conversion using MAX2. MAX2. 32 is used to convert TTL to RS2. But these days, USB is the most used protocol! Everything runs on USB – be it printer, scanner, displays or anything! But how to convert USB to UART? One way is USB . The other way is to use USB- UART bridges which directly convert USB . They are widely and easily available these days. Here are some of the websites: Robokits, e. Xtreme Electronics, Sparkfun, Adafruit etc. All these devices work on CP2. USB- UART conversions. IC CP2. 10x. CP2. ICs made by Silicon Labs. These are used to directly convert USB to UART. Below is the circuit schematic of CP2. CP2. 10. 1 Schematics. Though these ICs are not available in DIP Packages, so it is always advisable to buy any one of the modules listed above. This is how a CP2. USB- UART Bridge looks like. The drivers of CP2. They work with the Windows platform. Drivers for Mac and Linux are also available. We will discuss a little later in the same post as to how to install these drivers and work with them. This was all about what is logic level conversion, why we need it, and how to do it. Now its enough of theoretical topics, lets have something practical stuff to do now! Next, we deal how to use the serial communication devices with your PC. So get your PC and USB- UART bridge ready! That’s all you need. Loopback Test. A Loopback Test in serial communication is a test in which we check whether the Rx and Tx are working properly or not. How we do it? Just short the Tx and Rx pins of the USB- UART Bridge and connect it to your PC! So it’s like transmitting data from your PC and receiving the same through the same port! Have a look at the following block diagram. Loopback Test Setup for USB- UART Bridges. Loopback Test Block Diagram. Using a Serial Terminal at PC/Mac. So far so good. You have made the hardware connections. How do you send serial data from your PC (via USB) to any other device? Well, seems like now is time to deal with serial terminals! What is a serial terminal? A serial terminal is an application, which allows you to directly control the serial ports of your PC/Mac i. Bingo! For various applications, it is best to have a serial terminal. For example, you want to communicate to an AVR microcontroller, or say you wanna control a microcontroller through your PC (a cool example would be control a robotic car wirelessly using your computer, it would be like real world NFS! We organized one such event last year as well !!), so how would you do that? Yes exactly! You will use a serial terminal on your PC! Another example could be when you want to use a module, say for example, a GSM module, or a Bluetooth module with your PC. You can communicate with those modules only with the help of these serial terminals! A number of serial terminals are available, both for Windows and Unix. The most popular ones for Windows are: Realterm, Pu. TTy, ZOC Terminal, Terminator etc. The most popular ones for Mac OS X are: Coolterm, i. Term, Terminator, ZOC terminal etc. For Linux, one such application XTerm comes along with the package. As we can see, some of them are cross- platform terminal emulators.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
August 2017
Categories |