Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Write data to serial port with time delay between string

Hi I am using the "Basic Serial Write and Read.vi" example in labview.

 

Can anybody tell me how to write a string with a time delay after each line?

 

The reason I need to do this is the modem that I'm sending data to needs a 100ms delay between strings.

 

For example:

 

Text1 blah blah blah/n     need a 100ms delay

Text2 blah blah blah/n     need a 100ms delay

Text3 blah blah blah/n

 

Your help is appreciated.

 

Kind regards

 

Mark  

0 Kudos
Message 1 of 13
(7,994 Views)

Hi Markwtc,

 

I would try putting a for loop around the serial write and wait commands, that way you will call your write three separate times after waiting the specified amount. You will need to create an array of strings, one entry for each write, and then index them through the wall of the for loop.

SerialWriteLoop.JPG

Let me know if that works for you.

 

Thanks

Scott M.

Applications Engineer
National Instruments
Message 2 of 13
(7,978 Views)

Hi Scott,

 

Thank you for your reply. I am a novice learing Labview. I have spent a few hours learing how to make arrays but need some adivce to put it all together.

 

Can you please have a look at the attached file and offer some advice.

 

Kind regards,

 

Mark

0 Kudos
Message 3 of 13
(7,969 Views)

Hi Mark,

 

The for loop needed to be around the serial write command, and the "-" character in your strings was "subtracting" the rest of the string. You can delete the "read" section from the code if your not going to be using it. Have a look at this see if it gets you going in the right direction.

 

Scott M.

 

Applications Engineer
National Instruments
Message 4 of 13
(7,932 Views)
Scott M:  I am working with something similar. When you say "...array of strings, one entry for each write" does this mean that the quantity of command lines we can send out is limited to how many entries we create? For example, if I made 4 entries in the array I wouldn't be able to send out more than 4 commands in a Run cycle? 

For my purposes it would be nice if there was a way that it didn't matter how many lines of command the user wanted to send, and there was just a time delay in between every new line that was input into a "write" command box. This is if I don't know a maximum for number of commands someone using my program will want to send.

 

Thanks so much for any help

0 Kudos
Message 5 of 13
(7,927 Views)

If you want the ability for a user to type multiple lines in a string control, you can have code that separates the lines into an array.

0 Kudos
Message 6 of 13
(7,922 Views)

What code would separate the lines into an array? Will that still include the time delay in between each line?  I am working off of the screen shot from above, but using a serial read and write that writes one byte at a time.

I'm not sure what settings to use for the string array, which looks like this in my program: string array image.JPG

 I can't find anything in LabVIEW that tells me what either box is supposed to mean, or what values I should be putting in, but I do know that I can create more of the one on the right side.

0 Kudos
Message 7 of 13
(7,914 Views)

Sorry, but I don't know what you are asking now. You can use the example posted with an array of commands. You or the user can enter each command into a single element of the array. If you don't want to use an array on the front panel, you can use a single string control and then create the array with something like Spreadsheet String to Array. You would use either a carriage return or line feed as the separator (I don't remember which will work). Use the rest of code above.

 

Your comment about 'what either box is supposed to mean' is confusing. It's just a string array (a numeric for the index value and the string box for data) and the values you enter into the array are whatever commands you want to send to the instrument. None of the commands are going to be documented in LabVIEW, of course.

0 Kudos
Message 8 of 13
(7,911 Views)

I got it to work without using an array.  Since I know the number of characters in each command (6), I was able to have it sending only 6 characters at a time from a string composed of many commands typed one after the other.  I put in an option for the user to control how much time elapses between each command sent.  Keep in mind I started out using the serial-write-and-read-1-byte.vi that is available on this site, so it looks different than the ones above.  However, the elements and wiring I used to carry out this task would also work for the programs above.

Here is my diagram:

 

control for sending commands.JPG

 

0 Kudos
Message 9 of 13
(7,883 Views)
Well, it seems a bit Rube Goldbergish. And your wait in between commands is not quite correct. It executes in parallel to your loop so it does specify the wait after the write. You could add a sequence structure to the write case or simply use the Delay function and wire the error clusters - think dataflow.
0 Kudos
Message 10 of 13
(7,881 Views)