|
If you have no background in computing then I would suggest you start with Visual Basic. Have a look at these tutorials[^] and see how you get on.
|
|
|
|
|
|
zero.zero wrote: I suggest you start with SMALL BASIC
Good suggestion, I had forgotten about that.
|
|
|
|
|
Personally i suggest Java, because there are plenty of tutorials and it is completely free and easy to learn. I have recently began programming Java and i eally enjoy it!!!
|
|
|
|
|
Ok anybody go any good links some PDF Format tutorails for Java???????
|
|
|
|
|
|
|
Why not try the "source" of all Java --- www.java.sun.com? They have tutorials for everything in Java!
AF Pilot
|
|
|
|
|
i have tried the Java.Sun site but they dont get to the point quick enough .
|
|
|
|
|
TGeist wrote: they dont get to the point quick enough
Wrong. If you look in the right place, they get to the point. Also the important, nay huge, point that needs to be made is that all the tutorials start with the basics and build up from there. What a stupid idea, you wouldn't create a java application that way...
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
hi guys,
can anyone send me the name of J2EE books which are good and easy to understand.
|
|
|
|
|
I would start with this book[^]. Google a bit to get it.
|
|
|
|
|
hello
sir help me in this regards,i vl waiting for ur positive reply.
Your task is to create a programming system for a ferry. The ferry transports passengers and vehicles (cars, busses, lorries and bicycles). The ferry has space for 200 passengers and 40 cars. A lorry need as much space as two busses or 8 cars. A car need as much space as 5 bicycles. There are different fees for different vehicles and an extra fee might be added for passengers. Use the following fees:
1. Passenger without vehicle, 20 kr.
2. Bicycle 40 kr (passenger included).
3. Car 100 kr + 15 kr/passenger. (maximum 4 passengers)
4. Bus 200 kr + 10 kr/ passenger. (maximum 20 passengers)
5. Lorry 300 kr + 15 kr/ passenger. (maximum 2 passengers)
Every type of vehicle (car, bus, lorry, bicycle) will inherit from the class Vehicle. The functionality of the ferry is given by the interface Ferry :
public interface Ferry {
int countPassengers(); // Number of passengers on board
int countVehicleSpace(); // Used vehicle space. One car is 1.
int countMoney(); // Earned money
Iterator iterator(); // Vehicle iterator
void embark(Vehicle v); // Embark vehicle, warning if not enough space
void embark(Passenger p); // Embark passenger, warning if not enough room
void disembark(); // Clear (empty) ferry. The money earned remains,
// i.e., is not reset to zero
boolean hasSpaceFor(Vehicle v); // true if we can embark vehicle v
boolean hasRoomFor(Passenger p); // true if we can embark passenger p
String toString(); // Nice looking ferry status print out
}
A vehicle cannot leave the ferry until the ferry has been disembarked and the same vehicle cannot embark twice. The ferry iterator should iterate over all vehicles embarked (not the passengers). Also write a test program FerryMain.java, embarking a number of vehicles and passengers, showing the functionality of the methods.
# Exercise 2 (Getting Started with JUnit)
In this exercise we provide you with two classes. DataNetwork is a utility class, used in a real life project, to convert sequences of bytes (comming from the network) into Java data types. DataNetworkTest contains the tests for the previous class. Your task is:
1. Create a new project in Eclipse.
2. Configure the project to use JUnit 4 (see above).
3. Copy this two file (you will need to create the package da2222 first).
4. Execute the test and see the green bar.
5. Uncomment the second assertEquals and see the red bar. :'(
6. Make it green!
7. Append a small comment in the getShort() javadoc explaining what happened.
DataNetwork.java
package da2222;
/**
* Utility class to retrieve data from a byte array (in network format).
*/
public class DataNetwork {
/**
* Get the byte in the specific offset.
*/
public static byte get(byte[] data, int offset) {
return data[offset];
}
/**
* Get the short in the specific offset. Big endian
*/
public static short getShort(byte[] data, int offset) {
return (short) (get(data, offset) << 8 | get(data, offset + 1));
}
}
DataNetworkTest.java
package da2222;
import static org.junit.Assert.*;
import org.junit.*;
public class DataNetworkTest {
@Test
public void testGetShort() {
byte[] data = new byte[] {(byte) 0x00, (byte) 0x20, (byte) 0x84};
assertEquals(0x0020, DataNetwork.getShort(data, 0));
//assertEquals(0x2084, DataNetwork.getShort(data, 1));
}
}
# Exercise 3 (Writing JUnit Tests)
In your first assignment, Exercise 7, you implemented a class Arrays.java containing a number of methods that manipulated integer arrays. The task is now to implement a JUnit test (ArraysTest.java) for the class, verifying the correctness of each method.
# Exercise 4 (Generics and JUnit)
In your first assignment, Exercise 12, you provided a class that implemented a simple Queue interface.
1. Convert your implementation (both the interface and the class implementing it) to a generic Queue.
2. Write a JUnit test (QueueTest.java) for the generic Queue implementation that verifies the correctness of each method in the interface. Remember to test also the "extreme cases" (operations on an empty Queue, add a huge amount of elements...).
|
|
|
|
|
Air,Food,Water,and Google absolute necessities for life.
If you did not nail down the OO assignment from last time then go over it again. For JUNIT follow these:
1.Sun[^]
2. eclipse guide[^]
3. Others[^]
Good luck
|
|
|
|
|
hello,
Please suggest an idea of implementing a dictionary program in Java using collections.
Thanks
|
|
|
|
|
|
Hi there,
I am trying to get my swing panel to show a tooltip with the x,y coordinates of the point of the mouse location - whenever the mouse is sat at the location for 1 second or more.
Obviously this means that the tooltip invokation needs to respond to a mouse event of some sort.
THE CODE BENEATH IS THE PART OF MY PANEL CONSTRUCTOR:
//Register for mouse events on panel.
ScreenMouseListener myListener = new ScreenMouseListener();
addMouseListener(myListener);
addMouseMotionListener(myListener);
//THIS IS MY MOUSELISTENER CLASS...AND I NEED TO INVOKE THE TOOLTIP FROM HERE?
private class ScreenMouseListener extends MouseInputAdapter {
public void mousePressed(MouseEvent e) {
printOutput("Mouse Pressed", e);
isNearBlip(e);
}
private void isNearBlip(MouseEvent e) {
for (Point p1 : CurrentDisplayedAircraft) {
double x1 = p1.getX();
double y1 = p1.getY();
double x_dif=Math.abs(e.getX()-x1);
double y_dif=Math.abs(e.getY()-y1);
x_dif=Math.pow(x_dif, 2);
y_dif=Math.pow(y_dif, 2);
double sep=Math.sqrt(x_dif+y_dif);
//DISPLAY A TOOL TIP IF CLOSE TO THE POINT
if(sep<15){
//NEED TO CREATE A TOOLTIP SHOWING PROPERTIES
//OF P1 HERE...
}
}// end of for (ScreenTrajectory S : DisplayPositions) {
}
public void mouseReleased(MouseEvent e) {
printOutput("Mouse Released", e);
}
public void mouseMoved(MouseEvent e) {
printOutput("Mouse moved", e);
}
public void mouseDragged(MouseEvent e) {
printOutput("Mouse dragged", e);
}
public void mouseClicked(MouseEvent e) {
printOutput("Mouse Clicked", e);
}
void printOutput(String eventDescription, MouseEvent e) {
System.out.println(eventDescription
+ " (" + e.getX() + "," + e.getY() + ")"
+ " detected on "
+ e.getComponent().getClass().getName()
+ NL);
}
}
|
|
|
|
|
|
Sorry i cant see the example? iS it the remote control or the recording example and how do i get hold of source?
Thanks
|
|
|
|
|
All the projects have it to find source use ctrl-f source easy right?
|
|
|
|
|
Hi guys,
I have a problem in the following simple program of mine stated below. It's a simple program which enables the sending/receiving of messages(in bytes) from one PC to another. I'm sending the messages to Serial Comm ports R232 with Rxtcomm library.
There are two classes namely; serialCommMain and Comms.
serialCommMain is the GUI portion while Comms is the serial port comm portion.
I'm trying to send the messages over to another application in VB 6.0 in the other PC, as my other PC is using Windows 95 and unable to have java installed.
Although my other PC is able to verify that data is being sent through, the message isn't being displayed. The VB application I've created is working properly.
Kindly need help/assistance. thanks.
The code is as follows:
serialCommMain:
<br />
<small><br />
package SerialComm;<br />
import org.apache.commons.io.EndianUtils;<br />
<br />
public class serialCommMain extends JFrame{<br />
<br />
int indx = 9;<br />
static double number;<br />
static String Ans;<br />
private static final long serialVersionUID = 1L;<br />
static Container pane;<br />
<br />
static Insets insets;<br />
<br />
static JTabbedPane Menu = new JTabbedPane();<br />
<br />
Comms C1;<br />
<br />
<br />
<br />
public Timer timer;<br />
public int speed = 500;<br />
<br />
<br />
<br />
public byte[] BytetxtMsg;<br />
public byte[] readMsg = new byte[400];<br />
static JButton BtnTransmit;<br />
static JButton BtnPause;<br />
byte START_BYTE = (byte) 0xAA;<br />
byte Checksum;<br />
<br />
<br />
static JTextArea txtRx, txtTx;<br />
<br />
static JPanel Rx = new JPanel();<br />
static JPanel Tx = new JPanel();<br />
static TitledBorder Tx_Rx, Tx_Tx;<br />
<br />
<br />
static JLabel lblENT, lblDEC;<br />
static JFormattedTextField Entry;<br />
static JTextField Decipher;<br />
static JPanel ENT = new JPanel(new BorderLayout());<br />
static TitledBorder D_ENT;<br />
<br />
static JPanel DEC = new JPanel(new BorderLayout());<br />
static TitledBorder D_DEC;<br />
<br />
<br />
public serialCommMain() {<br />
super();<br />
BytetxtMsg = new byte[indx];<br />
<br />
}<br />
<br />
<br />
<br />
public static void main(String[] args) {<br />
showGUI();<br />
<br />
}<br />
<br />
public static void showGUI(){<br />
<br />
<br />
<br />
<br />
<br />
<br />
JFrame frame = new JFrame("Serial Comm.");<br />
frame.setSize(800, 600);<br />
frame.setLocation(150,50);<br />
<br />
<br />
pane = frame.getContentPane();<br />
insets = pane.getInsets();<br />
pane.setLayout(null);<br />
<br />
<br />
Tx_Rx = BorderFactory.createTitledBorder(Tx_Rx, "Receive Message: ", TitledBorder.LEFT, <br />
TitledBorder.CENTER, new Font("Verdana", Font.BOLD, 10));<br />
<br />
txtRx = new JTextArea(10,30);<br />
txtRx.setEditable(false);<br />
<br />
<br />
Rx.add(txtRx);<br />
Rx.setBorder(Tx_Rx);<br />
pane.add(Rx);<br />
<br />
<br />
Tx_Tx = BorderFactory.createTitledBorder(Tx_Tx, "Transmit Message: ", TitledBorder.LEFT, <br />
TitledBorder.CENTER, new Font("Verdana", Font.BOLD, 10));<br />
<br />
txtTx = new JTextArea(10,30);<br />
txtTx.setEditable(false);<br />
<br />
<br />
Tx.add(txtTx);<br />
Tx.setBorder(Tx_Tx);<br />
pane.add(Tx);<br />
<br />
<br />
<br />
lblENT = new JLabel("Transmit: ");<br />
lblENT .setFont(new Font("Verdana", Font.BOLD, 10));<br />
<br />
D_ENT = BorderFactory.createTitledBorder(D_ENT, "TX: ", TitledBorder.LEFT, <br />
TitledBorder.CENTER, new Font("Verdana", Font.BOLD, 10));<br />
<br />
<br />
Entry = new JFormattedTextField(Entry);<br />
Entry.setValue(new Double(number));<br />
Entry.setColumns(10);<br />
Entry.addPropertyChangeListener("value", new ButtonListener());<br />
<br />
<br />
<br />
<br />
ENT.add(Entry, BorderLayout.EAST);<br />
ENT.add(lblENT, BorderLayout.WEST);<br />
ENT.setBorder(D_ENT);<br />
pane.add(ENT);<br />
<br />
<br />
<br />
<br />
lblDEC = new JLabel("Received: ");<br />
lblDEC .setFont(new Font("Verdana", Font.BOLD, 10));<br />
<br />
D_DEC = BorderFactory.createTitledBorder(D_DEC, "RX: ", TitledBorder.LEFT, <br />
TitledBorder.CENTER, new Font("Verdana", Font.BOLD, 10));<br />
<br />
<br />
Decipher = new JTextField(25);<br />
Decipher.setEditable(false);<br />
<br />
DEC.add(Decipher, BorderLayout.EAST);<br />
DEC.add(lblDEC, BorderLayout.WEST);<br />
DEC.setBorder(D_DEC);<br />
pane.add(DEC);<br />
<br />
<br />
<br />
BtnTransmit = new JButton("Transmit");<br />
BtnTransmit.setFont(new Font("Verdana", Font.BOLD, 10));<br />
pane.add(BtnTransmit);<br />
BtnTransmit.addActionListener(new ButtonListener());<br />
<br />
BtnPause = new JButton("Pause");<br />
BtnPause.setFont(new Font("Verdana", Font.BOLD, 10)); <br />
pane.add(BtnPause);<br />
BtnPause.addActionListener(new ButtonListener());<br />
<br />
<br />
<br />
Rx.setBounds(insets.left+5, insets.top+5, Rx.getPreferredSize().width, Rx.getPreferredSize().height);<br />
Tx.setBounds(Rx.getX()+400, Rx.getY(), Tx.getPreferredSize().width, Tx.getPreferredSize().height);<br />
ENT.setBounds(Rx.getX(), Rx.getY()+200, ENT.getPreferredSize().width, ENT.getPreferredSize().height);<br />
DEC.setBounds(Tx.getX(), Tx.getY()+200, DEC.getPreferredSize().width, DEC.getPreferredSize().height);<br />
<br />
BtnTransmit.setBounds(ENT.getX(), ENT.getY()+ 150, BtnTransmit.getPreferredSize().width, BtnTransmit.getPreferredSize().height);<br />
BtnPause.setBounds(BtnTransmit.getX()+ 120, BtnTransmit.getY(), BtnPause.getPreferredSize().width, BtnPause.getPreferredSize().height);<br />
<br />
frame.addWindowListener(new WindowAdapter(){<br />
public void windowClosing(WindowEvent e){<br />
System.exit(0); <br />
}<br />
});<br />
<br />
frame.setVisible(true);<br />
}<br />
<br />
<br />
}<br />
<br />
class ButtonListener extends serialCommMain implements ActionListener, PropertyChangeListener{<br />
<br />
<br />
private static final long serialVersionUID = 1L;<br />
<br />
public ButtonListener(){<br />
<br />
<br />
timer = new Timer(); <br />
<br />
BytetxtMsg[0]= START_BYTE;<br />
}<br />
<br />
TimerTask Trx = new TimerTask(){<br />
<br />
<br />
public void run() {<br />
<br />
C1 = new Comms(); <br />
<br />
try{ <br />
C1.sendBytes(BytetxtMsg); <br />
} catch (Exception e) {<br />
System.err.println("ERROR: " + e.getMessage());<br />
}<br />
<br />
<br />
}<br />
};<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
public void actionPerformed(ActionEvent E) {<br />
Object Src = E.getSource();<br />
<br />
<br />
<br />
<br />
<br />
<br />
if (Src == BtnTransmit){<br />
<br />
timer.scheduleAtFixedRate(Trx, 100, speed);<br />
<br />
number = ((Number)Entry.getValue()).doubleValue();<br />
<br />
System.out.println(number);<br />
EndianUtils.writeSwappedDouble(BytetxtMsg, 2, reverse(number));<br />
} <br />
}<br />
<br />
public static double reverse(double x) {<br />
ByteBuffer bbuf = ByteBuffer.allocate(8);<br />
bbuf.order(ByteOrder.LITTLE_ENDIAN);<br />
bbuf.putDouble(x);<br />
bbuf.order(ByteOrder.BIG_ENDIAN);<br />
return bbuf.getDouble(0);<br />
}<br />
public void propertyChange(PropertyChangeEvent Evt) {<br />
<br />
<br />
} <br />
<br />
} <br />
</small>
Comms:
<br />
<small><br />
<br />
package SerialComm;<br />
<br />
public class Comms extends serialCommMain implements SerialPortEventListener {<br />
private CommPortIdentifier commPortId;<br />
private SerialPort serialPort;<br />
private OutputStream outStream;<br />
private InputStream inStream;<br />
private byte[] readBuffer = new byte[400];<br />
int SIZE; <br />
String S;<br />
int DisplayLen = 0;<br />
public Comms(){<br />
<br />
super();<br />
<br />
try{<br />
<br />
<br />
connect("COM2");<br />
}catch (Exception e) {<br />
System.err.println("ERROR: " + e.getMessage());<br />
<br />
}<br />
<br />
}<br />
<br />
public void connect(String portName) throws IOException {<br />
try {<br />
<br />
commPortId = CommPortIdentifier.getPortIdentifier(portName);<br />
<br />
<br />
serialPort = (SerialPort) commPortId.open(this.getClass().getName(), 2000);<br />
<br />
setSerialPortParameters();<br />
<br />
outStream = serialPort.getOutputStream();<br />
inStream = serialPort.getInputStream();<br />
<br />
<br />
} catch (NoSuchPortException e) {<br />
throw new IOException(e.getMessage());<br />
} catch (PortInUseException e) {<br />
throw new IOException(e.getMessage());<br />
} catch (IOException e) {<br />
serialPort.close();<br />
throw e;<br />
}<br />
<br />
<br />
}<br />
<br />
public void sendBytes (byte[] bytes)<br />
{<br />
try<br />
{<br />
<br />
SIZE = indx;<br />
for(int i = 0; i< SIZE; i++){ <br />
S = Integer.toString(ByteConversion(bytes[i]), 16) + " ";<br />
txtTx.append(S.toUpperCase());<br />
DisplayLen = txtTx.getLineCount();<br />
<br />
}<br />
<br />
<br />
txtTx.append("\n");<br />
<br />
if (DisplayLen > 8){<br />
txtTx.setText("");<br />
}<br />
<br />
<br />
outStream.write (bytes, 0, bytes.length);<br />
}<br />
<br />
catch (IOException e)<br />
{<br />
System.out.println("IOException" + e);<br />
} <br />
}<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
private void setSerialPortParameters() throws IOException {<br />
int baudRate = 9600;
<br />
try {<br />
serialPort.setSerialPortParams(<br />
baudRate,<br />
SerialPort.DATABITS_8,<br />
SerialPort.STOPBITS_1,<br />
SerialPort.PARITY_NONE);<br />
<br />
serialPort.setFlowControlMode(<br />
SerialPort.FLOWCONTROL_NONE);<br />
} catch (UnsupportedCommOperationException ex) {<br />
throw new IOException("Unsupported serial port parameter");<br />
}<br />
}<br />
<br />
public int ByteConversion(byte mySignedByte){<br />
<br />
ByteBuffer bb = ByteBuffer.allocate(4);<br />
<br />
bb.put(new byte[] {0, 0, 0, mySignedByte});<br />
<br />
bb.rewind();<br />
<br />
int unsignedByteVal = bb.getInt();<br />
<br />
return unsignedByteVal;<br />
<br />
}<br />
<br />
<br />
<br />
<br />
public void disconnect() {<br />
<br />
if (serialPort != null) {<br />
try {<br />
outStream.close();<br />
inStream.close();<br />
} catch (IOException ex) {<br />
}<br />
serialPort.close();<br />
serialPort = null;<br />
}<br />
}<br />
<br />
<br />
private void readSerial() {<br />
<br />
<br />
try {<br />
int availableBytes = inStream.available();<br />
if (availableBytes > 0) {<br />
inStream.read(readBuffer, 0, availableBytes);<br />
<br />
txtRx.append("Received :" +<br />
new String(readBuffer, 0, availableBytes));<br />
}<br />
} catch (IOException e) {<br />
}<br />
}<br />
<br />
<br />
public void serialEvent(SerialPortEvent event) {<br />
switch (event.getEventType()) {<br />
<br />
case SerialPortEvent.BI:<br />
<br />
case SerialPortEvent.OE:<br />
<br />
case SerialPortEvent.FE:<br />
<br />
case SerialPortEvent.PE:<br />
<br />
case SerialPortEvent.CD:<br />
<br />
case SerialPortEvent.CTS:<br />
<br />
case SerialPortEvent.DSR:<br />
<br />
case SerialPortEvent.RI:<br />
<br />
case SerialPortEvent.OUTPUT_BUFFER_EMPTY:<br />
break;<br />
<br />
case SerialPortEvent.DATA_AVAILABLE:<br />
readSerial();<br />
<br />
break;<br />
}<br />
} <br />
<br />
<br />
}<br />
</small>
The errors I've got:
<small><br />
<br />
1500.0
<br />
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 9<br />
at org.apache.commons.io.EndianUtils.writeSwappedLong(EndianUtils.java:209)<br />
at org.apache.commons.io.EndianUtils.writeSwappedDouble(EndianUtils.java:263)<br />
at SerialComm.ButtonListener.actionPerformed(serialCommMain.java:303)<br />
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)<br />
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)<br />
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)<br />
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)<br />
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)<br />
at java.awt.Component.processMouseEvent(Unknown Source)<br />
at javax.swing.JComponent.processMouseEvent(Unknown Source)<br />
at java.awt.Component.processEvent(Unknown Source)<br />
at java.awt.Container.processEvent(Unknown Source)<br />
at java.awt.Component.dispatchEventImpl(Unknown Source)<br />
at java.awt.Container.dispatchEventImpl(Unknown Source)<br />
at java.awt.Component.dispatchEvent(Unknown Source)<br />
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)<br />
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)<br />
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)<br />
at java.awt.Container.dispatchEventImpl(Unknown Source)<br />
at java.awt.Window.dispatchEventImpl(Unknown Source)<br />
at java.awt.Component.dispatchEvent(Unknown Source)<br />
at java.awt.EventQueue.dispatchEvent(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)<br />
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)<br />
at java.awt.EventDispatchThread.run(Unknown Source)<br />
Stable Library<br />
=========================================<br />
Native lib Version = RXTX-2.1-7<br />
Java lib Version = RXTX-2.1-7<br />
ERROR: SerialComm.Comms<br />
ERROR: null<br />
ERROR: SerialComm.Comms<br />
ERROR: null<br />
<br />
<br />
<br />
</small>
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
Too much code, not enough information.
What problem are you having? Do you get a compilation failure? Do you get an exception at runtime? Does it run but not do anything?
Just saying "I have a problem" is too vague. The more specific you can be, the more people will be able to help you.
|
|
|
|
|
Download[^]
Use winrar to get to the .jar and two .dll files
Copy the .jar to jre/lib/ext and the two .dll two jre/bin
Then I want you two run this code:
Code 1:
import gnu.io.*;
public class demo
{
public static void main(String[] args)
{
listPorts();
}
static void listPorts()
{
java.util.Enumeration<CommPortIdentifier> portEnum = CommPortIdentifier.getPortIdentifiers();
while ( portEnum.hasMoreElements() )
{
CommPortIdentifier portIdentifier = portEnum.nextElement();
System.out.println(portIdentifier.getName() + " - " + getPortTypeName(portIdentifier.getPortType()) );
}
}
static String getPortTypeName ( int portType )
{
switch ( portType )
{
case CommPortIdentifier.PORT_I2C:
return "I2C";
case CommPortIdentifier.PORT_PARALLEL:
return "Parallel";
case CommPortIdentifier.PORT_RAW:
return "Raw";
case CommPortIdentifier.PORT_RS485:
return "RS485";
case CommPortIdentifier.PORT_SERIAL:
return "Serial";
default:
return "unknown type";
}
}
}
Code 2:
public static HashSet<CommPortIdentifier> getAvailableSerialPorts() {
HashSet<CommPortIdentifier> h = new HashSet<CommPortIdentifier>();
Enumeration thePorts = CommPortIdentifier.getPortIdentifiers();
while (thePorts.hasMoreElements()) {
CommPortIdentifier com = (CommPortIdentifier) thePorts.nextElement();
switch (com.getPortType()) {
case CommPortIdentifier.PORT_SERIAL:
try {
CommPort thePort = com.open("CommUtil", 50);
thePort.close();
h.add(com);
} catch (PortInUseException e) {
System.out.println("Port, " + com.getName() + ", is in use.");
} catch (Exception e) {
System.err.println("Failed to open port " + com.getName());
e.printStackTrace();
}
}
}
return h;
}
Post your results from both codes.
Good luck
|
|
|
|
|
Ok , fellas. Let me rephrase my question.
My problem is that I can detect my ports and the connection works over the two PCs. However, when I tried to send data over to the other PC, the message being sent over looks something like "@.pp...." in my output, which is incorrect. I wanted the output to be in hex, something like
"AA BC 25 EE AC...".
Any suggestions?
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|
Ok , fellas. Let me rephrase my question.
My problem is that I can detect my ports and the connection works over the two PCs. However, when I tried to send data over to the other PC, the message being sent over looks something like "@.pp...." in my output, which is incorrect. I wanted the output to be in hex, something like
"AA BC 25 EE AC...". I'm quite new to java.
Any suggestions?
DA: http://www.pohcbsonic.deviantart.com/
Blog: http://www.pohcbsonicx.blogspot.com/
Homepage: http://www.pohcbsonic.tripod.com/
|
|
|
|
|