The idea of this article beginning when the company I worked now need some utility command to build connectivity between the application which is build in java platform connect to hardware. To gain connectivity to hardware tools we need command line in ASCII code as like this “alt+27, alt+112, alt+48, alt+62, alt+76, alt+80, alt+84, alt+49”, if we use this line syntax using command prompt M$ DOS, before the main command first we must write command “echo” + space followed by these ASCII code, after hit the enter button then command running and hopefully the hardware can response to that command line.
By using this ASCII code list as reference, than we get ASCII code that needed to accessing this hardware:
Be sides of ASCII code that often use in daily programming like in table above, there is another ASCII code is rare used in daily programming, this reference table below is shown ASCII code that represent symbol and line character:
After knowing ASCII code for hardware specification, and now time to figure out how to connect ASCII code to command line in Java, that is using Runtime command from “java.lang.Runtime”, with complete command write like this “Runtime.getRuntime().exec(‘this ASCII code written to be execute’);” with return value class Process from “java.lang.Process” than initialize into “p” object, from that object we can got this command “p.waitFor();” with aiming the system will wait until this command to hardware is come to end, as the following source code as an example how to use ASCII code to Runtime command. But don’t forget to write this line “cmd /c” before “echo” syntax if you try to execute it on windows, to call DOS command prompt.
StringBuffer strNew = new StringBuffer();
strNew.append(new Character((char)27));
strNew.append(new Character((char)112));
strNew.append(new Character((char)48));
strNew.append(new Character((char)62));
strNew.append(new Character((char)76));
strNew.append(new Character((char)80));
strNew.append(new Character((char)84));
strNew.append(new Character((char)49));
Process p = Runtime.getRuntime().exec("cmd /c echo "+strNew.toString());
p.waitFor();
No comments:
Post a Comment