How can I implement a dynamic loop rate?
Appologies if this has been answered, but searching hasn't revealed the solution.
I have a data acquisition appliction on the RT clocked externally. I can send every x-th sample to the host PC for display via shared variable (data bandwidth is no issue). I'd like to dynamically determine what "x" should be based on the processor load on the host (I can send x to the RT from the host).
Is there a simple way to determine how much processor time my application is sucking up in the host PC application so I can adapt x to the environment?
Hi Lee Jay!
Thank you for contacting National Instruments. From my understanding of the information you have provided, I think I may have a suggestion to achieve this behavior. However, I am a bit unclear of what you are trying to do specifically. LabVIEW does not have any inherent functionality to determine processor timing and resource usage as you have described. From within the program we can determine the time that elapses from one point to another by using the Tick Count and Sequence Structures functionalities.
Another aspect to consider is trying to use something similar to Queue Basics, which can be found in the Example Finder. This should allow for control over the rate at which items are read at the host regardless of the data coming from the target.
I hope this helps. Let me know if there is anything else I can help with or clarify. Have a great day!
Jason W.
National Instruments
Applications Engineer
Similar Messages
-
How can I implement a do loop in Test Stand
I'm trying to create a looping step that will execute at least one time like a traditional do loop in a text based language. Can it be done using the loping feature of a single step, or do I have to execute the step, and loop using a goto step with a precondition?
Thanks in advance for any help.
David DupontWe had a contractor build us an app using TestStand 2.0.1. In the documentation he mentions that the application uses "custom flow control step types that are defined in a TestStand_LabWindow/CVI add-on that is available as a free download from NI". I looked over the original disk and I found a folder containing these step types. You might want to see if you can find them on the web site. Or if is possible here I can attempt to attach them if you want.
Using LabVIEW 2010SP1 and TestStand 4.5 -
How can I repeat a for loop, once it's terms has been fulfilled???
Well.. I've posted 2 different exceptions about this game today, but I managed to fix them all by myself, but now I'm facing another problem, which is NOT an error, but just a regular question.. HOW CAN I REPEAT A FOR LOOP ONCE IT HAS FULFILLED IT'S TERMS OF RUNNING?!
I've been trying many different things, AND, the 'continue' statement too, and I honestly think that what it takes IS a continue statement, BUT I don't know how to use it so that it does what I want it too.. -.-'
Anyway.. Enought chit-chat. I have a nice functional game running that maximum allows 3 apples in the air in the same time.. But now my question is: How can I make it create 3 more appels once the 3 first onces has either been catched or fallen out the screen..?
Here's my COMPLETE sourcecode, so if you know just a little bit of Java you should be able to figure it out, and hopefully you'll be able to tell me what to do now, to make it repeat my for loop:
Main.java:
import java.applet.*;
import java.awt.*;
@SuppressWarnings("serial")
public class Main extends Applet implements Runnable
private Image buffering_image;
private Graphics buffering_graphics;
private int max_apples = 3;
private int score = 0;
private GameObject player;
private GameObject[] apple = new GameObject[max_apples];
private boolean move_left = false;
private boolean move_right = false;
public void init()
load_content();
setBackground(Color.BLACK);
public void run()
while(true)
if(move_left)
player.player_x -= player.movement_speed;
else if(move_right)
player.player_x += player.movement_speed;
for(int i = 0; i < max_apples; i++)
apple.apple_y += apple[i].falling_speed;
repaint();
prevent();
collision();
try
Thread.sleep(20);
catch(InterruptedException ie)
System.out.println(ie);
private void prevent()
if(player.player_x <= 0)
player.player_x = 0;
else if(player.player_x >= 925)
player.player_x = 925;
private void load_content()
MediaTracker media = new MediaTracker(this);
player = new GameObject(getImage(getCodeBase(), "Sprites/player.gif"));
media.addImage(player.sprite, 0);
for(int i = 0; i < max_apples; i++)
apple[i] = new GameObject(getImage(getCodeBase(), "Sprites/apple.jpg"));
try
media.waitForAll();
catch(Exception e)
System.out.println(e);
public boolean collision()
for(int i = 0; i < max_apples; i++)
Rectangle apple_rect = new Rectangle(apple[i].apple_x, apple[i].apple_y,
apple[i].sprite.getWidth(this),
apple[i].sprite.getHeight(this));
Rectangle player_rect = new Rectangle(player.player_x, player.player_y,
player.sprite.getWidth(this),
player.sprite.getHeight(this));
if(apple_rect.intersects(player_rect))
if(apple[i].alive)
score++;
apple[i].alive = false;
if(!apple[i].alive)
apple[i].alive = false;
return true;
public void update(Graphics g)
if(buffering_image == null)
buffering_image = createImage(getSize().width, getSize().height);
buffering_graphics = buffering_image.getGraphics();
buffering_graphics.setColor(getBackground());
buffering_graphics.fillRect(0, 0, getSize().width, getSize().height);
buffering_graphics.setColor(getForeground());
paint(buffering_graphics);
g.drawImage(buffering_image, 0, 0, this);
public boolean keyDown(Event e, int i)
i = e.key;
if(i == 1006)
move_left = true;
else if(i == 1007)
move_right = true;
return true;
public boolean keyUp(Event e, int i)
i = e.key;
if(i == 1006)
move_left = false;
else if(i == 1007)
move_right = false;
return true;
public void paint(Graphics g)
g.drawImage(player.sprite, player.player_x, player.player_y, this);
for(int i = 0; i < max_apples; i++)
if(apple[i].alive)
g.drawImage(apple[i].sprite, apple[i].apple_x, apple[i].apple_y, this);
g.setColor(Color.RED);
g.drawString("Score: " + score, 425, 100);
public void start()
Thread thread = new Thread(this);
thread.start();
@SuppressWarnings("deprecation")
public void stop()
Thread thread = new Thread(this);
thread.stop();
GameObject.java:import java.awt.*;
import java.util.*;
public class GameObject
public Image sprite;
public Random random = new Random();
public int player_x;
public int player_y;
public int movement_speed = 15;
public int falling_speed;
public int apple_x;
public int apple_y;
public boolean alive;
public GameObject(Image loaded_image)
player_x = 425;
player_y = 725;
sprite = loaded_image;
falling_speed = random.nextInt(10) + 1;
apple_x = random.nextInt(920) + 1;
apple_y = random.nextInt(100) + 1;
alive = true;
And now all I need is you to answer my question! =)package forums;
import java.util.Random;
import javax.swing.Timer;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
public class VimsiesRetardedAppleGamePanel extends JPanel implements KeyListener
private static final long serialVersionUID = 1L;
private static final int WIDTH = 800;
private static final int HEIGHT = 600;
private static final int MAX_APPLES = 3;
private static final Random RANDOM = new Random();
private int score = 0;
private Player player;
private Apple[] apples = new Apple[MAX_APPLES];
private boolean moveLeft = false;
private boolean moveRight = false;
abstract class Sprite
public final Image image;
public int x;
public int y;
public boolean isAlive = true;
public Sprite(String imageFilename, int x, int y) {
try {
this.image = ImageIO.read(new File(imageFilename));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("Bailing out: Can't load images!");
this.x = x;
this.y = y;
this.isAlive = true;
public Rectangle getRectangle() {
return new Rectangle(x, y, image.getWidth(null), image.getHeight(null));
class Player extends Sprite
public static final int SPEED = 15;
public Player() {
super("C:/Java/home/src/images/player.jpg", WIDTH/2, 0);
y = HEIGHT-image.getHeight(null)-30;
class Apple extends Sprite
public int fallingSpeed;
public Apple() {
super("C:/Java/home/src/images/apple.jpg", 0, 0);
reset();
public void reset() {
this.x = RANDOM.nextInt(WIDTH-image.getWidth(null));
this.y = RANDOM.nextInt(300);
this.fallingSpeed = RANDOM.nextInt(8) + 3;
this.isAlive = true;
private final Timer timer = new Timer(200,
new ActionListener() {
public void actionPerformed(ActionEvent e) {
repaint();
public VimsiesRetardedAppleGamePanel() {
this.player = new Player();
for(int i=0; i<MAX_APPLES; i++) {
apples[i] = new Apple();
setBackground(Color.BLACK);
setFocusable(true); // required to generate key listener events.
addKeyListener(this);
timer.setInitialDelay(1000);
timer.start();
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == e.VK_LEFT) {
moveLeft = true;
moveRight = false;
} else if (e.getKeyCode() == e.VK_RIGHT) {
moveRight = true;
moveLeft = false;
public void keyReleased(KeyEvent e) {
moveRight = false;
moveLeft = false;
public void keyTyped(KeyEvent e) {
// do nothing
public void paintComponent(Graphics g) {
super.paintComponent(g);
//System.err.println("DEBUG: moveLeft="+moveLeft+", moveRight="+moveRight);
if ( moveLeft ) {
player.x -= player.SPEED;
if (player.x < 0) {
player.x = 0;
} else if ( moveRight ) {
player.x += player.SPEED;
if (player.x > getWidth()) {
player.x = getWidth();
//System.err.println("DEBUG: player.x="+player.x);
Rectangle playerRect = player.getRectangle();
for ( Apple apple : apples ) {
apple.y += apple.fallingSpeed;
Rectangle appleRect = apple.getRectangle();
if ( appleRect.intersects(playerRect) ) {
if ( apple.isAlive ) {
score++;
apple.isAlive = false;
g.drawImage(player.image, player.x, player.y, this);
for( Apple apple : apples ) {
if ( apple.isAlive ) {
g.drawImage(apple.image, apple.x, apple.y, this);
g.setColor(Color.RED);
g.drawString("Score: " + score, WIDTH/2-30, 10);
private static void createAndShowGUI() {
JFrame frame = new JFrame("Vimsies Retarded Apple Game");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(new VimsiesRetardedAppleGamePanel());
frame.pack();
frame.setSize(WIDTH, HEIGHT);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
public static void main(String[] args) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
createAndShowGUI();
}Hey Vimsie, try resetting a dead apple and see what happens. -
How can I create classes dynamically?
Guys
My requirment is I want to create classes and their instancess too dynamically. First is it possible in Java?
If so, then my next question is how can I refer such dynamically created classes in my code to avoid compilation error.
Thanks in advance
Regards
SunilFor other ways to generate classes on runtime you could also have a look at BCEL:
http://jakarta.apache.org/bcel
And dynamic proxies:
http://java.sun.com/j2se/1.4.2/docs/guide/reflection/proxy.html
If so, then my next question is how can I refer such
dynamically created classes in my code to avoid compilation
error.Generally the classes that you load should either implement some interface or extend some abstract class you know of at compile time so that the compiler knows what methods are available for use. If that's not possible you can only use reflection. -
How can I implement IMAQ correlation for 16bit image?
Hi
When using IMAQ correlate. vi in Machine vision Filter catergory, the vi only works for 8 bit source and template image case.
16 bit source image case makes error.
But I need 16 bit source image without losing image information, I want to use full 16 bit image correlation with 8 bit template.
How can I implement the code in labview?
Need help.
Many thanks.Unfortunately you can't do so.
There are some functions in the Vision Lib that only accept 8bit images. In order to use them you have to convert your image to an 8bit Image.
Keep in mind that converting an Image to 8bit will not necessary result in a loss of data. Check your Images, it might be that you are not using the full range of a 16bit value. you might be able to use a mixture of dynamic shifting and bit shifting in order to convert an image to an 8 bit, then embedding these criterias in the image and use them to convert back to a 16bit at a later time without losing any data, or in most cases minimal precision loss.
If you would like to attach one of the images you are using, I can take a look at it to see if this is possible in your case.
Good luck,
Dan,
www.movimed.com - Custom Imaging Solutions -
How can we implement a regular expression in if condition?
hi,
could any body tell me how can we implement regular expression in if condition?
if a page contains links with .html,.pdf,.img etc as href paths then i should only retrieve the links whose href path is .pdf .
any idea
thanks in advancePasumarthi,
Here is some VBA that should do the trick. This was created against the empirix homepage. www.empirix.com.
Private Sub RSWVBAPage_afterPlay()
Dim objReg As New RegExp
Dim objMatch As Match
Dim doc As String
'Get the html
RSWApp.GetHtml doc
'set parameters for regular expression searching and matching
With objReg
'find all occurances
.Global = True
.IgnoreCase = True
'regular expression pattern specified here
.Pattern = "a href=(.+?)pdf"""
End With
'Loop through the matches and write them to the results log.
For Each objMatch In objReg.execute(doc)
RSWApp.WriteToLog objMatch.Value
Next
Set objReg = Nothing
End Sub -
How can I implement commands in Labwindows?
I have a target with 8051 microprocessor. This microprocessor have a program in MS_DOS.
I want to do an emulation with Labwindows.
I comunicate with pc by RS232.
In the MSDOS program I use the following commands:
sp(back_espace key)= Initialitation board.
vx(direction memory)(enter key)= Readed memory
My question is: How can I implement commands in Labwindows?Hi,
erm, could you re-post this question in the LabWindows/CVI forum?
You might get a few more answers in there
When you talk about emulating, I assume you're refering to getting Windows (which flavour - 9x/NT/me/xp/2k) to do some sort of display depending on button presses from a user interface, or are you wanting to turn the whole PC into an emulator, whereby another PC communicates to it through the serial port, and you want the emulating pc to react as though it was the 8051?
Thanks
S.
// it takes almost no time to rate an answer -
How can I get my ES2 loops to play correctly? I keep getting the message that the audio is not found when I drag the loops from my audio browser even though they play fine in the preview.
It's exactly as I stated. Whenever I try to drag these kinds of loops (ESX24 / software instrument loops? the ones marked in green with the white music note next to them) from the loop browser into the timeline a message comes up saying Audio Not Found for that loop. And a new track is created automatically when loops are dragged into the timeline, so I'm not creating some other random / synth instrument track so I'm not sure what the deal is... But perhaps I'll try creating a software instrument track first and then drag the loop into that track and see what happens - maybe there's something with the default settings that automatically creates audio tracks whenever loops are imported?
-
How can I do a dynamic include of a page fragment?
I have a technical support website with a lot of simple html pages. What I want to do is hyperlink from the index page to another page, which would display these html pages as a page fragment, dynamically based on a session bean set by the hyperlink.
I basically want to do this, if it was possible:
<jsp:directive.include file="#{SessionBean1.pageToDisplay}"/>
Now the FAQ's has a topic "How can I do a dynamic include of a page fragment?", which would seem to answer my question.
But this is all it says, and it makes no sense to me. Could someone please translate? :)
"Using a page fragment file (but using instead of the usual Creator approach) will accomplish a dynamic include."Here is 1 solution:
First add this to the jsp:root tag:
xmlns:c="http://java.sun.com/jsp/jstl/core"
Then surround the page fragment directive with something like this:
<div style="position: absolute; left: 24px; top: 408px">
<c:if test="${SessionBean1.count > 0}">
<jsp:directive.include file="testPF.jspf"/>
</c:if>
</div> -
How can I implement a comfirmation window when closing javafx application?
hi,guys
I'd like to add a confirmation window when user is closing my javafx application,if user click yes, I will close the application,if no ,I wouldn't close it ,how can I implement this function?
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
@Override
public void handle(WindowEvent arg0) {
try
//todo
catch(Exception ex)
System.out.print(ex.getMessage()+"\r\n");
});Hi. Here is an example:
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.paint.Color;
import javafx.scene.layout.*;
import javafx.scene.control.*;
public class ModalDialog {
public ModalDialog(final Stage stg) {
final Stage stage = new Stage();
//Initialize the Stage with type of modal
stage.initModality(Modality.APPLICATION_MODAL);
//Set the owner of the Stage
stage.initOwner(stg);
Group group = new Group();
HBox hb = new HBox();
hb.setSpacing(20);
hb.setAlignment(Pos.CENTER);
Label label = new Label("You are about to close \n your application: ");
Button no = new Button("No");
no.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
stage.hide();
Button yes = new Button("Yes");
yes.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent event) {
stg.close();
hb.getChildren().addAll(yes, no);
VBox vb = new VBox();
vb.setSpacing(20);
vb.setAlignment(Pos.CENTER);
vb.getChildren().addAll(label,hb);
stage.setTitle("Closing ...");
stage.setScene(new Scene( vb, 260, 110, Color.LIGHTCYAN));
stage.show();
}Test:
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.*;
* @author Shakir
public class ModalTest extends Application {
* @param args the command line arguments
public static void main(String[] args) {
Application.launch(ModalTest.class, args);
@Override
public void start(final Stage primaryStage) {
primaryStage.setTitle("Hello World");
Group root = new Group();
Scene scene = new Scene(root, 300, 250, Color.LIGHTGREEN);
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>(){
@Override
public void handle(WindowEvent arg0) {
arg0.consume();
try
ModalDialog md = new ModalDialog(primaryStage);
catch(Exception ex)
System.out.print(ex.getMessage()+"\r\n");
primaryStage.setScene(scene);
primaryStage.show();
} -
How can I implement a real time datawarehouse
Hi, I'm a little lost here but I want to know how can I implement a real time datawarehouse in sql server, I don't know if it is only to make the extraction process the shortest time possible.
Thank youHi Mega15,
I agree with everything Seif and Louw said, but I'd like to add that if you are using SQL Server 2012 or 2014 and you want to use DirectQuery or ROLAP mode (depending on what SSAS mode are you using, tabular or multidimensional) you may be interested on
using columnar indexes on your base tables.
Analytical and aggregated queries will take GREAT advantage from these indexes, they will perform much better than with traditional B-Tree indexes in most of your scenarios.
Regards.
Pau. -
How can I implement a Digital I/O counter with a maximum source frequency of 80 MHz (like 6602 board) using CompactRIO? It appears as if the Digital I/O modules for CompactRIO are much slower than this.
Thank you,
--RayHi Ray,
The highest frequency input we offer for C Series modules is 20 MHz if you are doing LVTTL and 10 MHz for 5 V TTL. These modules are the 9402 and 9401, respectively. Unfortunately, there is no 80 MHz input on this form-factor.
Regards,
Chris E.
Applications Engineer
National Instruments
http://www.ni.com/support -
How can i add a dynamic header value in to the pdf
I am using a AssemblerService (Invoke DDX) to modify a Pdf file. How can i enter a dynamic value into the header using ddx ?
DDX used
<DDX xmlns="http://ns.adobe.com/DDX/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.adobe.com/DDX/1.0/ coldfusion_ddx.xsd">
<PDF result="Out1">
<PDF source="Doc2">
<Header>
<Right>
<StyledText>
<p>"here i need to add a dynamic data from the process"</p>
</StyledText>
</Right>
</Header>
</PDF>
</PDF>
</DDX>
Thank You.Insertion Point is a placeholder Object which is used to dynamically replace while assembling. Search through the assmber guide to get any hints.
Nith -
How can I implement an user function in a derived column of a report ?
Hello,
I've a report and added a derived column.
In this column should be displayed the result of a function.
GETANZGJMONATE ( to_date(#START_AFA#,'DD.MM.YYYY'), #ND#, :P302_GJ );
How can I implement this?
Thanks in advance
Regards UlrikeUlrike - I would do this in the SQL statement (there may be other ways).
Presumably START_AFA and ND are table columns?
Presumably you've also created the GETANZGJMONATE function?
So, something like this should work (this also assumes that START_AFA is of a DATE type - you'll need the TO_DATE call if not):
SELECT COL1
, COL2
, START_AFA
, ND
, GETANZGJMONATE (START_AFA, ND, :P302_GJ)
from TABLE
where ...
Can't remember if you have to grant any particular execute permissions on the function ('grant execute on GETANZGJMONATE to public', for example) when you call it from SQL on a page, but you could try that if the function call fails.
Depending on what's in :P302_GJ and what the function parameter data type is, you might need to use the '&P302_GJ.' syntax or TO_NUMBER etc.
Hope this helps.
Regards,
John. -
How can i implement 'Distribute Qty' function in BAPI_GOODSMVT_CREATE
Hi all,
Using MIGO For GR. if more than one Batch or Production Date or Vendor Batch for same Purchase Order Line Item and Deliv date, need to hit Distribute Qty button to split the entry line into multiple lines before enter Production Date and Vendor Batch.
So I want use bapi BAPI_GOODSMVT_CREATE implement MIGO function for a interface. Anyone have some suggestion how can i implement the 'Distribute Qty' function in the bapi.
My email address: [email protected]Hello,
1. Use structure BAPIPAREX for passing custom fields. (There are several blogs/posts on how to make use of this).
2. In the BAPI i noticed there is a BAdI to populate these fields into your business tables.
Call BAdI MB_BAPI_GOODSMVT_CREATE to fill own fields
TRY.
get badi lo_mb_bapi_GOODSMVT_CREATE.
CATCH cx_badi_not_implemented. "#EC NO_HANDLER
ENDTRY.
TRY.
call badi lo_mb_bapi_goodsmvt_create->extensionin_to_matdoc
EXPORTING
EXTENSION_IN = EXTENSIONIN[]
CHANGING
CS_IMKPF = S_IMKPF
CT_IMSEG = T_IMSEG[]
CT_RETURN = return.
CATCH cx_badi_initial_reference. "#EC NO_HANDLER
ENDTRY.
Maybe you are looking for
-
I want this on Scott McNealy's desk by tomorrow
The java technology has evolved nicely over the years. It is doing very well on the server side; on the mobile side all the major players are announcing java enabled devices. But on the side where you expect people to really get acquainted with the j
-
Unable to create a pdf file using the print routine
Hey all, Recently, i've been unable to create a pdf using the print routine from quickbooks, word, outlook, etc... using the print routine and the adobe pdf driver.... I have vista and cs3... Any thoughts? Thanks, Murph [email address deleted by host
-
Convert spool to pdf and send in email sometimes attachment duplicated.
Hi all, I have a process that creates a spool, converts it to a pdf and then attaches it to an email. My problem is that sometimes, the same attachment is duplicated. The process seems to work fine in debug mode (the attachment changes for each loop)
-
Why have my notes and contacts been deleted and my applications won't launch
I tried using my iPad mini today but both my notes and contacts have been deleted and my applications either won't launch at all or launch for a few minutes and then shutdown. I also tried to download another app which said had been downloaded but I
-
Blue question mark instead of photo
I sometimes get a blue question mark instead of a photo on my mac book pro. How do i fix that?