ChipObject and VC++

i have a problem in compiling an RLP example program
/* ChipObject and DIO 96 example program */
and i think its a linker error...
do i need dll or something to work this out
or files in my project are incorrect?
Files included in my VC++ project:
digex2.cpp // Digital Example 2, RLP example for DIo 96 board
osiBus.cpp
osiUserCode.cpp
tDIO96.cpp
// no header files included in my project all other files are in the project directory
// such as:
// osiBus.h
// osiTypes.h
// tDIO96.h
// t8255.h
// /nimdbg/trace.h /* i think this is for trace object*/
// /nimdbg/tStatus2.h
other external dependencies like visa.h
i have set the INCLUDE DIRECTORY:
C:\PROGRAM FILES\NATIONAL INSTRUMENTS\CVI70\INCLUDE
error i get from Visual C++ 6.0
--------------------Configuration: CO_Project - Win32 Debug--------------------
Linking...
digex2.obj : error LNK2001: unresolved external symbol "public: __thiscall t8255::t8255(class tAddressSpace,class nMDBG::tStatus2 *)" (??0t8255@@QAE@VtAddressSpace@@PAVtStatus2@nMDBG@@​@Z)
osiUserCode.obj : error LNK2001: unresolved external symbol _viMapAddress@28
osiUserCode.obj : error LNK2001: unresolved external symbol _viFindNext@8
osiUserCode.obj : error LNK2001: unresolved external symbol _viClose@4
osiUserCode.obj : error LNK2001: unresolved external symbol _viGetAttribute@12
osiUserCode.obj : error LNK2001: unresolved external symbol _viOpen@20
osiUserCode.obj : error LNK2001: unresolved external symbol _viFindRsrc@20
osiUserCode.obj : error LNK2001: unresolved external symbol _viOpenDefaultRM@4
osiUserCode.obj : error LNK2001: unresolved external symbol _viUnmapAddress@4
Debug/CO_Project.exe : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.
CO_Project.exe - 10 error(s), 0 warning(s)
a journey of a thousand miles is started by taking the first step.
- chinese proverb

You will need to add the visa32.lib to your VC++ project to resolve those errors. If you have VISA installed, you can find it under C:\VXIpnp\WinNT\lib\msc
Bilal Durrani
NI

Similar Messages

  • Where can I found detailed Doc for chipObject and iBus object

    Hello,
    Can somebody told me where can I find the document for the chipObject and iBus, I am program for the E series daqcard which contain the tSTC, tESTC class. Do NI has document of these object.

    The only documentation for the E series cards in the MH DDK consists of the E series RLP manual and the STC Technical Reference manual. There is no separate documentation for the ChipObject for the E series or the STC.
    There is general documentation for the MH DDK and the WinCE PocketPC examples.
    I have attached a few files included with
    the MH DDK which provide a bit more information on the ChipObjects and iBus.
    Christian L
    NI Consulting Services
    Christian Loew, CLA
    Principal Systems Engineer, National Instruments
    Please tip your answer providers with kudos.
    Any attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system,
    or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject
    to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense
    Attachments:
    How_To_Make_an_iBus.html ‏5 KB
    How_to_use_a_ChipObject.html ‏8 KB
    Ex_Arch.png ‏46 KB

  • Register level programmin​g with ChipObject​s

    i have a problem in compiling an RLP example program
    /* ChipObject and DIO 96 example program */
    and i think its a linker error...
    do i need dll or something to work this out
    or files in my project are incorrect?
    Files included in my VC++ project:
    digex2.cpp // Digital Example 2, RLP example for DIo 96 board
    osiBus.cpp
    osiUserCode.cpp
    tDIO96.cpp
    // no header files included in my project all other files are in the project directory
    // such as:
    // osiBus.h
    // osiTypes.h
    // tDIO96.h
    // t8255.h
    // /nimdbg/trace.h /* i think this is for trace object*/
    // /nimdbg/tStatus2.h
    other external dependencies like visa.h
    i have set the INCLUDE DIRECTORY:
    C:\PROGRAM FILES\NATIONAL INSTRUMENTS\CVI70\INCLUDE
    error i get from Visual C++ 6.0
    --------------------Configuration: CO_Project - Win32 Debug--------------------
    Linking...
    digex2.obj : error LNK2001: unresolved external symbol "public: __thiscall t8255::t8255(class tAddressSpace,class nMDBG::tStatus2 *)" (??0t8255@@QAE@VtAddressSpace@@PAVtStatus2@nMDBG@@​@Z)
    osiUserCode.obj : error LNK2001: unresolved external symbol _viMapAddress@28
    osiUserCode.obj : error LNK2001: unresolved external symbol _viFindNext@8
    osiUserCode.obj : error LNK2001: unresolved external symbol _viClose@4
    osiUserCode.obj : error LNK2001: unresolved external symbol _viGetAttribute@12
    osiUserCode.obj : error LNK2001: unresolved external symbol _viOpen@20
    osiUserCode.obj : error LNK2001: unresolved external symbol _viFindRsrc@20
    osiUserCode.obj : error LNK2001: unresolved external symbol _viOpenDefaultRM@4
    osiUserCode.obj : error LNK2001: unresolved external symbol _viUnmapAddress@4
    Debug/CO_Project.exe : fatal error LNK1120: 9 unresolved externals
    Error executing link.exe.
    CO_Project.exe - 10 error(s), 0 warning(s)
    a journey of a thousand miles is started by taking the first step.
    - chinese proverb

    What operating system are you using? Windows? Unix? For many of these operating systems there are ready-made drivers and you should not need to use the ChipObjects.
    Based on your description most likely you are missing the VISA library (visa32.lib) in your project. On Windows this is normally located in the C:\VXIPNP\WinNT\lib\msc directory.
    If you are using the ChipObjects on an OS that doesn't support PCI cards through VISA, you need to update osiUserCode.cpp to interface to the regosters of the board using non-VISA functions.
    Christian Loew, CLA
    Principal Systems Engineer, National Instruments
    Please tip your answer providers with kudos.
    Any attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system,
    or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject
    to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense

  • Ni 6602 Card, Configuration in Register Level Programming

    Hello,
    I want to do register level programming with the NI 6602 card .
    I want to use an x4 encoder reader and I want to use the continuous
    frequency generation.
    so i got the following tool to map the kernel space to the user space, so
    a simple shell script will do the job.
    http://www.linux.it/~rubini/software/phob/phob.html
    and than just using the provided function phob_io
    to programm the registers in a shell script:
    #!/bin/bash
    # shell script for init 6602 card with prf and encoder counter
    # set prf
    ../phob_io ''0:048=0000'' # Input Select Register
    ../phob_io ''0:00C=1109'' # Command Register
    ../phob_io ''0:038=00ffffff'' # Load A Register
    ../phob_io ''0:03C=00ffffff'' # Load B Register
    ../phob_io ''0:
    034=9218'' # Mode Register
    But don"t get any output as i expect, what is wrong?
    Do i have to set some othe registers, or write somthing to the PCI-Config?
    Does anyone has some sample configuration?
    Thanks
    Mario Behn
    Mario Behn
    Microwave Remote Sensing Laboratory Room 104
    University of Massachusetts
    Knowles Engineering Building
    Amherst, MA 01003-4410
    phone (413) 545-4675
    fax (413) 545-4652
    email [email protected]

    A typical project for one of the 660x RLP examples needs to include the following source code files:
    ../OSinterface/osiBus.cpp - generic register I/O interface used by the example code
    ../OSinterface/Linux/osiUserCode.cpp - OS specific adapter used by osiBus to access registers on the hardware in the specific OS
    ../ChipObjects/tTIO.cpp - abstraction of the chips and registers on the hardware into C++ classes and properties
    and one of the examples files, e.g.
    ../Examples/gpct_ex1.cpp - implementation of a specific operation, including all initialization of the hardware
    (The same is true for the examples for other boards although the names of the ChipObject and examples will be different.)
    Each of these files needs to be compiled to give y
    ou object files, and then all of the object files need to be linked together to build an application (executable binary). The errors you list seem to indicate that you are not using all of these files.
    There is more information on the RLP example architecture in the attached PDF document.
    Christian Loew, CLA
    Principal Systems Engineer, National Instruments
    Please tip your answer providers with kudos.
    Any attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system,
    or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject
    to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense
    Attachments:
    Register_Level_Programming_Architecture.pdf ‏165 KB

  • Programming Analog Input Registers for MSeries NI-6221

    I am trying to understand the Preliminary M Series Register Map in order to correctly setup and acquire data from the Analog Input channels of my PCX-6221 card. I have been able to figure out the DIO locations and use them but I am having trouble understanding what I have to do to configure and acquire data using the Analog Input registers of the card. I need to program at this level for an RTX application using Microsoft Visual Studio Net 2003 and have had great success doing so with other NI Cards. I have tried looking at the examples provided by the MDDK but I haven't been able to create a environment that allows me to compile them with Chipobjects and it appears like alot of the work is hidden by the subroutines.
    I wonder if someone had a high level algorithum using the Register Map it would help out alot.
    Questions:
    How would I create a multiple channel Scan List and load it into the card setting gain etc...
    How would I configure the card to acquire continously at a specified freq (ex 1000 samples a sec)
    How would I start/stop acquisition
    I would guess getting the status of the FIFO and accessing the FIFO is a matter of reading the AI_STATUS_1 and AI_FIFO_DATA locations
    Would looking at the Register Programming Manual for the "E" Series help me or just get me more confused?
    Thanks in advance for any light you can shed on the subject.
    Floyd

    Hi Floyd-
    Let me address your questions individually:
    How would I create a multiple channel Scan List and load it into the card setting gain etc...
    A multi-channel scanlist can be created as shown in the method aiConfigureChannel() from ai.cpp in the M Series MHDDK \Examples folder.  Note that the other operations leading up that point (notably, aiClearConfigurationMemory() must be performed in the order shown in the various AI examples.  aiex3.cpp is the most useful starting point for investigation, in my opinion.
    How would I configure the card to acquire continously at a specified freq (ex 1000 samples a sec)
    aiex3.cpp shows how to setup the device and its DMA controller (aka the "MITE") for DMA operation.  In order to configure for continuous operation you set the "continous" flag in that example to kTrue.  The effect of that setting is to program the STC-II to generate either a finite or continuous AI sample clock.  This programming is performed in the function aiNumberOfSamples() from ai.cpp and has the effect of setting the appropriate bitfield for continuous operation in the AI_Mode_1 register. 
    Earlier in your post you asked if the STC Technical Reference Manual ( http://digital.ni.com/manuals.nsf/websearch/E929838D7D0EE50986256728007FEADF ) would be a good reference.  In fact, it's a great reference from the perspective of understanding the bitfield/register names and understanding the basics of how the timing hardware works (for example BC, UC and other sample counters are all functionally equivalent in the STC and STC-II).  From the perspective of actual register writes and reads, the functionality is different between E Series and M Series.  The biggest difference, as another forum user alluded, is that we map and write directly to the registers on M Series so Windowed_Mode reads and writes are no longer necessary.
    Another difference between STC and STC-II is that the STC-II uses NI TIO-style counter/timers.  For that reason, the NI 660x RLP manual ( http://digital.ni.com/manuals.nsf/websearch/4CE1C778F442B01386256C870060F9F3  ) would be a good reference for M Series counter/timer operations.
    How would I start/stop acquisition
    Assuming you don't need an external start trigger, you only need to write to the strobe bit AI_Command_2->AI_START1_Pulse.  This will create a single start trigger pulse internally.  The differences between AI_START1 and AI_START are described in the STC Technical Reference Manual.
    A finite acquisition would be stopped automatically by the AI timing engine based on the number of samples you program via the method shown in aiNumberOfSamples().  Continuous AI would be stopped by first stopping the DMA operation and then calling aiReset().
     I would guess getting the status of the FIFO and accessing the FIFO is a matter of reading the AI_STATUS_1 and AI_FIFO_DATA locations
    Yes, this would work but I would strongly suggest using DMA as shown in aiex3.cpp.  If you want to use "programmed I/O" to read the FIFO data directly, that method is shown in aiex2.cpp
     Would looking at the Register Programming Manual for the "E" Series help me or just get me more confused?
    In many cases it would be very helpful.  See my comments, above.
    I have inherited code that works on 65xx cards which I am pretty sure uses windowed mode that I am using in this 6221 driver. I have found that I can set the PLL registers to act as DIO and I can read the Discrete inputs just fine. Makes me curious, if Windowed mode is not used doesn't that mean the addresses are relative to the BAR1 address? Why then am I able to read the DIO?
    I'm not sure why this would work- it's possible that some legacy functionality is still working due to the way you access the hardware in your code.  For full functionality with M Series you must use mapped memory I/O to write and read from the device's registers.
    Also starting with Clock_and_FOUT according to the example I set it for Slow_Internal_Timebase. But when I read back that Address it is always zero. According to the register map it is a "write". Does that mean I can't read it's contents? Or do I seem to have a problem because I am trying to use windowed mode with this card.
    Yes, the "write" registers are write-only and the "read" registers are read-only.  The effect of data read from or written to "write" or "read" registers, respectively, is undefined.
    Hopefully this helps-
    Tom W
    National Instruments

  • Input impedance of NI 6602 Card

    Hi All,
        Why is the Input impedance of the PFI's are Finite? In the data sheet it is mentioned that input impedance is 25k-500k ohms. I have measured the impedance of the PFI channel using a Multimeter and it shows that as 9k ohms. In any case (say even if 25k ohms), why is the input impedance finite?
    When i connect my PWM signal to a PFI channel it is pulled down and so pulses ar not detected. I have had to use a pull up to count pulses. So, can any one explain why this input impedance is finite.
    Thanks in advance

    A typical project for one of the 660x RLP examples needs to include the following source code files:
    ../OSinterface/osiBus.cpp - generic register I/O interface used by the example code
    ../OSinterface/Linux/osiUserCode.cpp - OS specific adapter used by osiBus to access registers on the hardware in the specific OS
    ../ChipObjects/tTIO.cpp - abstraction of the chips and registers on the hardware into C++ classes and properties
    and one of the examples files, e.g.
    ../Examples/gpct_ex1.cpp - implementation of a specific operation, including all initialization of the hardware
    (The same is true for the examples for other boards although the names of the ChipObject and examples will be different.)
    Each of these files needs to be compiled to give y
    ou object files, and then all of the object files need to be linked together to build an application (executable binary). The errors you list seem to indicate that you are not using all of these files.
    There is more information on the RLP example architecture in the attached PDF document.
    Christian Loew, CLA
    Principal Systems Engineer, National Instruments
    Please tip your answer providers with kudos.
    Any attached Code is provided As Is. It has not been tested or validated as a product, for use in a deployed application or system,
    or for use in hazardous environments. You assume all risks for use of the Code and use of the Code is subject
    to the Sample Code License Terms which can be found at: http://ni.com/samplecodelicense
    Attachments:
    Register_Level_Programming_Architecture.pdf ‏165 KB

  • Analog Triggering and Interrupt generation on the PCIe-6320 under Linux

    We would like to use the analog triggering functions of the PCIe-6320 under Linux to time tag external events.
    I have no experience with the MH DDK but have been told this is what we would need to implement the functions we want. We plan on using Fedora Linux and we are targetting kernel 2.6.31 with the PREEMPT_RT patch applied. We may consider slightly more recent kernel versions. The PREEMPT_RT patch is used to greatly improve determinism in the system and get real-time responses to some external events.
    Here is what we wish to do in more details:
    We wish to route at least two analog inputs to the comparator, then route the output of the comparator to a digital input which in turn would create a PCIe interrupt. The interrupt software handler would than time tag that event for our application purposes. We need the comparator threshold to be software programmable in level and slope. We are also interested in using the Watchdog Timer feature of the board.
    Our application is written in C/C++.
    Would the above be feasible? Please provide comments and instructions how we should address our requirement.
    Thanks!

    Patof wrote:
    I am not familiar with the MHDDK. I would like to have an idea of the effort required to implement the functions I have described using MHDDK on Linux. Like I mentionned, we plan on using Linux kernel 2.6.31 with the PREEMPT_RT patch. Could you provide comments on that matter? I need to evaluate the amount of time I will need to spend to deploy and use MHDDK for the PCIe-6320.
    There are two factors to consider when writing a driver for your specific application:
    Using the deterministic kernel API calls
    Writing to the device registers to
    Control the watchdog timer
    Configure the analog comparator
    Manage the analog subsystem state as trigger events occur
    Handle device interrupts
    The MHDDK for X Series offers the following behavior out-of-the-tarball:
    A Linux kernel module using the standanrd kernel and PCI subsystem calls
    Mapping device registers to user-mode for access
    Demonstrating/documenting how to
    Control the watchdog timer (dioex6.cpp)
    Manage the analog subsystem state as trigger events occur (aiex2.cpp, aiex4.cpp)
    Handle device interrupts (reference manual only)
    There are two notably missing pieces and one item to consider:
    Missing: deterministic kernel API calls. If you decide to use the nirlpk module, you would need to change it from the standard interfaces to the deterministic variants.
    Missing: configuring the analog comparator. You will need to implement this with additional insight from this discussion board.
    Consider: if your application requires device access from kernel-mode only, you would not be able to use the MHDDK's C++ classes that perform device programming but would need to implement register programming in C.
    To estimate the time for these three, here are my recommendations:
    Review the nirlpk.c source file to understand how device access and DMA buffers are implemented and mapped to the user-mode application.
    Beware that operation-specific programming help (as you would need for analog triggering) typically requires two weeks for a complete response.
    Review the ChipObjects in the MHDDK distribution to understand how register addresses, widths, and bit fields affect device programming.
    Joe Friedchicken
    NI VirtualBench Application Software
    Get with your fellow hardware users :: [ NI's VirtualBench User Group ]
    Get with your fellow OS users :: [ NI's Linux User Group ] [ NI's OS X User Group ]
    Get with your fellow developers :: [ NI's DAQmx Base User Group ] [ NI's DDK User Group ]
    Senior Software Engineer :: Multifunction Instruments Applications Group
    Software Engineer :: Measurements RLP Group (until Mar 2014)
    Applications Engineer :: High Speed Product Group (until Sep 2008)

  • Chipobject available for m-series?

    Are M-Series chipObjects files available from NI? If not, anyone from NI have an ETA? I have developed drivers for E-Series boards, and would like to begin working on and M-Series driver very soon. Thanks!
    scott gillespie
    applied brain, inc.

    Do you think, a Delphi support is possible.
    I have 6 NI cards 6024-6033 runing with delpi an nidaq.
    Would buy some M-Cards, if there is a deplphi support.
    In europe lots of people are waiting for a delphi support. Meanwhile they are buying DT and others
    with delphi support.

  • A problem with Threads and loops.

    Hi, I have some code that needs to be constantly running, like while(true)
          //code here
    }However, the code just checks to see if the user has input anything (and then if the user has, it goes to do some other stuff) so I don't need it constantly running and hogging up 98% of the CPU. So I made my class (which has the method that needs to be looped, call it ClassA) implement Runnable. Then I just added the method which needed to be looped into the public void run()
    I have another class which creates an instance of the above class (call it ClassB), and the main(String[] args) is in there.
    public static void main(String[] args)
              ClassA test = new ClassA();
              Thread thread = new Thread(test.getInstanceOfClassA());
              thread.start();
              while(true)
                           //I do not know what to put here
                   try
                        thread.sleep(100);
                   catch(InterruptedException iex)
         }However, the thread only calls run() once,(duh...) but I can't think of away to get it to run - sleep - run -sleep forever. Can someone help me?

    Hi, I have some code that needs to be constantly
    running, like while(true)
    //code here
    }However, the code just checks to see if the user has
    input anything (and then if the user has, it goes to
    do some other stuff) so I don't need it constantly
    running and hogging up 98% of the CPU. Where does the user input come from. Are you reading from an InputStream? If so, then your loop will be blocked anyway when reading from the InputStream until data is available. During that time, the loop will not consume processor cycles.
    public static void main(String[] args)
              ClassA test = new ClassA();
    Thread thread = new Thread(test.getInstanceOfClassA());I have never seen this idiom. If ClassA instanceof Runnable, you simply write new Thread(test).
              thread.start();
              while(true)
    //I do not know what to put
    do not know what to put here
                   try
                        thread.sleep(100);
                   catch(InterruptedException iex)
         }However, the thread only calls run() once,(duh...)Yeah, why would you want to call it more than once given that you have an infinite loop in ClassA.run()?
    Harald.
    Java Text Crunching: http://www.ebi.ac.uk/Rebholz-srv/whatizit/software

  • A problem with Threads and MMapi

    I am tring to execute a class based on Game canvas.
    The problem begin when I try to Play both a MIDI tone and to run an infinit Thread loop.
    The MIDI tone "Stammers".
    How to over come the problem?
    Thanks in advance
    Kobi
    See Code example below:
    import java.io.IOException;
    import java.io.InputStream;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    import javax.microedition.lcdui.game.GameCanvas;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.Player;
    public class MainScreenCanvas extends GameCanvas implements Runnable {
         private MainMIDlet parent;
         private boolean mTrucking = false;
         Image imgBackgound = null;
         int imgBackgoundX = 0, imgBackgoundY = 0;
         Player player;
         public MainScreenCanvas(MainMIDlet parent)
              super(true);
              this.parent = parent;
              try
                   imgBackgound = Image.createImage("/images/area03_bkg0.png");
                   imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
                   imgBackgoundY = this.getHeight() - imgBackgound.getHeight();
              catch(Exception e)
                   System.out.println(e.getMessage());
          * starts thread
         public void start()
              mTrucking = true;
              Thread t = new Thread(this);
              t.start();
          * stops thread
         public void stop()
              mTrucking = false;
         public void play()
              try
                   InputStream is = getClass().getResourceAsStream("/sounds/scale.mid");
                   player = Manager.createPlayer(is, "audio/midi");
                   player.setLoopCount(-1);
                   player.prefetch();
                   player.start();
              catch(Exception e)
                   System.out.println(e.getMessage());
         public void run()
              Graphics g = getGraphics();
              play();
              while (true)
                   tick();
                   input();
                   render(g);
          * responsible for object movements
         private void tick()
          * response to key input
         private void input()
              int keyStates = getKeyStates();
              if ((keyStates & LEFT_PRESSED) != 0)
                   imgBackgoundX++;
                   if (imgBackgoundX > 0)
                        imgBackgoundX = 0;
              if ((keyStates & RIGHT_PRESSED) != 0)
                   imgBackgoundX--;
                   if (imgBackgoundX < this.getWidth() - imgBackgound.getWidth())
                        imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
          * Responsible for the drawing
          * @param g
         private void render(Graphics g)
              g.drawImage(imgBackgound, imgBackgoundX, imgBackgoundY, Graphics.TOP | Graphics.LEFT);
              this.flushGraphics();
    }

    You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
    However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
    You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
    Regds,
    SD
    N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
    Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM

  • Problem with Threads and a static variable

    I have a problem with the code below. I am yet to make sure that I understand the problem. Correct me if I am wrong please.
    Code functionality:
    A timer calls SetState every second. It sets the state and sets boolean variable "changed" to true. Then notifies a main process thread to check if the state changed to send a message.
    The problem as far I understand is:
    Assume the timer Thread calls SetState twice before the main process Thread runs. As a result, "changed" is set to true twice. However, since the main process is blocked twice during the two calls to SetState, when it runs it would have the two SetState timer threads blocked on its synchronized body. It will pass the first one, send the message and set "changed" to false since it was true. Now, it will pass the second thread, but here is the problem, "changed" is already set to false. As a result, it won't send the message even though it is supposed to.
    Would you please let me know if my understanding is correct? If so, what would you propose to resolve the problem? Should I call wait some other or should I notify in a different way?
    Thanks,
    B.D.
    Code:
    private static volatile boolean bChanged = false;
    private static Thread objMainProcess;
       protected static void Init(){
            objMainProcess = new Thread() {
                public void run() {
                    while( objMainProcess == Thread.currentThread() ) {
                       GetState();
            objMainProcess.setDaemon( true );
            objMainProcess.start();
        public static void initStatusTimer(){
            if(objTimer == null)
                 objTimer = new javax.swing.Timer( 1000, new java.awt.event.ActionListener(){
                    public void actionPerformed( java.awt.event.ActionEvent evt){
                              SetState();
        private static void SetState(){
            if( objMainProcess == null ) return;
            synchronized( objMainProcess ) {
                bChanged = true;
                try{
                    objMainProcess.notify();
                }catch( IllegalMonitorStateException e ) {}
        private static boolean GetState() {
            if( objMainProcess == null ) return false;
            synchronized( objMainProcess ) {
                if( bChanged) {
                    SendMessage();
                    bChanged = false;
                    return true;
                try {
                    objMainProcess.wait();
                }catch( InterruptedException e ) {}
                return false;
        }

    Thanks DrClap for your reply. Everything you said is right. It is not easy to make them alternate since SetState() could be called from different places where the state could be anything else but a status message. Like a GREETING message for example. It is a handshaking message but not a status message.
    Again as you said, There is a reason I can't call sendMessage() inside setState().
    The only way I was able to do it is by having a counter of the number of notifies that have been called. Every time notify() is called a counter is incremented. Now instead of just checking if "changed" flag is true, I also check if notify counter is greater than zero. If both true, I send the message. If "changed" flag is false, I check again if the notify counter is greater than zero, I send the message. This way it works, but it is kind of a patch than a good design fix. I am yet to find a good solution.
    Thanks,
    B.D.

  • Problem with Threads and "plase wait..."-Window

    Hi everyone,
    I have a problem that I'm not able to solve in any way... I have a time-consuming task (a file decryption) which I execute in a separate thread; I've used the SwingWorker class, like suggested by sun-tutorial, and it works right. The problem is that I have to wait that the decryption have finished before continuing with program-execution. Therefore I would like to display a "please wait"-window while the task runs. I've tryed all the possible ways I know but the problem is always the same: the waitWindow is displayed empty, the bounds are painted but the contents no; it's only painted when the decrypt-task has finished. Please help me, I have no more resources....
    decrypt-file code:
    public class DecryptFile {
      private String cryptedFileNameAndPath;
      private ByteArrayInputStream resultStream = null;
      // need for progress
      private int lengthOfTask;
      private int current = -1;
      private String statMessage;
      public DecryptFile(String encZipFileNameAndPath) {
        cryptedFileNameAndPath = encZipFileNameAndPath;
        //Compute length of task...
        // 0 for indeterminate
        lengthOfTask = 0;
      public ByteArrayInputStream getDecryptedInputStream() {
        return this.resultStream;
       * Called from ProgressBarDemo to start the task.
      public void go() {
        current = -1;
        final SwingWorker worker = new SwingWorker() {
          public Object construct() {
            return new ActualTask();
        worker.start();
       * Called from ProgressBarDemo to find out how much work needs
       * to be done.
      public int getLengthOfTask() {
        return lengthOfTask;
       * Called from ProgressBarDemo to find out how much has been done.
      public int getCurrent() {
        return current;
      public void stop() {
        current = lengthOfTask;
       * Called from ProgressBarDemo to find out if the task has completed.
      public boolean done() {
        if (current >= lengthOfTask)
          return true;
        else
          return false;
      public String getMessage() {
        return statMessage;
       * The actual long running task.  This runs in a SwingWorker thread.
      class ActualTask {
        ActualTask () {
          current = -1;
          statMessage = "";
          resultStream = AIUtil.getInputStreamFromEncZip(cryptedFileNameAndPath); //here the decryption happens
          current = 0;
          statMessage = "";
      }The code that calls decryption and displays waitWindow
          final WaitSplash wS = new WaitSplash("Please wait...");
          final DecryptFile cryptedTemplate = new DecryptFile (this.templateFile);
          cryptedTemplate.go();
          while (! cryptedTemplate.done()) {
            try {
              wait();
            } catch (Exception e) { }
          this.templateInputStream = cryptedTemplate.getDecryptedInputStream();
          wS.close();Thanks, thanks, thanks in advance!
    Edoardo

    Maybe you can try setting the priority of the long-running thread to be lower? so that the UI will be more responsive...

  • Problem with threads and graphics

    I have a thread that chooses paths for a Travelling salesman problem, it then calls a TSPdraw class and passes it the path, which the class then draws. the problem is when i have two threads it creates two windows but only draws a path in one of them. any ideas where i`m going wrong

    Are you using swing components? Swing isn't threadsafe. If you have multiple threads that want to update your UI you need to use the SwingUtilities.invokeLater(...)or invokeAndWait(...). There is a page in the swing tutorial about this at: http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html

  • Problem with threads and ProgressMonitor

    Dear Friends:
    I have a little problem with a thread and a ProgressMonitor. I have a long time process that runs in a thread (the thread is in an separate class). The thread has a ProgressMonitor that works fine and shows the tasks progress.
    But I need deactivate the main class(the main class is the user interface) until the thread ends.
    I use something like this:
    LongTask myTask=new LongTask();
    myTask.start();
    myTask.join();
    Now, the main class waits for the task to end, but the progress monitor don`t works fine: it shows only the dialog but not the progress bar.
    What's wrong?

    Is the dialog a modal dialog? This can block other UI updates.
    In general, you should make sure that it isn't modal, and that your workThread has a fairly low priority so that the UI can do its updating

  • Problem with threads and/or memory

    I'm developing an application where there are 3 threads. One of them sends a request to the other, and if the 2nd can't answer it, it sends it to the 3rd (similar to CPU -> CACHE -> MEMORY). When i run the program with 1000-10.000 requests, no problem occurs. When i run it with 300.000-1.000.000 requests, it sometimes hangs. Is this a problem with the garbage collector, or should it be related to the threads mecanism.
    (note: eache thread is in execution using a finite state machine)

    i had been running the program inside Netbeans.
    Running the jar using the command line outside
    Netbeans i have no more problems... Does Netbeans use
    it's own JVM?Depends how you set it up, but look under the options. There are settings for the compiler and jvm that it uses.

Maybe you are looking for

  • Output from java class and display

    I have a big output from a java class after executing a java class... where can store that huge output before I <cflocation to the same page? I need to display the output to the user on the relocated page...Any help appreciated...

  • Folder linked to FTP site

    Hello, Some time ago I created a link to an FTP site that functions like a local directory. Recently, I needed to create another one but have forgotten how I created the first. I am able "add a network location" but that doesn't achieve the same type

  • Exporting data in tables to an Excel spreadsheet?

    Is there a script or another way to export or save a documents tables (multiple tables over several pages) to an excel spreadsheet? I have found a solution which involves exporting each spread as a html file which i can then open straight in excel bu

  • CODING HELP ME!!!

    I know that I can use System.out.print() to display messages to the screen. How can I input messages that the user types at my prompt into a program? Thank you

  • Disabling context menu

    Dear Expert, My requirement is to disable the context menu for certain / all parts of BExweb report. How could this be possible for either the whole report or just some parts of the report? Seems like whatever is shown on the report I can click and t