Thread: Java Help
View Single Post
  #8   Spotlight this post!  
Unread 11-01-2012, 00:21
frasnow's Avatar
frasnow frasnow is offline
Software
no team
Team Role: Mentor
 
Join Date: Jun 2010
Rookie Year: 2010
Location: Oregon
Posts: 83
frasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to beholdfrasnow is a splendid one to behold
Re: Java Help

I compared the source code for WPILib 2011 & 2012 and the developers changed the constructors for all the I/O to use
Code:
ConstructorName(int moduleNumber, int channel)
instead of the old
Code:
ConstructorName(int slot, int Channel)
The module number is not the same as the slot (OK it is for the first Analog module). The first digital I/O module located in slot 2 of the cRIO is actually module 1. In an 8 slot cRIO digital I/O module 2 should be placed in slot 6. Considering that the signatures of the old constructors and the new ones are the same, I can see lots of veteran teams making this mistake. Even if it is documented somewhere (I haven’t checked). The exceptions being thrown by WPILib don’t have the most helpful error messages in this regard.

Team 997 was also seeing the exception “Solenoid channel 1 on module 3 is already allocated", which makes it sound like our code had allocated solenoid channel 1 twice. We made it work by using the simple constructor where only the channel is specified. A better error message could have saved us time. The error really should say something about 3 being an invalid module number and suggest using 1 or 2 (The solenoid module in slot 3 is module 1). In fact the incorrect exception message actually appears to be masking an only slightly more useful exception CheckedAllocationException("Index " + index + " out of range");. Hiding an exception with one that gives false information is a bad programming practice.

Another way to fix this problem in WPILib would be to deprecate the old constructor and add a new one with a different signature. You can only have one of each module type, so a Boolean value would work for the module number.
Code:
ConstructorName(boolean isModuleOne, int Channel)
Reply With Quote