====== FHZ1000PC ====== {{fhz1000pc.png|fhz1000pc}} FHZ 1000 PC (and the newer version FHZ 1300 PC) is an interface device between the FS20 radio protocol and a PC via an USB interface. It is sold by Conrad in Sweden (http://www.conrad.se), Germany and probably in many other countries. ===== Hardware ===== {{fhz1000pcopen.png|fhz1000pc inside}} FHZ1000PC has a fairly straight forward structure based on standard components. It is build around a PIC16F628 processor and uses a FT232AM chip from [[http://www.ftdichip.com|FTDI]] for USB communication. Looking at the picture above you will see from right: * Receiver daughter board (with red antenna) * Transmitter daughter board * PIC16F628 processor * FT232AM USB to serial converter * Unknown chip * USB-Connector The software in the PIC-processor communicates with standard asynchronous serial communication with the FT232AM chip using 9600 baud, 1 stop bit and no parity. There are some german sites where they describe how to modify the hardware: * [[http://www.ipsymcon.de/wiki/index.php/Umbau_FHZ1000PC_USB_auf_LAN|Convert to LAN-Interface]] * [[http://www.ipsymcon.de/wiki/index.php/Externe_Sendeantenne_FHZ1xxxPC|Boosted transmitter]] ===== Interfacing ===== The software accompanying the device when purchased from Conrad is unfortunately in German only. To make things even worse, the software has no documented external interface allowing direct access to the device. So we are left to do this interfacing ourselves. Fortunately [[http://www.ftdichip.com|FTDI]] provides both drivers and API:s to their chips for free (they live on selling the chips), so the drivers can be downloaded from their site. Through their drivers we get access to the serial communication with the PIC-processor. The protocol used here has been reversed engineered by [[http://fhz4linux.info/tiki-index.php?page=FHZ1000+Protocol|fhz4linux]]. ===== Interfacing from Windows ===== I want to access the protocol on Windows from Java, but FTDI only supply drivers for C/C++ so I also need some kind of conversion here. I actually considered writing a small C-daemon to talk TCP/IP with, but I found a nice set of Java drivers for the FT232AM-chip (D2XX-drivers) on https://jd2xx.dev.java.net. So I was finally able to write a Java class that represents a FHZ1000PC-device and allow my software to control the FS20 system. ===== Interfacing from Linux ===== Since Java is a platform independent language, we want the software to work for Linux as well. On Linux, there are no specific drivers for this device available but we can still use the fact that there is a standard FTDI-Chip. The trick here is to persuade Linux that this is really just a USB serial device. There are at least three ways of doing this, and they are described on [[http://fhz4linux.info/tiki-index.php?page=Driver+installation| the fhz4linux-site]]. I prefer method number 3, and it has worked fine on my Ubuntu. The Java interface class I have written actually checks which OS it is running under (a bit ugly) and adapts its access methods accordingly. ===== Software on Windows ===== To use the interface you have to do the following steps: * Install the software accompanying the device (this is the easiest way to get the USB drivers installed) * Download the D2XX-java drivers from [[https://jd2xx.dev.java.net/servlets/ProjectDocumentList|jd2xx.dev.java.net]], it is actually the files jd2xx.dll and jd2xx.jar you need. I had to use the 2005-version since I got problems with the 2006-build. * Download my {{:fhz1000pc_829.zip|fhz1000pc}} interface class, and you are all set to talk Java to FHZ1000 PC. This class is used by the [[fhz1000pcport]]-class in the [[:start|NetHomeServer]] ===== Example ===== public class HomeManager { static int houseCode = FHZ1000PC.StringFS20ToInt("11112433"); static byte lamp = (byte)FHZ1000PC.StringFS20ToInt("1113"); static byte button = (byte)FHZ1000PC.StringFS20ToInt("1141"); static FHZ1000PC port; public static void main(String[] args) { try { port = new FHZ1000PC(); port.fs20Init(); // Turn the lamp off port.sendFS20Command(houseCode, lamp, FHZ1000PC.COMMAND_OFF); port.registerEventListener(new FS20EventListener(){ public void fs20Event(FS20Event event){ if ((event.getHouseCode() == houseCode) && (event.getButton() == button)){ try { // If I receive a command from the button, resend it to the lamp port.sendFS20Command(houseCode, lamp, event.getFunction()); } catch (IOException e){ e.printStackTrace(); } } } }); Thread.sleep(10000); } catch (IOException e){ e.printStackTrace(); } catch (InterruptedException e){ e.printStackTrace(); } } }