Subject:
|
Opening COM port error
|
Newsgroups:
|
lugnet.robotics.rcx.java
|
Date:
|
Fri, 28 Nov 2003 17:21:18 GMT
|
Viewed:
|
5978 times
|
| |
| |
Hi guys,
First of all, thanx Brian, but I managed to solve the weird firmdl.bat problem
by fooling around with different batteries and IR range levels.
Secondly,I'm trying to send data packets to the RCX through java methods called
from a C++ program (I know it's stupid but dont ask why). Here are two
implementations which tells the robot to move forward and backward:
public static void forward( int distance )
{
try {
RCXPort port = new RCXPort();
InputStream is = port.getInputStream();
OutputStream os = port.getOutputStream();
DataInputStream dis = new DataInputStream(is);
DataOutputStream dos = new DataOutputStream(os);
byte[] dt = { 3, (byte)distance};
dos.write(dt);
dos.flush();
}
catch (Exception e) {
}
}
public static void reverse( int distance )
{
try {
RCXPort port = new RCXPort();
InputStream is = port.getInputStream();
OutputStream os = port.getOutputStream();
DataInputStream dis = new DataInputStream(is);
DataOutputStream dos = new DataOutputStream(os);
byte[] dt = { 4, (byte)distance};
dos.write(dt);
dos.flush();
}
catch (Exception e) {
}
}
I know the implementation isnt very elegant but I want to keep the "forward" and
"reverse" methods separate, hence, the almost identical definitions.
Here's the problem: After calling "forward", when I try to call "reverse", I get
a COM port error which says "Error 5:Opening COM5". I'd figure that I need to
close the stream after "dos.flush()" with "dos.close()" before calling "reverse"
but I still have the same problem. I think I need to not only close the stream
but the port as well but I'm not sure of how to do this.
Any ideas anyone? Many thanks.
Tyler
|
|
Message has 1 Reply: | | Re: Opening COM port error
|
| (...) This probably is an issue of leaving your Port object around after you're done using it. You have a memory leak in each routine, because you call 'new RCXPort();' without ever calling 'delete port;' on the object. You should definitely call (...) (21 years ago, 28-Nov-03, to lugnet.robotics.rcx.java)
|
6 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|