rrojas Posted November 19, 2004 Report Share Posted November 19, 2004 All, In my VI I have two main loops. One loop writes to the serial port and one loop reads from it. I am experiencing lag when I press a button to have a message written to the serial port. On the other end I have another computer that is running an emulator that responds to the messages it gets and sends out an appropriate reponse. The read loop in my VI receives the responses fine and updates the front panel quickly. It's just the write loop that takes it's danged time to write. A little more explanation: The write loop is a loop with a case statement inside. This case statement reflects different states. One state is a "user listen" state which waits for a user to hit a button on the FP. Once the event structure captures a particular button press, it goes on to unbundle a bundle of possible messages in order to select the right message to send. Once it finds the correct message to send, it creates the packet, wrapping a sync word and a checksum before and after it, respectively. Then it shoots it out to the port. Is the unbundling taking a lot of time? I would include images of my VIs except I really have no idea what is causing this lag in writing to the serial port. :headbang: I have included waits in the read loop hoping that this will prompt it to release the processor and allow another process (i.e., the write loop) to have the processor, but it doesn't seem to make a difference. Any help at all as to how I can make the writes to the port faster would be appreciated. If you guys need further explanation, please feel free to ask and I will provide. Thanks. Quote Link to comment
didierj Posted November 22, 2004 Report Share Posted November 22, 2004 1. At which speed do you transmit data over the serial port? Sending one Byte over the serial port at 9600 baud needs 10ms! At 57600 baud needs .17ms Make sure your serial port writes to 57600, 115200 baud or higher. 2. To find the process that consume the most time either use the VI-profiler (Menu: Tools>>Advanced>>Profile IVs...) or place Tick Count's in your block diagram (with e.g. sequences to have the Tick Count readed at the whished time), subtract the values from different Tick Counts. VI-profiler is based on vi, with Tick Count one can "profile" parts of a vi. Didier Quote Link to comment
rrojas Posted November 22, 2004 Author Report Share Posted November 22, 2004 1. At which speed do you transmit data over the serial port?Sending one Byte over the serial port at 9600 baud needs 10ms! At 57600 baud needs .17ms Make sure your serial port writes to 57600, 115200 baud or higher. 2. To find the process that consume the most time either use the VI-profiler (Menu: Tools>>Advanced>>Profile IVs...) or place Tick Count's in your block diagram (with e.g. sequences to have the Tick Count readed at the whished time), subtract the values from different Tick Counts. VI-profiler is based on vi, with Tick Count one can "profile" parts of a vi. Didier 2717[/snapback] Well, I'm transmitting at 19200 baud right now but I am putting time delays in the loop that reads from the serial port so shouldn't that give up the CPU and allow the loop that writes to the serial port run? Are there any other mechanisms I can use to set my writing loop to a higher priority than my read loop - other than timed loops? Quote Link to comment
Michael Aivaliotis Posted November 23, 2004 Report Share Posted November 23, 2004 The write loop is a loop with a case statement inside. This case statement reflects different states. One state is a "user listen" state which waits for a user to hit a button on the FP. Once the event structure captures a particular button press, it goes on to unbundle a bundle of possible messages in order to select the right message to send. Once it finds the correct message to send, it creates the packet, wrapping a sync word and a checksum before and after it, respectively. Then it shoots it out to the port.Is the unbundling taking a lot of time? I would include images of my VIs except I really have no idea what is causing this lag in writing to the serial port. :headbang: Thanks. 2712[/snapback] Can you post a screenshot of the frame\case that does the message sending. Something sounds fishy. You are mixing the terms case and state. Are you using a state machine architecture or a plain event structure in a loop? Quote Link to comment
JackHamilton Posted November 29, 2004 Report Share Posted November 29, 2004 I'm not understanding why you have two loops accesing the same hardware that can only be controlled synchroniously? How are you handing access to the single resource (serial port). You should only have one loop controlling all read/write activity of the serial port. This way you don't interrupt a read when a write request comes along. Normally, you should not see much of a delay other than that attributed by the baud rate. It will be difficult to debug problems if two loops are competing for the same resource - how do you know a write preceeds a read for requested data? Some more detail - or a snapshot of the code would be great. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.