05-21-2010 03:29 AM
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
05-21-2010 04:32 AM
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:
05-21-2010 04:40 AM
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
05-21-2010 04:56 AM
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.
05-21-2010 07:07 AM
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.
05-21-2010 09:15 AM
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.
05-25-2010 03:15 AM
05-25-2010 04:29 AM
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.
05-25-2010 04:43 AM