Go to Post FIRST is aimed at those girls on your team. They don't know anything about mechanics, or electricity, or programming, or machining. They have no interest in it, either. They're perfect candidates for FIRST. - Madison [more]
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 26-11-2011, 00:25
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Toggling RS232 RTS pin on WinXP machine using Java


Hello Java-on-Windows gurus.

Is there a simple way, in Java, to access an RS232 port on a WinXP machine for the sole purpose of toggling the RTS pin?

Reply With Quote
  #2   Spotlight this post!  
Unread 26-11-2011, 00:52
rrossbach rrossbach is offline
Registered User
AKA: Ron R
FRC #2607 (RoboVikings)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Warrington PA
Posts: 90
rrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to behold
Re: Toggling RS232 RTS pin on WinXP machine using Java

It's not as simple as using c/c++ and the win32 api - it's been a while since Sun/Oracle have supported a Java serial communications API on Windows. But it can be done if you track down the necessary drivers/libraries - try starting with RXTX

If you're not constrained to use Java, it's probably simpler/faster to use the win32 api with c/c++, or the serialport api in .NET

Hope that helps....feel free to PM me if questions

- Ron
Team #2607 controls mentor
__________________

FIRST Mid-Atlantic Volunteer
FRC Team #2607 Mentor
Reply With Quote
  #3   Spotlight this post!  
Unread 26-11-2011, 01:29
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Toggling RS232 RTS pin on WinXP machine using Java


Thanks, but... All I want to do is allocate an RS232 port, and toggle the RTS pin.

I don't need a full serial port library with transmit and receive interrupts and buffers and XON/XOFF and RTS/CTS handshaking protocols and baud rate, parity, etc etc etc.

All I want to do is toggle the RTS pin. Isn't there a simple way to do this?



Reply With Quote
  #4   Spotlight this post!  
Unread 26-11-2011, 09:58
rrossbach rrossbach is offline
Registered User
AKA: Ron R
FRC #2607 (RoboVikings)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Warrington PA
Posts: 90
rrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to behold
Re: Toggling RS232 RTS pin on WinXP machine using Java

Using Java on Windows, that is the simple way

Joking aside, the issue is that serial comms isn't part of the "core" Java libraries - it's an extension - so isn't part of the standard JDK distribution. That means that without the additional library/driver, you don't have any way to access the serial port hardware in the Java runtime - even just to do something simple like toggle RTS.

That's why you need the additional library/driver like RXTX. Even though you don't need the full comms library functionality, you need it to get access to the serial port hardware.

- Ron
Team #2607 controls mentor
__________________

FIRST Mid-Atlantic Volunteer
FRC Team #2607 Mentor
Reply With Quote
  #5   Spotlight this post!  
Unread 26-11-2011, 10:22
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,077
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Toggling RS232 RTS pin on WinXP machine using Java

Quote:
Originally Posted by rrossbach View Post
without the additional library/driver, you don't have any way to access the serial port hardware in the Java runtime - even just to do something simple like toggle RTS.

That's why you need the additional library/driver like RXTX. Even though you don't need the full comms library functionality, you need it to get access to the serial port hardware.
My question is this: why do I need a full comms library... why can't I just do a Windows API call to allocate a serial port, and then another API call to toggle the RTS?

If the question seems naive, it's because I know very little about Java, and I've never looked at the Windows API... this question is based on what I've done in other contexts with other APIs.

Thanks.


Reply With Quote
  #6   Spotlight this post!  
Unread 26-11-2011, 14:26
rrossbach rrossbach is offline
Registered User
AKA: Ron R
FRC #2607 (RoboVikings)
Team Role: Mentor
 
Join Date: Nov 2008
Rookie Year: 2008
Location: Warrington PA
Posts: 90
rrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to beholdrrossbach is a splendid one to behold
Re: Toggling RS232 RTS pin on WinXP machine using Java

Quote:
Originally Posted by Ether View Post
... why can't I just do a Windows API call to allocate a serial port, and then another API call to toggle the RTS?

If the question seems naive, it's because I know very little about Java, and I've never looked at the Windows API... this question is based on what I've done in other contexts with other APIs.
No problem, sorry my explanations are a little incomplete. This is one of those cases where a simple question yields a reasonably complex answer.

You don't have direct access to the Windows API in the out-of-the-box Java environment like you do in C, C++, etc. That's because one of Java's goals is platform-independence, and platform-independence means there are extra layers of abstraction between your java code and the operating system. Your java code can only access underlying "native" functions that the intervening layers expose for you via the Java API. This wikipedia article may help picture it a bit better.

To help illustrate further, instead of accessing the serial port let's say you want to read a file in a Java program. You would use something like FileReader in the Java API to open and access the file. The implementation of the FileReader API on whatever platform you're using (Windows, Linux, etc) takes care of mapping the Java API to whatever native functions are needed. That's why each platform (Windows, Linux, etc) has it's own JDK implementation - so your Java code can run across them without changing (at least in theory )

It so happens that FileReader is part of the out-of-the-box Java environment, so you don't need to install anything extra to do file i/o in Java. However, that's not the case with the serial port API (JavaComm). JavaComm isn't included out-of-the-box, so you need an extra library (like RXTX) that implements JavaComm or a similar API on the platform you want to use.

As an alternative, there is also a general-purpose "native access" API called JNA that opens up direct access to native code. You could use that to directly access the Windows API functions you need (like EscapeCommFunction) provided you're already familiar with the Windows API.

But the point is you still need some additional library (RXTX, JNA, etc) to do this in Java. And if you're going to end up writing direct calls to the underlying Windows API at the end of the day anyway, it may be simpler to just use .NET, or C, etc.

Hope that helps, sorry for the long explanation. There's lot's of additional material available out there in the google-sphere as well.

- Ron
Team #2607 controls mentor
__________________

FIRST Mid-Atlantic Volunteer
FRC Team #2607 Mentor
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 22:19.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi