Ports


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: Ports

  1. #1
    Join Date
    Oct 2004
    Posts
    151

    Question Ports

    Hi everyone,

    I am trying to write some bits to the parallel port using the java communications port and all is okay except that i need some clarification on something.

    The parallel port is connected to circuit board that needs nine inputs(or better known as nine bits)
    Now this is what i am doing to write the values to the parallel port

    Code:
    import javax.comm.*;
    import java.io.*;
     
    public class PortTest 
    {
    ParallelPort port;
    int outputByte = 256;  //The byte value is 100000000
    
    public void outputBits() 
    {
    
    try 
    {
    port.getOutputStream().write(outputByte);
    } 
    
    catch(Exception e) 
    { 
    e.printStackTrace();
    }
      
    }
    
    public static void main(String args[])
    {
    PortTest p1 = new PortTest();
    p1.outputBits;
    }
    
    }
    Now here is my problem, the output stream only seems to output to the first eights bits but does not output the last bit which is a zero. Now i know that a byte is eight bits but if i use a byte array it still does not work.

    Basically my question is that i need to output nine bits but i seem to be able to only output eight bits and would really appreciate some guidance from anyone on this topic.

    Any help is greatly appreciated

    Thank You

    Yours Sincerely

    Richard West
    Last edited by freesoft_2000; 08-07-2005 at 10:34 AM.
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Have you thought of passing a BitSet object and then having your recipient decode the BitSet?

  3. #3
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    The doc for OutputStream.write(int) says that it only writes a byte from the low order 8 bits. I don't see any way to write anything but byte(s). The write(byte[]) method would allow you to write more than one byte.
    I don't know how the 9 bits you want to send would be stripped out of the 16 in 2 bytes.
    Do you have a way to observe what's going out with a write()? Then you could try different arrangements of the 9 bits in the 2 bytes.
    Norm

  4. #4
    Join Date
    Oct 2004
    Posts
    151
    Hi everyone,

    I have a way to monitor this via the circuit connected to the parallel port. Now i can use byte[] because lets say i do this

    Code:
    int i = 1, j = 0;
    byte[] b = new byte[2];
    b[1] =  i.getByte(); //The binary value is 00000001
    b[2] =  j.getByte();//The binary value is 00000000
    
    public void outputBits() 
    {
    
    try 
    {
    port.getOutputStream().write(b);
    } 
    
    catch(Exception e) 
    { 
    e.printStackTrace();
    }
      
    }
    Now what happens is b[1] is outputted from pin 1 - pin 7. Now i was hoping that b[2]
    would output from pin 8 - pin 15 but instead it outputted from pin 1 - pin 7 thus overriding the first value.

    I really not sure of what else to do and would really appreciate any help on this topic

    Any help is greatly appreciated

    Thank You

    Yours Sincerely

    Richard West
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

  5. #5
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Not sure about your example.
    Arrays in Java are zero based. There isn't a b[2].
    Also int is not an Object and has no methods such as getByte().
    The program as shown can't compile or execute.

    You can initialize the byte array as with any other array by putting values in {}:

    byte[] b = new byte[] {1, 0};

    For testing I would suggest using something other than 0 so you can verify that it is working.
    byte[] b = new byte[] {23, 33}; or byte[] b = new byte[] {(byte)'a', (byte)'z'};

    Norm

  6. #6
    Join Date
    Oct 2004
    Posts
    151
    Hi everyone,

    Sorry for the wrong code this is what i did

    I have a way to monitor this via the circuit connected to the parallel port. Now i tried to use byte[] and this is what i have got so far

    Code:
    int i = 1, j = 3;
    
    Integer inti = new Integer(i);
    Integer intj = new Integer(j);
    
    byte[] b = new byte[2];
    b[0] =  inti.byteValue(); //The binary value is 00000001
    b[1] =  intj.byteValue();//The binary value is 00000011
    
    public void outputBits() 
    {
    
    try 
    {
    port.getOutputStream().write(b);
    } 
    
    catch(Exception e) 
    { 
    e.printStackTrace();
    }
      
    }
    Now what happens is b[0] is outputted from pin 1 - pin 7. Now i was hoping that b[1]
    would output from pin 8 - pin 15 but instead it outputted from pin 1 - pin 7 thus overriding the first value.

    I really not sure of what else to do and would really appreciate any help on this topic

    Any help is greatly appreciated

    Thank You

    Yours Sincerely

    Richard West
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

  7. #7
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    I thought that parallel ports sent 1 byte at a time vs serial port sending a bit at a time.
    What you are observing seems to be that byte[0] is sent first and byte[1] is sent next. That is what I'd expect.

    What are the specifications for usages of the 25 pins?

    BTW Using Integer and .getByteValue() seems like the hard way to initialize a byte array.

  8. #8
    Join Date
    Oct 2004
    Posts
    151

    Question

    Hi everyone,

    Quote Originally Posted by Norm
    I thought that parallel ports sent 1 byte at a time vs serial port sending a bit at a time
    Not necessarily, depends on your programming

    Quote Originally Posted by Norm
    What are the specifications for usages of the 25 pins?
    Pin 1 - Strobe
    Pin 2 - Parity
    Pin 3 - Data
    Pin 4 - Data
    Pin 5 - Data
    Pin 6 - Data

    Pin 7 - Request Data
    Pin 8 - Internal Error Check
    Pin 9 - Internal Security

    The rest are don't care bits

    Richard West
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

  9. #9
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Your specs only show 4 bits for data. Pins 3-6. Would that imply that you only send half a byte at a time? I'm only guessing of course. I would think parallel means x bits at a time, while serial only sends 1 bit at a time, a byte taking 8 sends (plus parity).

    With 25 pins, wouldn't there be room for 8 bits of data?

  10. #10
    Join Date
    Oct 2004
    Posts
    151

    Question

    Quote Originally Posted by Norm
    Your specs only show 4 bits for data. Pins 3-6. Would that imply that you only send half a byte at a time? I'm only guessing of course.
    Yes you are right

    Quote Originally Posted by Norm
    With 25 pins, wouldn't there be room for 8 bits of data?
    The circuit was designed with only nine inputs. Its the design of the circuit that i am catering to

    Richard West
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

  11. #11
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Good, now we're making progress. Now you need to determine which 4 bits of a byte are being transmitted when you do a write. Then to write a full byte will take 2 writes. Say it's the lower 4 bits. Write the byte, then shift it to the right 4 bits and write it again.
    If the bits were numbered: 76543210 you would write 3210 on the first write and 7654 on the second.
    What is the reading device expecting? It needs to be in synch with what you're doing,

  12. #12
    Join Date
    Oct 2004
    Posts
    151

    Question

    Hi everyone,

    Quote Originally Posted by Norm
    What is the reading device expecting?
    This is what it is expecting
    Code:
    10xxxx101
    
    x - don't care values
    Th thing is that i have to write the above 9 bits to the parallel port at one go or the circuit would have errors. I can write 8 bits(because its exactly a byte) but what about more than that?

    Any help is greatly appreciated

    Thank You

    Yours Sincerely

    Richard West
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

  13. #13
    Join Date
    Jul 2005
    Location
    SW MO, USA
    Posts
    299
    Your definitions for the pin usages:
    Pin 1 - Strobe
    Pin 2 - Parity
    Pin 3 - Data
    Pin 4 - Data
    Pin 5 - Data
    Pin 6 - Data
    Pin 7 - Request Data
    Pin 8 - Internal Error Check
    Pin 9 - Internal Security

    What values you want written on the pins:
    1=Strobe=1
    2=Parity=0
    3=Data=x
    4=Date=x
    5=Data=x
    6=Data=x
    7=Request Data=1
    8=Internal Error Check=0
    9=Internal Security=1

    Research on web at HowStuffworks site defines the pins as follows:
    1= Strobe >Same as yours BUT not part of data written. IE you don't control the value of this bit.

    2=data0 >Yours is called parity. Being your bit you can put anything here you want.
    3-6 =data1-4 >Same as yours
    7=data5 >Yours is Request Data. Being your bit you can put anything here you want
    8=data6 > Yours Internal Error Check. Being your bit you can put anything here you want
    9=data7 > Yours Internal Security. Being your bit you can put anything here you want

    10=Acknowledge
    ...

    So according to HowStuffworks, when you write a byte on a parallel port, the 8 bits would go out on pins 2-9. I don't know how you can control what is written to pins 1 and 10 thru 25.

    Earlier you said:
    b[0] is outputted from pin 1 - pin 7.
    That's only 7 bits, the write should be outputing 8. Are you sure that only 7 bits are received and not 8 on pins 2 thru 9?

    Bottom line - You can only write 8 bits at a time, on pins 2 thru 9. The other pins are used by the hardware for whatever. If you want to control more than those 8 bits, you'll need your own hardware board on the computer to do the write.

    Who designed this circuit that you're trying to communicate with? Why didn't they know how PC parallel ports work? What is their explanation or expectation?

    Good luck,
    Norm

  14. #14
    Join Date
    Jul 2005
    Posts
    9
    Ignore him, see my last post at DevShed, where I also was conned into giving him extensive advice. He is simply having a laugh at your expense.
    Last edited by NovaX; 08-09-2005 at 12:45 PM.

  15. #15
    Join Date
    Oct 2004
    Posts
    151

    Question

    Hi everyone,

    Quote Originally Posted by Norm
    Research on web at HowStuffworks site defines the pins as follows: 1= Strobe >Same as yours BUT not part of data written. IE you don't control the value of this bit.
    My bit numbers start from 0. So the pin 1 you are talking about is actually pin 0 which i do not write anything too as i do not control it.

    Quote Originally Posted by Norm
    Earlier you said:
    b[0] is outputted from pin 1 - pin 7.
    That's only 7 bits, the write should be outputing 8. Are you sure that only 7 bits are received and not 8 on pins 2 thru 9?
    Sorry its a typo. What i meant is pin 1 - pin 8

    Quote Originally Posted by Norm
    Bottom line - You can only write 8 bits at a time, on pins 2 thru 9. The other pins are used by the hardware for whatever. If you want to control more than those 8 bits, you'll need your own hardware board on the computer to do the write.
    I think i have to ask the designer to redesign this circuit

    Quote Originally Posted by Norm
    Who designed this circuit that you're trying to communicate with? Why didn't they know how PC parallel ports work? What is their explanation or expectation?
    The lead engineer that designed this circuit is fresh out of university as the previous lead engineer retired about a month ago. The new engineer said that all pins of parallel port can be used for communication and it was a programming error and not his. I also had felt something amiss.

    Quote Originally Posted by Norm
    Good luck,
    Norm
    Thanks man as i think i am going to need it.

    Its really been a pleasure interacting with you norm and hope someday i can return the favour

    Thank You

    Yours Sincerely

    Richard West

    ps. Hey novax, why don't go and read the full post at Sun's forum. No one cares dude. Even after he posted that at Sun's site i still got replies on this topic. I have a feeling that novax = sjasja = carpaltunnel, they are the same people as they seem to talk the same way and always harass everyone at Sun's website. Point to note, write them off.

    Sjalle if you are there please erase the second last post(by novax)
    if possible as i feel its a nuisance and a waste of your bandwith
    Last edited by freesoft_2000; 08-09-2005 at 03:57 PM.
    What type of softwares do you like and what would you pay for it?

    http://www.wizardsolutionsusa.com/fo...hread.php?t=12

Similar Threads

  1. Accessing COM ports
    By john_smith in forum .NET
    Replies: 1
    Last Post: 02-20-2003, 06:15 AM
  2. How to monitor which ports are being used?
    By mark erickson in forum .NET
    Replies: 4
    Last Post: 09-14-2002, 07:50 PM
  3. Assigning ports.
    By Chad in forum Java
    Replies: 0
    Last Post: 07-10-2001, 11:36 AM
  4. Serial Ports
    By Timothy Schilbach in forum VB Classic
    Replies: 2
    Last Post: 07-21-2000, 11:47 AM
  5. Serial Ports
    By Timothy Schilbach in forum VB Classic
    Replies: 0
    Last Post: 07-20-2000, 05:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center