This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
uphp:serial_port_programming [2017/02/12 11:45] jeff created |
— (current) | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Serial Port Programming ====== | ||
- | WattmonPRO comes with an RS-232 serial interface on pins 7 and 8 and an RS-485 port on an RJ45 connector. | ||
- | |||
- | ===== Using the RS-232 Serial Port ===== | ||
- | |||
- | To open the serial port, use the [[fseropen|fseropen()]] function. | ||
- | The serial port is treated like a file after opening and standard file functions such as [[fread|fread()]], | ||
- | |||
- | An example of using the serial port is shown below: | ||
- | <code php><? | ||
- | // Open the serial port at 115200 baud in non-blocking mode | ||
- | $fp = fseropen(115200, | ||
- | if (!$fp) { | ||
- | | ||
- | } else { | ||
- | $res = fwrite($fp," | ||
- | if ($res) { | ||
- | | ||
- | } | ||
- | fclose($fp); | ||
- | } | ||
- | ?></ | ||
- | |||
- | ==== Jumper Settings inside Wattmon ==== | ||
- | {{: | ||
- | |||
- | ==== RS-232 Cable Connection ==== | ||
- | In order to connect to a device you will need to procure a DB9 cable (male or female) and connect it up as shown in the following diagram. | ||
- | {{: | ||
- | |||
- | ===== Using the RS-485 Serial Port ===== | ||
- | |||
- | In order to use the RS-485 port, you need to disable modbus polling. | ||
- | |||
- | {{: | ||
- | |||
- | To open the RS-485 port, use the [[f485open|f485open()]] function. | ||
- | The RS-485 serial port is treated like a file after opening and standard file functions such as [[fread|fread()]], | ||
- | |||
- | An example of using the RS-485 serial port is shown below: | ||
- | <code php><? | ||
- | // Open the 485 port at 115200 baud with no parity | ||
- | $fp = f485open(115200, | ||
- | if (!$fp) { | ||
- | | ||
- | } else { | ||
- | $res = fwrite($fp," | ||
- | if ($res) { | ||
- | | ||
- | } | ||
- | fclose($fp); | ||
- | } | ||
- | ?></ | ||
- | |||
- | ==== RS-485 Cable Connection ==== | ||
- | |||
- | Use a standard RJ-45 cable and cut it to connect your RS-485 device to WattmonPRO. | ||
- | ^ PIN ^ Color ^ Description | ||
- | | 1,2 | Orange | ||
- | | 4 | Blue | D+ / A | | ||
- | | 5 | White-Blue | D- / B | | ||
- | |||
- | {{: |