LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Execute a non Stop Action during others actions

Hello,

 

I have a problem with my program. I have developping a communication with the serial port with the example of Labwindows. But it read when the users rest on the button. I would like read the serial port all the time and can do other action in the same time. Can you help me please ?

Thank you,

Regards

0 Kudos
Message 1 of 9
(4,427 Views)

Hi romess, here you are with the need of performing several tasks inside the single program. This can be obtained in several ways; here a non-exhaustive list of possible solution, in order of increasing complexity:

 

  • Standard UI timer: inside the callback perform the serial port activity. Given the time of the serial port process, you must define a timer interval so that some time is left for user interface activity
  • Asyncronous timer: the same as above, with some multithreading added due to the way async timers are structured. CVI offers a specific instrument (<cvidir>\toolslib\toolbox\asynctmr.fp) to handle such timers; they have the same callback definition of standard UI timers so that what you have developed for the above solution can be portes almost 'as is' to async timers
  • Multithreading

When developing programs that have two or more independent tasks, some precautions are to be taken in order to prevent contemporaneous access to shared resources or to internal variables/objects: a good starting point is to read <cvidir>\bin\MultithreadingOverview.pdf document, which even if aimed to pure multithreading structures, nevertheless gives you a conceptual framework on the possible problems you can find and how to prevent them.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 9
(4,419 Views)

Thank you very much Roberto for your rapid answer.

A person tell me to use ProcessSystemEvents and thread to execute one action un loop all the time and all the action of the program in the same time.

But I dont know if it exist others functions to make this ?

And i dont see how do to realize this ?

Can you help me please ?

Thank you very much

0 Kudos
Message 3 of 9
(4,416 Views)

I personally discourage systematic use of ProcessSystemEvents in a program as it may interfere with normal events handling by the system and can cause unpredictable situations.

 

Before going that way you should at least give a try to some examples that come with CVI: samples\userint\timer.prj to shows you how to use standard UI timers and gives some caveat in their usage.

A step above can be to study  samples\toolbox\asyncdem.prj application, which gives you an immediate comparison between standard UI timers and asynchronous timers.

As per multithreading, I suggest you to use Help >> Find Example menu function and search for "multithreading" keyword: starting from "simple.prj" example listed there you can progressively deep into multithreaded programming.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 9
(4,414 Views)

Ok Thank you very much. I have found. 🙂

But I have just one last question.

I send in the serial port ascii bytes. But my program must receive just Hexadecimal byte.

Does it exist a function who convert ascii to hexadecimal?

Otherwise how can I do to Convert ?

Thank you for your help.

0 Kudos
Message 5 of 9
(4,399 Views)

Don't make the error of considering ascii, int and hex as separate things with need to convert between each other! They are nothing but different representations of the same bit pattern: either you say (int)65 or (octal)101 or (hex)0x41 or (ascii)"A" or (binary)01000001, you are always treating the same exact thing. So unless your external device sends you a message like "0x41" (4 characters), the string you receive in ComRd needs no convertion at all and what you call "hexadecimal bytes"can simply be a hexadecimal representation used in the documentation to make things clear.

 

Different is the case if you need to pack two or more received bytes into a more complex data type (short, in, float...): if this is your situation, I'd like to know what exactly you need to do with received data before answering in a possibly wrong way.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 9
(4,384 Views)
In reality, my program say to the user to enter hexadecimal bytes. But when I enter this value, when my programm affich this value, It's not that I like. When I use the program with Hyperterminal, I have create a program who take the ascii value and return the hexadecimal value partner. And I would to do the same thing with my Labwindows program.
0 Kudos
Message 7 of 9
(4,348 Views)

That is: you have a string control in which the user enters something like "0x41, 0x42, 0x43" and you want to send to your instrument the string "ABC", right?

 

So:

 

char   inS[32], outS[32];

 

GetCtrlVal (panelHandle, PANEL_STRING, inS);

sscanf (inS, "%x,%x,%x", (int *)&outS[0], (int *)&outS[1], (int *)&outS[2]);

 

the result of all this is the string "ABC" in outS variable which can be sent through the serial port.

Of course this is just a framework: you must add some check for validity of user input and scan/format appropriately the strings.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 9
(4,340 Views)
As alternatives you can think of using ANSI C strtod () function with base 16 to scan user input, or Scan () function from CVI Formatting and I/O library.


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 9
(4,336 Views)