LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Search Text File and send with serial port

Hello,

 

I realize a project during my training course in France.

I must develop an communication with serial port.

I would like look for a text file and send this text file with serial port?

Thank you for your help,

 

Regards

Jérome

0 Kudos
Message 1 of 11
(4,799 Views)

Hello Jérome,

I can give you a conceptual framework for you to study on and to adapt to your actual needs; afterwards, if you have specific questions about some aspect we can deep into technical details.

 

Basically your application will have the following steps:

 

1. Locate the text file to handle

CVI offers some functions to browse system resources and locate the files: FileSelectPopup is the most flexible you can use, since it permits you to browse either local, removable and remote resources

 2. Open and configure the serial port

OpenComConfig is the function that permits you to open the port with desired settings. Be sure to match speed, parity and so on with receiver settings. I suggest you to set -1 as the output queue size so to bypass windows internal buffers and write directly to the port: you will achieve a slightly more predictable behaviour in your program

3. Open the file

I personally prefere to use native CVI Formatting and I/O library functions, which I consider more user friendly with reference to error checking; in any case CVI offers both those functions (OpenFile) and standard ANSI C function (fopen): if you may have options to port this code to other platforms perhaps ANSI C code will be better

4. Create a loop to read a bunch of file and transmit to the port

Continuing with CVI library, you can use ReadFile to read a fixed amount of bytes from the file and ComWrt to send it to the serial port. The equivalent ANSI C function will be fgets.

Within the loop you may add instructions to read user input (e.g. cancel requests) and system events if you want

5. At file end, close the file (CloseFile / fclose) and the port (CloseCom) and that's all.

 

Don't forget to add error checking to your program: when dealing with disk and serial I/O this is a crucial aspect that differentiates a well developed program to a bad one!

Some informations on error checking can be found in the online help: look for "Checking for errors in CVI" item in the Programmer Reference help; additionally you may want to look to my contribution on this subject.

Message Edited by Roberto Bozzolo on 05-17-2010 09:58 AM


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 11
(4,800 Views)

Thank you very much for your rapid answer !

I have taken the example in Labwondows for create the communication of serial port. I have taken serial like example.

And I want added the selection of text file and the send of this text file.

Can I have a bar of selection to choose the text file ? Because I dont see the function in the *.iur that I must use to choose the text file.

And after I create a buckle "while" to send all octet in my text file ?

 

Thank you for your help and sorry for my english!

 

Regards

0 Kudos
Message 3 of 11
(4,795 Views)
There is not a UIR control that performs file selection: you may want to add a simple button to start the process and inside its callback call FileSelectPopup () function that opens standarg file selection dialogue. The function has several parameters and can be tailored in several ways so I suggest you to look at the online help for it for an explanations of available possibilities.


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 11
(4,780 Views)

Ah yes ok !! Thank you !

And when my file text is loaded, I have all character in my output it's true ?

I can send all character after ?

And I would like affich all character when I load, Can I use an Text Box or other function ?

0 Kudos
Message 5 of 11
(4,772 Views)

FileSelectPopup simply returns you the complete pathname of the selected file, it does not actually opens it. It's up to you to do what you want on the file.

Depending on file size, after opening it you can read it completely or read in pieces (the loop I mentioned before).

Yes, you can display file contents in a textbox with ResetTextBox

 

 

It has come to my mind that you can use ComFromFile to perform your task: read the command instructions for a detailed explanation on how to use it.

 

 

Please remember that all serial functions are syncronous one: i.e. the system is freezed until they terminate. It is important to understand it since transferring large files over the serial channel may seriously impact over your program responsiveness. That is why I suggested you to split the transmission in a loop.



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 11
(4,770 Views)

Ok ok Thank you !

I have programming this :

case EVENT_COMMIT:
   retVal = FileSelectPopup("", "*.txt","*.txt", "Load Text File", VAL_LOAD_BUTTON, 0, 0, 1, 0, imageFileBuf);
   if (retVal == VAL_EXISTING_FILE_SELECTED)
    {
    Status1 = OpenFile(imageFileBuf, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);

But FileSelectPopup return the adress of text and no the text.

To recup the text, he exist a function for recup the text in a variable ?

Thank you

0 Kudos
Message 7 of 11
(4,758 Views)

How have you defined imageFileBuf? It should be

char   imageFileBuf[MAX_PATHNAME_LEN];

 

What does it mean "returns the address of the text and no the text"? When seeing a char[] variable in the variable window you should see both the address of the array and the string content.



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 11
(4,751 Views)

Yes imageFileBuf is defined char imageFileBuf[MAX_PATHNAME_LEN].

But when I do ResetTextBox(panel_handle, PANEL_2_TEXTBOX_3, imageFileBuf), I see in my text box d:\Documents and Settings\... But I would like all characters contents in the text file.

0 Kudos
Message 9 of 11
(4,743 Views)
Jérome, after opening the file you must read (ReadFile...) it, otherwise you won't see its contents! Smiley Wink


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 10 of 11
(4,739 Views)