2-way to open the projector: serial port, single board

Source: Internet
Author: User

Package com; </P> <p> Import Java. io. *; <br/> Import java.net. socket; <br/> Import Java. util. *; <br/> Import javax. comm. *; </P> <p>/** <br/> * Mar 26,201 0 <br/> * @ author zcj <br/> * <br/> * in normal and VIP modes: open the projector [via serial port, through PLC] <br/> */</P> <p> public class projector {<br/> static enumeration portlist; <br/> static comatrix ortidentifier portid; <br/> static SerialPort; <br/> static outputstream o Utputstream; </P> <p>/** <br/> * use the serial port to open the projector [connecting the projector to the PC host] <br/> * @ throws exception <br/> */<br/> Public static void openprojectorbyserial (string command) {<br/> try {<br/>/* obtain the enumeration object of the comatrix ortidentifier object */<br/> portlist = comatrix ortidentifier. getportidentifiers (); </P> <p> byte [] bt = new byte [4]; <br/> BT [0] = (byte) 0x43; <br/> BT [1] = (byte) 0x30; <br/> BT [2] = (byte) 0x30; // enable projector [0x30 ], disable cast Instrument [0x31] <br/> BT [3] = (byte) 0x0d; </P> <p>/* iterate this enumeration object */<br/> while (portlist. hasmoreelements () {</P> <p>/* Get A comatrix ortidentifier object */<br/> portid = (comatrix ortidentifier) portlist. nextelement (); </P> <p> If (portid. getporttype () = comatrix ortidentifier. port_serial) {<br/> If (portid. getname (). equals ("COM1") {<br/> // open the communication <br/> SerialPort = (SerialPort) portid. open ("simplewriteapp", 2000); <br/> Seri Alport. setserialportparams (19200, SerialPort. databits_8, SerialPort. stopbits_1, SerialPort. parity_none); </P> <p> // open the output stream and write the command <br/> outputstream = SerialPort. getoutputstream (); <br/> outputstream. write (BT); <br/> outputstream. flush (); </P> <p> outputstream. close (); <br/> SerialPort. close (); <br/>}< br/>}catch (exception e) {<br/> system. out. println ("ear2projector 62 abnormal output when the projector is opened through serial port Now: "+ E. getmessage (); <br/>}finally {<br/> // close the stream and port <br/> try {<br/> If (outputstream! = NULL) {<br/> outputstream. Close (); <br/>}< br/> If (SerialPort! = NULL) {<br/> SerialPort. close (); <br/>}< br/>} catch (exception e) {<br/> system. out. println ("ear2projector 76 exception when closing the port:" + E. getmessage ()); <br/>}</P> <p>/** <br/> * Open the projector on the server. [the projector is not a PC host. connected together, it is connected to the single-host machine.] <br/> */<br/> Public static void openprojectorbyserver () {<br/> Socket socket = NULL; <br/> printwriter OS = NULL; <br/> try {<br/> socket = new socket ("remoteip", 20681); <br/> OS = ne W printwriter (socket. getoutputstream (); </P> <p> OS. write ("$00-001,50"); // open the projector <br/> // OS. write ("$00-001,51"); // disable the projector <br/> OS. flush (); </P> <p> OS. close (); // close the socket output stream <br/> socket. close (); // close socket <br/>} catch (exception e) {<br/> system. out. println ("ear2projector 106 error opening projector with Single Board:" + E. getmessage (); <br/>}finally {<br/> try {<br/> If (OS! = NULL) {<br/> OS. Close (); <br/>}< br/> If (socket! = NULL) {<br/> socket. close (); <br/>}< br/>} catch (exception e) {<br/> system. out. println ("ear2projector 117 exception when closing socket object... "+ E. getmessage (); <br/>}< br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.