Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JDBC sending commands through RxTx

Have Programming Question? Ask it here!
 
 
 


Duhit Choudhary
sending commands through RxTx
0 Answer(s)      2 years ago
Posted in : JDBC


i am trying to call lightOn and LightOff method from NewSerialWriter's run() method but not able to make the correct logic. please help me with this. here is my code of different classes.

package newRelay_3088;

import gnu.io.CommPort; import gnu.io.CommPortIdentifier; import gnu.io.SerialPort; import java.io.InputStream; import java.io.OutputStream; import java.util.*;

public class LightController {

public LightController() throws Exception
{
    super();

    CommPortIdentifier commPortIdentifier = CommPortIdentifier.getPortIdentifier("COM12");

    if(commPortIdentifier.isCurrentlyOwned())
    {
        System.out.println("Error: Port is currently in use");
    }
    else
    {
        CommPort commPort = commPortIdentifier.open(this.getClass().getName(), 2000);

        if(commPort instanceof SerialPort)
        {
            SerialPort serialPort = (SerialPort) commPort;
            serialPort.setSerialPortParams(19200, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

            InputStream in = serialPort.getInputStream();
            OutputStream out = serialPort.getOutputStream();

            (new Thread(new NewSerialReader(in))).start();
            (new Thread(new NewSerialWriter(out))).start();
        }
        else
        {
             System.out.println("Error: Only serial ports are handled by this example.");
        }
    }
}

public static void main(String[] args)
{
    try
    {
        new LightController();
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }

    Lights light_1 = new Lights("00000001");

    Lights light_2 = new Lights("00000002");

    Lights light_3 = new Lights("00000004");

    Lights light_4 = new Lights("00000008");

    Lights light_5 = new Lights("00000016");

    Lights light_6 = new Lights("00000032");

    Lights light_7 = new Lights("00000064");

    Lights light_8 = new Lights("00000128");

    HashMap<Integer, Lights> lightList = new HashMap<Integer, Lights>();

    lightList.put(1, light_1);
    lightList.put(2, light_2);
    lightList.put(3, light_3);
    lightList.put(4, light_4);
    lightList.put(5, light_5);
    lightList.put(6, light_6);
    lightList.put(7, light_7);
    lightList.put(8, light_8);

    lightList.get(1).lightOn(); 
}

}


package newRelay_3088;

import java.io.IOException; import java.io.OutputStream;

public class Lights{ OutputStream out; String str;

public Lights(String str)
{
    this.str = str;
}

public void lightOn()
{
    // code for light on goes here
    System.out.println(str);
    try
    {   
        String hexString = String.format("%02X", Integer.parseInt(str));
        System.out.println("HexSting : " + hexString);
        System.out.println(hexString.length());
        String command = "!012" + hexString + "\r";
        System.out.println(command);
        System.out.println(command.getBytes());
        out.write(command.getBytes());
        System.out.println("-----------------------1-------------------------");
        int c = 0;
        while((c = System.in.read()) > -1)
        {
            System.out.println("-----------------------2-------------------------");
            this.out.write(c);
        }
    }
    catch ( IOException e )
    {
        e.printStackTrace();
    }
}

public void lightOff(int sequenceNo)
{
    // code for light off goes here
    try
    {

        String hexString = String.format("%02X", Integer.parseInt(str));
        System.out.println("HexSting : " + hexString);
        System.out.println(hexString.length());
        String command = "!012" + hexString + "\r";
        System.out.println(command);
        out.write(command.getBytes());
        System.out.println("-----------------------1-------------------------");
        int c = 0;
        while((c = System.in.read()) > -1)
        {
            System.out.println("-----------------------2-------------------------");
            this.out.write(c);
        }
    }
    catch ( IOException e )
    {
        e.printStackTrace();
    } 
}

public void getLightStatus()
{
    // method for getting the current status of all the lights
    // code goes here
}

}


package newRelay_3088;

import java.io.IOException; import java.io.InputStream;

public class NewSerialReader implements Runnable{

InputStream in;

public NewSerialReader(InputStream in)
{
    this.in = in;
}

public void run()
{
    byte[] buffer = new byte[1024];
    int length = -1;

    try
    {
        while((length =this.in.read(buffer)) > -1 )
        {
            System.out.print(new String(buffer, 0, length));
        }
    }
    catch ( IOException e )
    {
       e.printStackTrace();
    } 
}

}


package newRelay_3088;

import java.io.IOException; import java.io.OutputStream;

public class NewSerialWriter implements Runnable{ public OutputStream out;

public NewSerialWriter(OutputStream out) 
{
    this.out = out;
}

public void run() 
{

}

} please help ,e with this. also tell me where else my logic is not right. i sm trying to send 8 different commands to a relay to switch on and off the lights and at the same time continuously checking the status... thanks a ton in advance.


Advertisement
View Answers

Related Tutorials/Questions & Answers:
sending commands through RxTx
sending commands through RxTx  i am trying to call lightOn and LightOff method from NewSerialWriter's run() method but not able to make the correct... me where else my logic is not right. i sm trying to send 8 different commands
Sending images through java mail
Sending images through java mail  Am trying to develop greeting application that having images..... in one jsp page i displayed all images and by clicking one image the control go to mail sending page in that the image should add
Advertisements
How to use AT Commands with J2ME?
How to use AT Commands with J2ME?  How to use AT Commands with J2ME? Thank you for your answer
execute dos commands
execute dos commands  how to execute dos commands using a java program
What is the use of DBCC commands?
What is the use of DBCC commands?  What is the use of DBCC commands?   Hi, DBCC stands for database consistency checker. We use these commands to check the consistency of the databases, i.e., maintenance, validation
Implementing voice commands
Implementing voice commands  Am trying to write a java program to implement voice commands within a windows platform using preferably java (though any language will do). I would be glad for any tips and procedures that would help
MySQL Commands
MySQL Commands       In this section, we are going to read about the mysql commands. Each... of commands. To see list of mysql commands, you type help or \h on the mysql>
sending mails - JSP-Servlet
sending mails  my intension is sending mails through java program with out installing any softwares.what is code
Servlet os running commands issues - Development process
Servlet os running commands issues  hello, i want the help regarding the running os commands through servlet. so please send it either on my personal email address or send it on the rose india servlet tutorial. thanx n
Difference between TRUNCATE and DELETE commands
Difference between TRUNCATE and DELETE commands  hii, What is the difference between TRUNCATE and DELETE commands?   hello, TRUNCATE is a DDL command whereas DELETE is a DML command. TRUNCATE is much faster than
Mysql Date Commands
Mysql Date Commands       Mysql Date Commands illustrate the list of commands for retrieving current... illustrate an example from 'Mysql Date Commands'. To understand this example, we use
sending mail using jsp
sending mail using jsp  please give me the detailed procedure and code for sending mail through jsp program   Please visit the following links: http://www.roseindia.net/ejb/introduction/j2eedemo.shtml http
java mail sending with images
java mail sending with images  I need to send images through java mail without giving content path(i.e. we don't want hard code the image path)can you tell me the idea?   Please visit the following links: http
sending mail - JSP-Servlet
sending mail  Hi, what is the code for sending mail automatically without user intervention? thanks in advance
Some Common Types of FTP Commands
it is important to know some common types of FTP commands. Though, many FTP commands are different in different commands but some of the commands are same regardless of the computer or operating system. Some commands are executed without any
sending mails - JSP-Servlet
sending mails   sending mail using smtp protocal ,while running,i got error an javax.mail.sendfailed exception. what is this error
sending automatic email - JavaMail
sending automatic email  Dear sir. In my project i need to send an automatic email to the clients when their accounts are going to expire in 30... date and through a trigger it will send a message to the particular client
sending emails - JavaMail
sending emails  what is the code for sending emails in java  Hi Friend, Please visit the following link: http://www.roseindia.net/javamail/ Hope that it will be helpful for you. Thanks
chown, chgrp commands in java - Java Beginners
chown, chgrp commands in java  Hello: I used chgrp and chown two commands in java to change files properties like String exFile = "/home/camera/www/onlineview/46/*.jpg"; try { Runtime rt = Runtime.getRuntime
sending data to facebook
sending data to facebook  how to post data into facebook from a java program
Common SQL Commands
Common SQL Commands    SQL commands...). Here are a list of SQL commands. 1. DML COMMANDS INSERTUPDATESELECTDELETE... Ajay  The commands are based on this table: 1. DML COMMANDS
Sending email without authentication
Sending email without authentication  Hi sir, Am doing a project in JSP, in that i want to send mail without any authentication of password so send.../mail/sending-an-email-in-jsp.shtml
Sending File - JSP-Servlet
Sending File  How to use tag in Jsp, & How read a file fom Client  Hi Friend, We used tag to upload a file. Please visit the following links: http://www.roseindia.net/jsp/fileupload.shtml http
sending a mail - JSP-Servlet
sending a mail   I m writing a code for send mail in jsp,i sending a mail to specified receiver but if i attach an file and send a mail then i m getting an error. Here Attachment is in String[] Attachment=null so how
the commonly used unix commands like date ls cat etc. are stored in
the commonly used unix commands like date ls cat etc. are stored in  the commonly used unix commands like date ls cat etc. are stored
sending a zip file to servlet
sending a zip file to servlet  I have created a .zip file in a servlet on the local system(no static ip). The .zip file contains xml files. I have to send it to another servlet which is in a server(has a static ip). I have done
Sending Emails In Java
Sending Emails In Java  I want to send emails from within a java program. I saw some online java programs to do that, but they needed me to enter a smtp server, but i don't know what that should be. Can someone please help
Sending Emails In Java
Sending Emails In Java  I want to send emails from within a java program. I saw some online java programs to do that, but they needed me to enter a smtp server, but i don't know what that should be. Can someone please help
Sending Emails In Java
Sending Emails In Java  I want to send emails from within a java program. I saw some online java programs to do that, but they needed me to enter a smtp server, but i don't know what that should be. Can someone please help
for sending project build
for sending project build  hello I want to send my iphone project build to someone else how can i send it...   yes you can send but Follow the steps on the portal to creating an ad hoc build and certificate. Look
iphone mail sending problem
iphone mail sending problem  Hi, I'm receiving the following error ... while sending mail in my iphone application Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[viewController
regarding sending mesage - JavaMail
regarding sending mesage  i have tried the following program /* import java.util.*; import javax.mail.*; import javax.mail.internet.*; import... me in this regard   Hi friend, I am sending you a link
sending sms from laptop to mobile
sending sms from laptop to mobile   sending sms from laptop to mobile for multi users
sending sms from laptop to mobile
sending sms from laptop to mobile   sending sms from laptop to mobile for multi users
Sending mail - JavaMail
Sending mail  Need a simple example of sending mail in Java  Hi,To send email you need a local mail server such as apache james. You first...) { to = newTo;}}Thanks  Java Code for sending messages(text or multimedia
Sending an email in JSP
Sending an email in JSP       Sending an email in JSP In this section, you will learn how to send an email in jsp.   Following is a simple JSP page for sending
Sending emails and insert into trable
Sending emails and insert into trable  I have created a form, once people submit it should go to the email and insert to table also, the second part is working, but it's not getting to configured email. the code is below, I'm I
sending email code - JSP-Servlet
sending email code  How To Send Emails using jsp  Hi friend, I am sending you a link. This link will help you. Please visit for more information. http://www.roseindia.net/mail/sending-an-email
sending doc files - Swing AWT
sending doc files  how to send doc file using java from one machine to other over a network
sending sms with help of java - JavaMail
sending sms with help of java  hi can u plz help me to learn how to send sms with help of java. waiting for your reply
Sending SMS From Java Programs
Sending SMS From Java Programs  I want to develop and application to send sms from my computer, can someone please help me, like tell me where to start and what i need
Sending email with read and delivery requests
Sending email with read and delivery requests  Hi there, I am sending emails using JavaMail in Servlets on behalf of a customer from the website, and I'm having difficulty understanding how to implement, read and delivery
code for sending email using j2me
code for sending email using j2me  could someone tell me why when i try to compile this line using netbeans 7.1 Properties property... for sending a file attachment to gmail account
Sending mail (Contact Form in a website)
Sending mail (Contact Form in a website)  Hi, I just uploaded few of my webpages into a free web hosting service, where i can just upload the web pages. Am very much new into this field. I want to write a contact form, which
sending email using smtp in java
sending email using smtp in java  Hi all, I am trying to send and email to through my company mail server. Following is my code package com.tbss; import javax.mail.*; import javax.mail.internet.*; import
Email sending in jsp - JSP-Servlet
Email sending in jsp  Hi, Im trying to send email from my jsp... i've already tried a sample code from google, for sending email to my office 'smtp... attached the whole coding as below: For input :index.jsp Sending
Sending query with variable - JSP-Servlet
Sending query with variable   While displaying pages in frames concept, one page contains links and other page contains messages for that links. The links page is not static one. Links page displays the contents from
sending mail with attachment in jsp - JSP-Servlet
sending mail with attachment in jsp  Hi Experts
SMS sending questions using java - MobileApplications
SMS sending questions using java  am doing project sending SMS from pc.how to send bulk SMS ?i achive sending single SMS .but i would like to send bulk SMS.am using mobile phone for sending SMS.is it possible sending bulk SMS
automatically resend when connection lost in sending email
automatically resend when connection lost in sending email  send automatically email when connection lost in sending bulk email using javamail for exp more than 10000 emails
Advertisements
 

 

 

DMCA.com