Loading ...
Sorry, an error occurred while loading the content.

428Re: Requesting some Help On the Digital Output

Expand Messages
  • jujames84
    Jun 14, 2010
    • 0 Attachment
      Ok I redid it... This has worked out... I was reading what your said about the in-stream reading...
      [code]
      import com.ridgesoft.intellibrain.IntelliBrain;
      import com.ridgesoft.intellibrain.IntelliBrainAnalogInput;
      import com.ridgesoft.intellibrain.IntelliBrainDigitalIO;
      import javax.comm.SerialPort;
      import java.io.OutputStream;
      import java.io.InputStream;


      public class Main
      {
      /**
      * @param args the command line arguments
      */
      public static void main(String[] args)
      {
      // TODO code application logic here
      try
      {
      IntelliBrainAnalogInput switch1 = IntelliBrain.getAnalogInput(1);
      IntelliBrainAnalogInput switch2 = IntelliBrain.getAnalogInput(2);
      IntelliBrainAnalogInput switch3 = IntelliBrain.getAnalogInput(3);
      IntelliBrainAnalogInput switch4 = IntelliBrain.getAnalogInput(4);
      //IntelliBrainAnalogInput switch5 = IntelliBrain.getAnalogInput(5);
      //IntelliBrainAnalogInput switch6 = IntelliBrain.getAnalogInput(6);
      //IntelliBrainAnalogInput switch7 = IntelliBrain.getAnalogInput(7);
      IntelliBrainDigitalIO led1 = IntelliBrain.getDigitalIO(1);
      IntelliBrainDigitalIO led2 = IntelliBrain.getDigitalIO(2);
      IntelliBrainDigitalIO led3 = IntelliBrain.getDigitalIO(3);
      IntelliBrainDigitalIO led4 = IntelliBrain.getDigitalIO(4);
      //IntelliBrainDigitalIO led5 = IntelliBrain.getDigitalIO(5);
      //IntelliBrainDigitalIO led6 = IntelliBrain.getDigitalIO(6);
      //IntelliBrainDigitalIO led7 = IntelliBrain.getDigitalIO(7);
      led1.setDirection(true);
      led2.setDirection(true);
      led3.setDirection(true);
      led4.setDirection(true);
      //led5.setDirection(true);
      //led6.setDirection(true);
      //led7.setDirection(true);

      SerialPort comPort = IntelliBrain.getCom1();
      InputStream inStream = comPort.getInputStream();
      OutputStream outStream = comPort.getOutputStream();
      int data = 0;

      while((data = inStream.read()) != -1)
      {
      // Switch1 and LED1
      if(switch1.isSet() == true || inStream.read() == 11)
      {
      led1.set();
      outStream.write(1);
      }
      else if(switch1.isSet() == false || inStream.read() == 12)
      {
      led1.clear();
      outStream.write(10);
      }
      // Switch2 and LED2
      if(switch2.isSet() == true || inStream.read() == 21)
      {
      led2.set();
      outStream.write(2);
      }
      else if(switch2.isSet() == false || inStream.read() == 22)
      {
      led2.clear();
      outStream.write(20);
      }
      // Switch3 and LED3
      if(switch3.isSet() == true || inStream.read() == 31)
      {
      led3.set();
      outStream.write(3);
      }
      else if(switch3.isSet() == false || inStream.read() == 32)
      {
      led3.clear();
      outStream.write(30);
      }
      // Switch4 and LED4
      if(switch4.isSet() == true || inStream.read() == 31)
      {
      led4.set();
      outStream.write(4);
      }
      else if(switch4.isSet() == false || inStream.read() == 32)
      {
      led4.clear();
      outStream.write(40);
      }
      }
      }
      catch(Exception error)
      {
      error.printStackTrace();
      }
      }
      }
      [/code]



      --- In intellibrain@yahoogroups.com, "ridgesoft" <rs1@...> wrote:
      >
      > Hi,
      >
      > As described in the API documentation, the getCom1 call "will cause communication between the virtual machine and the host computer to be disabled, giving your program exclusive access to the COM1 port." This means RoboJDE will lose communication with the virtual machine on the IntelliBrain controller. In addition, messages RoboJDE sends to the controller will be received by your program, rather than by the virtual machine running your program. You should shutdown RoboJDE before you start your program if you intend to take control of the COM1 port. Perhaps you are intending to use the other serial port, COM2, which is the one with the 4 pin header at the front edge of the board.
      >
      > Also, the InputStream.read method blocks waiting for characters. Your program will stop in the read method until a character is received. If there are no characters received, your program will not execute. Also, the first read in the while statement appears to read but not use the character it receives. The second read, in the if statement, will only execute if switch1.isSet returns true. So, if switch1 is set the loop will do two reads per iteration. If it is not set the loop will do one read per iteration. I'm not sure this is what you intend.
      >
      > Regards,
      >
      > RidgeSoft Support
      >
      > --- In intellibrain@yahoogroups.com, "jujames84" <jujames84@> wrote:
      > >
      > > I wrote this program that takes an input from the Analog Input (A01) - Hight or Low and then determines what to do next based on an output to the Digital Input 1 (IO1). Now that works fine - Sample Code:
      > >
      > > [code]
      > > import com.ridgesoft.intellibrain.IntelliBrain;
      > > import com.ridgesoft.intellibrain.IntelliBrainAnalogInput;
      > > import com.ridgesoft.intellibrain.IntelliBrainDigitalIO;
      > > import java.io.OutputStream;
      > > import java.io.InputStream;
      > > import javax.comm.SerialPort;
      > >
      > > public class Main
      > > {
      > >
      > > /**
      > > * @param args the command line arguments
      > > */
      > > public static void main(String[] args)
      > > {
      > > // TODO code application logic here
      > > try
      > > {
      > > IntelliBrainAnalogInput switch1 = IntelliBrain.getAnalogInput(1);
      > > IntelliBrainDigitalIO led1 = IntelliBrain.getDigitalIO(1);
      > > led1.setDirection(true);
      > >
      > > while(true /*(data = inStream.read()) != -1*/)
      > > {
      > > // Switch1 and LED1
      > > if(switch1.isSet() == true)
      > > {
      > > led1.set();
      > > // test if it is working
      > > System.out.println("Switch 1 is ON");
      > > }
      > > else
      > > {
      > > led1.clear();
      > > //outStream.write(1);
      > > System.out.println("Switch 1 is OFF");
      > > }
      > >
      > > }
      > > }
      > > catch(Exception error)
      > > {
      > > error.printStackTrace();
      > > }
      > > }
      > >
      > > }
      > >
      > > [/code]
      > >
      > > Ok I modify the code to out the information while reading if there is any information at the same time throught the COM Port 1. But when I do that, the intellibrain is no longer responding through RoboJDE. The real problem is the output is no longer working, because I set up a LED Circuit to test the output and it did work before I added the output.write() COM Port.... Heres my sample:
      > >
      > >
      > > [code]
      > > import com.ridgesoft.intellibrain.IntelliBrain;
      > > import com.ridgesoft.intellibrain.IntelliBrainAnalogInput;
      > > import com.ridgesoft.intellibrain.IntelliBrainDigitalIO;
      > > import java.io.OutputStream;
      > > import java.io.InputStream;
      > > import javax.comm.SerialPort;
      > >
      > > public class Main
      > > {
      > >
      > > /**
      > > * @param args the command line arguments
      > > */
      > > public static void main(String[] args)
      > > {
      > > // TODO code application logic here
      > > try
      > > {
      > > IntelliBrainAnalogInput switch1 = IntelliBrain.getAnalogInput(1);
      > > IntelliBrainDigitalIO led1 = IntelliBrain.getDigitalIO(1);
      > > led1.setDirection(true);
      > >
      > > SerialPort comPort = IntelliBrain.getCom1();
      > > InputStream inStream = comPort.getInputStream();
      > > OutputStream outStream = comPort.getOutputStream();
      > > int data;
      > >
      > > while((data = inStream.read()) != -1)
      > > {
      > > // Switch1 and LED1
      > > if(switch1.isSet() == true && (data = inStream.read()) != 21)
      > > {
      > > led1.set();
      > > outStream.write(0);
      > > }
      > > else
      > > {
      > > led1.clear();
      > > outStream.write(1);
      > > }
      > >
      > > }
      > > }
      > > catch(Exception error)
      > > {
      > > error.printStackTrace();
      > > }
      > > }
      > >
      > > }
      > >
      > > [/code]
      > >
      > > I tried to account for the input data, but as I said the Digital output stopped working (using the LED Circuit Test)
      > >
      >
    • Show all 3 messages in this topic