XNET CAN frame queue overrun kills Read VI

Hello, I am trying to read CAN frames via XNET. My problem seems to be connected to the queue of my Input session: If the queue gets bombed with random CAN messages from somewhere, the session property "Number of Values Pending" increases rapidly. That's ok, because my program calls XNET Flush before it starts using the bus itself. Otherwise my program would read the old queue content first and the expected reply frames later. This behaviour is ok and expected.
But after I bombed the bus a little bit more so that the queue gets filled to maximal queue size (seems to be predefined as 1000), the Input session read operation will always timeout (tested with 1 second and more) and return an empty frame array. In this case the error wire is s to -1074384886 (timeout). The session always reports tranceiver state "Normal". Even the XNET Flush operation does not help, although it seems to empty the queue properly.
summary: hitting the queue size limit with incoming CAN frames results in dead read operations.

Hello pgraebel,
In the screenshot you posted, NI-XNET will wait 0.1seconds for 1 frame to be present in the queue.  If there is less than 1 fram available, the VI will timeout.  That being said, I would guess that the timeout happens if you ask for many frames (close to the buffer limit), but the timeout is too small.  If you are trying to read 1000 frames, you may need to wait longer than 1 second for the frames to go on the bus.  That really depends on your bus timing/frame timing/etc.
I made a small example to show you a little more how the buffers can be used in XNET.  You can set the buffer size and look at the unused spaces in both the read and write queue.  Let me know if it helps.
O. Proulx
National Instruments
www.ni.com/support
Attachments:
CAN Frame Input Queued.vi ‏37 KB

Similar Messages

  • XNET CAN (frame in)single point issue

    Hi guys,
    I have a problem reading a frame in a single point session. I have this issue now in two different (labview)vi's. In the first a device sends a single frame and I catch it in labview. In the second I send a single point frame from the same vi through another CAN tranceiver and catch this frame in the same vi.
    Sometimes the payload get catched and sometimes(like 5 executions) it's like nothing is received? How can I check raw frame data to know my payload is received?

    You are actually not doing single-point, instead, you are doing Stream Input. This will read into a queue of frames.
    In your while loop, you are doing a Frame CAN read w/o a timeout and a quantity of -1. This means, "return all frames that are currently available". Note, if there are no frames available, this will return an empty array.
    Here is where it gets tricky and you may need to know more about LabVIEW. You have an empty array, and you are then passing that into "index array". If you index an ampty array, you will get get a valid element (since an element cannot be empty) that contains the values of all zeros. This means that the timestamp will have a value of 0 and the payload will be an empty array.
    In the next frame, you are just checking for new timestamp to be different from the old timestamp. If the old timestamp was Feb 8th, 2011 @ 07:03 and the new timestamp is '0', that is indeed different and you will capture that as a frame detection.
    The simple fix would probably be to make frame detection only trigger on "(old != new) && (new != 0)". Note you need to also skip "old = new" in the last frame if you did NOT detect a frame.
    Other possible fixes:
    1. Read for 1 frame with a timeout. This will pause the VI until a frame is actually read.
    2. Since this is a queue (and not single-point), you can read and "frame detect" would just be if the array is not empty. With queues, old data is not repeated, so there would be no frames in this case. This dramatically simplifies your VI.

  • NI-xNET CAN interface Queued/Single Point/Stream

    Hi
    guys, I want to write a known frame on the Bus 1 time an directly after
    want to read a frame with a known Identifier. But only that frame, so
    no other received frames in that time.
    What is the best way or only way?
    Solved!
    Go to Solution.

    Example: Single Point In Session with Termination Set ON
    Attachments:
    CAN Signal Input Single Point with Termination.vi ‏93 KB

  • NI-xNET CAN interface Queued/Sin​gle Point/Stre​am

    Hi guys, I want to write a known frame on the Bus 1 time an directly after want to read a frame with a known Identifier. But only that frame, so no other received frames in that time.
    What is the best way or only way?

    You should post your question to this board.

  • XNET CAN filtering based on payload information of different frames

    Dear all,
    The CAN frames I recieve per cycle are with the following identifiers: 
    [1 frame] 513 (Radar status- range, elevation, target type)
    [1 frame]1536 (Target status - No of targets near field from byte 1 and No of targets far field from byte 2)
    Followed by 96 message pairs of which 1-32 pairs are for near field and 33-96 are for far field.
    1793 (Target Info 1)
    1794 (Target Info 2)
    For the filter, I need to to identify the 1536 frame first and read byte 1 and byte 2 which gives me information about the number near and far targets respectively. 
    Then I need to pick (equal to byte1) number of message pairs from the first 32 pairs and retrieve sigals from that; and then pick (equal to byte2) number of message pairs from then next 64 message pairs and retrive signals. 
    As this plots only the targets that are valuable. I am also looking to create more efficient projects that can be scaled to multiple radars. Any tips for efficient documentation would be much appreciated.
    Kind Regards,
    Red
    Attachments:
    MainRadar.vi ‏129 KB
    radar-.dbc files.zip ‏5 KB

    Hello Red,
    I saw your code. you need do some modifications.
    1. your using STOP vi in ForLoop. when it's true then it will stop your main VI completely. It's like abort button. Instead of that right click on forloop and select Stop terminal.
    2. your passing two index arrays to Forloop (CAN Frames & Search ID Array). if your giving like this, it will always executes based on least array index. So suppose you have 100 frames then it will runs up to 7 times (because your array have 7 elements)
    3. why are taking index from foorloop and again using other loop with Shift registers?  you can take last value directly from your 1st FoorLoop. Right click on the Tunnel and Select Last element.
    4. In your VI, your always clearing your XNET reference. Suppose CAN Frame is not present in next iteration then it wont take previous value. it will give you default value (max- 0)
    Munna

  • CAN Frame Signal Conversion With XNet

    When dealing with CAN, most new developer struggle with the Frame and Channel (or Signal) conversion.  Developers are trying to get away with using the cheapest CAN hardware, and as a result are opting to not use XNet hardware but instead use things like the USB 8473, or using non-NI hardware like the ValueCAN by Intrepid, or using Vector hardware, or CAN to serial adapaters.  The problem with all of these is you generally just read and write frames which is the raw form of CAN.  When using these cheap devices you can't ask the CAN bus what the signal Bus_Voltage is, instead you need to perform a frame read, find the frame associated with the signal, then pull out the bits for that signal, then scale the signal based on the signal selected.
    All of this is doable but a pain and can be very custom.  That's one reason NI came out with the Frame Channel Conversion Library.  This library converts from Frames to Channels using an industry standard CAN database file.  The problem with this library is it hasn't been updated in 5 years, and has known issues which likely will never be fixed.
    NI has since come out with XNet which supports reading and writing signals on XNet hardware.  The XNet drivers also support converting Frames to Signals without needing hardware at all.  This conversion has several limitations, and really only works for getting the latest value for a signal, not all values.  And in addition to that if the signal was never seen, the value will be the defaul value for that signal, not NaN.
    So I wrote a wrapper around the XNet conversion library to handle going from signals to frames, or from frames to signals.  Anyone looking to use a DBC file, on hardware that only supports frame API should use this conversion library, or at least use the XNet conversion sessions.
    CAN Frame Signal Conversion Using XNet 
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

    Hello Hooovahh,
    Nice work  . It’s very useful.
    I’m also converting CAN Raw data to Physical values in my project. Yes, your correct XNET APIs have some limitations. as you mentioned, there is one more limitation I found,
    If your Message Data length (Payload) is 4 Bytes (example) and other CAN Frames are having more than 4 Bytes then its throwing Error (Error Code -1074384737).
    While converting CAN Frames to signals, we will get different Payloads but, our selected signal message have 4 bytes then XNET will gives an error (at the time of Data Conversion).
    As per attached Snap, My Signal is related to IDxBB and I’m sending two different Frames then XNET will not convert.
    Hooovahh Wrote:
    NI has since come out with XNet which supports reading and writing signals on XNet hardware.  The XNet drivers also support converting Frames to Signals without needing hardware at all.  This conversion has several limitations, and really only works for getting the latest value for a signal, not all values.  And in addition to that if the signal was never seen, the value will be the default value for that signal, not NaN.
    When we will send Frame by Frame then we will get all values (not only recent values). XNET will take previous value (if data is not present for Next iteration)
    Please check this snippet for all values & NaN Display.
    Munna

  • Reading CAN frames from 10 sensors Simultaneously

    Hello,
    I have developed a code that reads CAN data frame from the CAN port (PCI CAN/2 series 2 board). The board have 2 CAN ports. I have connected a sensor to one of the ports and reading the CAN frames using my code. I want to use the same code to read CAN frames from 1o sensors simultaneously. Can anyone help me? I have tried creating SUB VI of my code but it reads only one port at a time.    
    Thanks in advance
    Solved!
    Go to Solution.

    Hi Gruenberg,
    I have one question....in my code the while loop interates at 1000ms  i.e.  I want to read CAN data every second (1 value per sec). But when I log this data I see that it gives me 11 values per sec. Because of this my log file is getting very bigger unnnecessarily. I tried to figure it out but couldn't find any solution. Can you tell me why this is happening?
    Please see attached docs.
    Thanks in advance.
    Attachments:
    F2C.jpg ‏291 KB
    CAN0.txt ‏1 KB

  • NI USB CAN 8473 write single frame and log all frame of network with read notification on the same port

    Hello,
    I am trying to code an application which:
    - Write sometime (button click) a frame on a CAN network
    - Log all frame of CAN NETWORK
    My hardware is NI USB 8473 (1 port).
    1/ After reading NI help about CAN APIs, I think it is not possible to do "log all CAN frame" with Channel API because I need to install a asynchronous callback to read all message, and this functionality is only present in frame API.
    Anyone can confirm?
    2/ No problem let's use Frame API
    I have tried "CAN Receive with Notification" example delivered with NI-CAN driver, configured on virtual CAN256.
    I start other sample program to generate some frame on virtual CAN257, no problem, everything is working.
    So, i have tried to modify "CAN Receive with Notification" to add write function. I have mixed this source with "Transmit Receive same Port" sample (which works fine alone on CAN256).
    My program is running, but nothing appens when I click on WRITE button.
    I suppose some attribute are not confired, but which one.
    Anyone can help? (source of my modified sample is joined to this post).
    Thanx.
    PS: please note im a newbie with CAN
    Attachments:
    CAN Receive with Notification.zip ‏10 KB

    Hi,
    Thank you for posting your question on National Instruments' Forums.
    I'm a little puzzled by your question.
    If I understood well, you just want to receive every frame reaching the port and sometime write something through the port. Am I correct ?
    You are right when you state that the NI USB 8473 can only work with frame API. However, if the operation you want to make is the one I discribed above, I can't see where you encounter a difficulty.
    Indeed, for such a case, the example you mentionned in your post is perfectly suited. "Transmit Receive same Port" allows you to receive the frames reaching the port and write we needed too.
    I think this example shoudl do the trick.
    Or have you a more specific application in mind ?
    I hope this information will help you.
    Best regards,
    Guillaume H.
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    >> NIDays 2011, le mardi 8 février au CNIT de Paris La Défense

  • LABVIEW NI-XNET CAN WRITE DELAY

    Hi,
    I am really happy that I can read this article because it seems like it is the similar problem that I am facing right now. I also has a really bad CAN update delay when I want to write Data on CAN bus.  I was trying to following your solusion here, use frame in single point, frame out single point. But I am not so sure that I can continue. In our labview, we use frame in/out stream(sorry the screenshot cut is wrong). But if I want to change it to frame in/out single point, it will show an error saying: mising wiring on NI-XNET block.
    In our labview, we use a big sequence loop. So what in saw in the 1st pic I attached is the first sequence, then in the 2nd sequence we had a Frame Can write frame. Then in the 3rd one, which is in the 2nd pic, it shows the CAN write frame that contain a lot of message that I would like to write on CAN bus.
    The problem here is sometimes the CAN loop takes 0.3s(I use a shift register in the 3rd sequence showing CAN loop time) to update which is too low for me to use Vector Canalyzer to record data. For example, I did a 10 sec test of recording using Canalyzer, it only has 59 values from Labview. 
    In your article it said I need to 'Frame in single point' for my reads, and 'Frame out single point' for my writes. I do know i can use database editor to build a session and define every frame and signal it it. However, I do not know where to put it then? is that connect to NI-XNET write frame? It is the only thing I can think of to do now? But is that meanning all the blocks in the second pic would be deleted.
    Because our grogram is really very very big and it including so many info, I do not think I can post VI. I thought there might be possibility that because of the ''BIG'' thing has something inside that culprit for CAN transmission delay. But I have tried to move  everything except CAN in this loop to another newly built loop. The problem is still there. 
    Thank you so much. 

    You actually always have an XNET database. It's just a matter of whether you use an external database or whether you create objects on the fly.
    From your screenshot, it looks like you are creating objects on the fly using the in memory database.
    Looking at your frame configuration, I was surprised to see Remote frames being configured. Most devices that I've encountered don't use them.
    So what sort of session are you trying to create? Frame Out Stream does not allow for cyclic transmission. You can repeat transmissions using a software loop. If you really have cyclic frames, Frame Out Single Point or Frame Out Queued would work. The post you referred to earlier was using the Frame Out Single Point.
    The XNET help is actually pretty good about breaking down the session modes. From that help, "...  this mode does not repeat its transmit. Unlike the Frame Output Queued mode, the Frame Output
    Stream mode does not use CAN frame properties from the database."
    So if you're using this mode and getting unexpected delays, it's likely due to your sequencing.

  • How can I enable/disable the transmission of a can frame? (filter etc...)

    Hello,
    I use the CAN
    Transmit-periodic.vi in LV 8.5, I want to enable or disable the
    transmission of a frame without stop the loop of my VI, does it exist
    in the frame api a vi which could stop, or mask the transmission of a
    frame?
    It's important I don't want to stop my VI that
    send my frame just filter a frame that I don't want send on my CAN
    bus...(I would command it with a boolean for example).
    Thank you.
    Bye.

    Hi there
    I'm not familiar with NI-CAN, but take a look at
    \vi.lib\Nican\nican.llb\ncAction.vi
    Can be found in the CAN\Frame API\Advanced palette.
    Start Transitions the CAN object from stopped (idle) state to started (running) state. If the CAN object is already started, this operation has no effect.
    Stop Stops the CAN Object. For example, if the CAN Object is configured to transmit data frames periodically, this action stops the periodic transmissions. This action will also clear all entries from the read queue.
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"

  • Xnet convert (frame raw to signal).vi

    I am using the Labview example program "CAN Signals Receive (Host).vi" in Labview 2013 to read CAN information from an NI 9146 ethernet chassis.  I can see that information is being passed to my host computer and through the "CAN Signals Receive" vi until it reaches the sub vi "XNET Convert (Frame Raw to Signal).vi".  When I open this sub vi I can see the data in the "frame data" control, but the "signal data" indicator remains at zero.  Does anyone have any ideas as to why I am not getting any data out?
    Labview 2013
    NI 9146 expansion chassis
    NI 9853 High Speed CAN Module
    Solved!
    Go to Solution.

    Nevermind, figured it out.

  • Advanced CAN Frame to Channel Conversion: Error with LV 8.5.1

    Hello!
    I´ve tried to read in a DBC-file with the "Advanced CAN Frame to Channel Conversion Example" on a LabVIEW 8.5.0 system and it works fine.
    On a LabVIEW 8.5.1 System I get the error:
    Scan From String (arg 6) in CAN FtoC Parse Channels and Mode.vi->CAN FtoC Parse CANdb Messages and Channels.vi->CAN Channel Data Import.vi
    Does anybody know a solution for this error?
    Thank you for your help,
    demo66
    regards,
    demo66

    Hi!
    It is a problem of localized decimal point.
    In a german Windows, LabVIEW will use Komma as decimal point.
    So the Scan From String.vi will convert string 0,21 in a double but not 0.21. From the file dbc you receive the values with period "." that's why it create the error 85.
    You have 2 possibilities: change the localized decimal point in LabVIEW (Tools -> Options) or you say to the Scan From String.vi to use "." as a decimal point.
    Go to CAN FtoC Parse Channels and Mode.vi and search the 2 Scan From String.vi
    Add at the beginning of the Format String %.; so that the format String will use the "." as decimal point (see Attachement).
    After that the example will work.
    Best regards
    Ken
    Attachments:
    Scan From String.jpg ‏51 KB

  • Can't queue a build after upgrading from 2008 to 2012 (TF246021)

    Hi,
    We're trialling an upgrade from TFS 2008 to 2012.4. New TFS has been set up on new hardware with new slq and build boxes. Then we imported 2008 backups and used TFSConfig to import / upgrade them. No errors or warnings where shown.
    Unfortunately we can't queue any builds on the collection. Even a brand new definition in a new team project building "hello world". Builds in other collections work OK.
    The error we're getting is 
    "TF246021: An error occurred while processing your request. Technical information (for administrator): SQL Server Error: 2601"
    Exception Message: Cannot insert duplicate key row in object 'dbo.tbl_BuildQueue' with unique index 'PK_tbl_BuildQueue'. The duplicate key value is (2, 1). (type SqlException)
    SQL Exception Class: 14
    SQL Exception Number: 2601
    SQL Exception Procedure: prc_iiQueueBuilds
    SQL Exception Line Number: 553
    SQL Exception Server: TFSSQL001\INST1
    SQL Exception State: 1
    SQL Error(s):
    Exception Data Dictionary:
    HelpLink.ProdName = Microsoft SQL Server
    HelpLink.ProdVer = 10.50.4000
    HelpLink.EvtSrc = MSSQLServer
    HelpLink.EvtID = 2601
    HelpLink.BaseHelpUrl = http://go.microsoft.com/fwlink
    HelpLink.LinkId = 20476
    Exception Stack Trace:    at Microsoft.TeamFoundation.Framework.Server.TeamFoundationSqlResourceComponent.MapException(SqlException ex, QueryExecutionState queryState)
       at Microsoft.TeamFoundation.Framework.Server.TeamFoundationSqlResourceComponent.HandleException(Exception exception)
       at Microsoft.TeamFoundation.Framework.Server.TeamFoundationSqlResourceComponent.Execute(ExecuteType executeType, CommandBehavior behavior)
       at Microsoft.TeamFoundation.Build.Server.DataAccess.BuildQueueComponent5.QueueBuilds(IEnumerable`1 requests, QueueOptions options)
       at Microsoft.TeamFoundation.Build.Server.TeamFoundationBuildService.QueueBuilds(TeamFoundationRequestContext requestContext, IList`1 requests, QueueOptions options)
       at Microsoft.TeamFoundation.Server.WebAccess.Build.ApiBuildController.QueueBuild(String definitionUri, String controllerUri, String whatToBuild, String shelveset, Nullable`1 checkin, String priority, String dropFolder, String msbuildArgs)
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass42.<BeginInvokeSynchronousActionMethod>b__41()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<>c__DisplayClass39.<BeginInvokeActionMethodWithFilters>b__33()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass4f.<InvokeActionMethodFilterAsynchronously>b__49()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeActionMethodWithFilters>b__36(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<>c__DisplayClass2a.<BeginInvokeAction>b__20()
       at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass25.<BeginInvokeAction>b__22(IAsyncResult asyncResult)
       at System.Web.Mvc.Controller.<>c__DisplayClass1d.<BeginExecuteCore>b__18(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
       at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
       at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
       at System.Web.Mvc.MvcHandler.<>c__DisplayClass8.<BeginProcessRequest>b__3(IAsyncResult asyncResult)
       at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass4.<MakeVoidDelegate>b__3(IAsyncResult ar)
       at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
       at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
       at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
    I found a thread with similar error but it doesn't help us.
    http://social.msdn.microsoft.com/Forums/en-US/ec3f9a9d-0c93-422b-bbc4-959e1e6bfe59/tf246021-an-error-occurred-while-processing-your-request-technical-information-for?forum=TFService
    Any help will be much appreciated.

    Hi Rad,  
    Thanks for your post.
    Daniel provided us the helpful suggestion, please confirm that.
    If install the new Build Service cannot resolve this issue, and according the error message: Cannot insert duplicate key row in object dbo.tbl_BuildQueue with nique…, it seems that this issue relate to your TFS database,
    we suggest you contact a Professional Support Service at
    http://support.microsoft.com/common/international.aspx?RDPATH=gp;en-us;offerprophone to gain more support on this case.  
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Trouble with Simple XNET CAN Example...

    I am trying to get a simple XNET CAN write frame going. Here is the VI I created...
    I keep getting this:
    I looks like I have a frame set up, so what else could be the issue?

    Hey,
    I am "trying" to create a session and send data on the fly. I changed my vi back to the simple one I had earlier in the day:
    Attachments:
    XNET_CAN_Write.vi ‏12 KB

  • IB Queue: Can a Queue be Unordered and Partitioned at the same same time?

    Hi,
    My question is related to Unordered Queue:
    Can a Queue be Unordered and Partitioned at the same same time?
    From PeopleBooks: Managing Service Operation Queues
    "Unordered:
    Select to enable field partioning and to process service operations unordered.
    By default, the check box is cleared and inbound service operations that are assigned to a queue are processed one at a time sequentially in the order that they are sent.
    Select to force the channel to handle all of its service operations in parallel (unordered), which does not guarantee a particular processing sequence. This disables the channel’s partitioning fields.
    Clear this check box if you want all of the queues’s service operations processed sequentially or if you want to use the partitioning fields."
    This seems to indicate that Unordered queues don't use partitioned fields. Yet, there are a few delivered Queues that are Unordered and have one or more Partition fields selected.
    EOEN_MSG_CHNL
    PSXP_MSG_CHNL
    SERVICE_ORDERS
    How does partitioning work in this case? Or is partitioning ignored in such cases?
    Thanks!

    I guess you could use reflection and do something like the following:
    import java.lang.reflect.Constructor ;
    import java.lang.reflect.Method ;
    public class MyClass<T> implements Cloneable {
      T a ;
      public MyClass ( final T a ) {
        // super ( ) ; // Superfluous
        this.a = a ;
      public MyClass<T> clone ( ) {
        MyClass<T> o = null ;
        try { o = (MyClass<T>) super.clone ( ) ; }
        catch ( Exception e ) { e.printStackTrace ( ) ; System.exit ( 1 ) ; }
        o.a = null ;
        //  See if there is an accessible clone method and if there is use it.
        Class<T> c = (Class<T>) a.getClass ( ) ;
        Method m = null ;
        try {
          m = c.getMethod ( "clone" ) ;
          o.a = (T) m.invoke ( a ) ;
        } catch ( NoSuchMethodException nsme ) {
          System.err.println ( "NoSuchMethodException on clone." ) ;
          //  See if there is a copy constructor an if so use it.
          Constructor<T> constructor = null ;
          try {
            System.err.println ( c.getName ( ) ) ;
            constructor = c.getConstructor ( c ) ;
            o.a = constructor.newInstance ( a ) ;
          } catch ( Exception e ) { e.printStackTrace ( ) ; System.exit ( 1 ) ; }
        } catch ( Exception e ) { e.printStackTrace ( ) ; System.exit ( 1 ) ; }
        return o ;
      public String toString ( ) { return "[ " + ( ( a == null ) ? "" : a.toString ( ) ) + " ]" ; }
      public static void main ( final String[] args ) {
        MyClass<String> foo = new MyClass<String> ( "zero" ) ;
        MyClass<String> fooClone = foo.clone ( ) ;
        System.out.println ( "foo = " + foo ) ;
        System.out.println ( "fooClone = " + fooClone ) ;
    }

Maybe you are looking for

  • How do I find albums in the Finder?  Where did they go?

    Just upgraded to iPhoto 06 from 04. When I look for photos in Finder I don't see any of my albums listed. The file structure is totally changed, and I don't even have a folder for 2006 but I do have prior years, which I can then look in to see pictur

  • External Hard Drive won't mount on desktop!

    Hey, guys. I ran into a problem this morning that I've never ran into before and I wasn't sure where to write it but I thought this is best. Here it goes... Last night I had a power surge and when I restarted my computer, my external hard drive did n

  • How can I avoid having "XE index" entries in the pdf bookmarks frame?

    Hi, I try to use RH9 to create a pdf file, but the contents (= bookmarks) frame looks like this: 1 Heading 1 2 XE "Index word 1" /* MERGEFORMAT Heading 2 3 XE "Index word 2" /* MERGEFORMAT XE "Index word 3" /* MERGEFORMAT XE "Index word 4" /* MERGEFO

  • Unnecessary black lines being printed in the printed document

    I have an year old HP M1136 Laser jet printer ( Serial No. - CND8B9QJ65 ) and use orignal HP cartridges. And I use Windows 7 ultimate (32-bit) as my operating system.  I guess, The problem isn't regarding the software. It might have something to do w

  • Deactivation of POWL Query

    Hi, I have unchecked the activated checkbox for one query in POWL_QUERYR. I do not want the query to become visible to users. I have done the changes in Development and found that it becomes invisible to an user only if I delete all entries for the p