RS232 read string from Labview

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
paulm
Posts: 36
Joined: Mon Mar 28, 2011 9:37 pm
Contact:

RS232 read string from Labview

Post by paulm »

Hi,

I'm using Labview to send and receive data to and from a PIC16F877A via the RS232 port on a PC. I'm using the E-blocks board with flowcode V4.5 to prototype the system before I send it to a PCB.

In Labview, I'm effectively trying to send a value that ranges from 0 - 255 to the PIC in order to control the duty cycle of a PWM waveform to a Motor. However, when I use the ReceiveRS232string function in flowcode, the data I receive it not correctly interpreted. For instance, if I send a continuous stream of values (140) as a string from Labview and I ultimately print this on the LCD screen, it can be displayed as 014, 140 or 401 when I read the string as 3 bytes. It's as if the string function doesn't know the start and end of each string that is sent from Labview.

Also, if I reduce the value in Labview to 71 this is interpreted as 717, and if I further reduce it to say 5 this will be read on the LCD screen as 555. I've included the file Test_16F877A_receive_serial_byte.fcf to illustrate what I'm trying to do.

The bit where I'm really confused is that when I tried sending a string of continuous values from the PIC to Labview the data is interpreted in Labview correctly.

So the SendRS232String function seems to work nicely when used in conjunction with Labview. I've included the file Test_16F877A_send_serial_byte.fcf to illustrate how this is done. It's pretty straight forward and works nicely.

I would be greatful if somebody could advise me on how to receive data values that range from 0-255 on the RS232 port reliably.

Thanks,
Paul
Attachments
Test_16F877A_send_serial_byte.fcf
(9.5 KiB) Downloaded 479 times
Test_16F877A_receive_serial_byte.fcf
(9.5 KiB) Downloaded 498 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 read string from Labview

Post by medelec35 »

Hi Paul,
What I always do is immediately after the printNumber LCD Macro I place a PrintString " " component macro
(Two sets of speech marks separated by two spaces)
What happens otherwise if you print to LCD 123 then immediately follow with 6.
The 6 will write over the 1 but nothing will write over the 23 so you will have 623
With the printString component macro, the 23 will be over written with 2 spaces, so just 6 will be displayed.

Martin
Martin

paulm
Posts: 36
Joined: Mon Mar 28, 2011 9:37 pm
Contact:

Re: RS232 read string from Labview

Post by paulm »

Hi Martin,

thanks for the reply, but I don't think your answer addresses my problem.

Just to clarify, I'm only using the LCD screen to try and debug aswell as illustrate what is actually going on.

I am trying get Labview to output a number between 0 to 255 via a decimal string over the RS232 port.

The first problem is that the numbers 0 to 9 only contains 1 character, whereas 10 to 99 contains 2 characters and finally 100 to 255 contains 3 characters.

The second problem is that when each number is sent as a string by Labview the ReceiveRS232String function in flowcode cannot detrmine the start and end of the string, so the data that is sent is effectively is all concatanated together as one continous string.

As I mentioned, there doesn't seem to be the same problem when I send data from the PIC to flowcode. In otherwords each string is partitioned correctly when it is displayed in Labview.

The only thing I can think of is that flowcode appends a termination character when it sends a string whereas Labview doesn't append a termination character when it send a string.

Thanks,
Paul

paulm
Posts: 36
Joined: Mon Mar 28, 2011 9:37 pm
Contact:

Re: RS232 read string from Labview

Post by paulm »

Correction in previous message:-
As I mentioned, there doesn't seem to be the same problem when I send data from the PIC to Labview. In otherwords each string is partitioned correctly when it is displayed in Labview.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RS232 read string from Labview

Post by Enamul »

Hi
What Martin suggested I use that if I have no problem like printing those numbers at starting cursor position and you have nothing immediately after this number printed in the display. But if you for example want to print the number from 17,0 cursor position and three number will occupy 17,18,19 th position of the display and two spaces will actually moved to 3rd line in a 4*20 display which will over-write first two characters in 3rd line. I use the following in those case:
For example, you want to print data=0 to 255 in 17,0 cursor position.
I use following macros:
cursor(17,0)
printascii(" ")
cursor(17,0)
printnumber(data)

Although it took more memory of program but don't have that risk of overwriting 3rd line characters.Hope that heps :D
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: RS232 read string from Labview

Post by Enamul »

Hi Paul,
I see what you mean. I haven't read through you post :oops: I have been through Martin's post as that is small :P

I have faced similar kind of issue in RS232 Tx,Rx. I have couple of suggestions for you:

1. Instead of Labview please try to send data from terminal (may be Hyperterminal or http://www.ddrservice.net/download/Soft ... l.exe.html) to see whether the problem is in code or in Labview.

2. For Rx, it's better to use RXINT to get string if you are doing any thing else other than receiving RS232 data. Missing is almost obvious otherwise.If you use RXINT you will need to use RS232 char receive not string.

3. You can use RS232 example file which is given in Flowcode example and that's is really useful one to start.
Enamul
University of Nottingham
enamul4mm@gmail.com

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 read string from Labview

Post by medelec35 »

Sorry guys,
I misread Paul's post. :(
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 read string from Labview

Post by Benj »

Hello,

Ok looking at your timeout's I see an issue.

Your first timeout of 255 for the string receive will force the macro to wait forever for three incoming characters. 255 is the maximum timeout that can be used. Reducing the timeout slightly say to 200 will stop the macro waiting forever and allow less characters to be received if less are sent. You may want to flush out your string before calling the receive string macro by using a calculation icon and the following code.

str[0] = 0
str[1] = 0
str[2] = 0
str[3] = 0

For the next receive byte macro again the maximum timeout that can be set is 255. You are currently passing 1000 which will probably not work correctly but looking at the code may be ok. I would again reduce this to something more like 100 - 200.

You could also change the RX timeout unit from legacy to milliseconds in the RS232 component EXT properties window for more reliable timeouts.

I have done work with Labview and transmitting data over serial. I think I had to do some kind of conversion from a unsigned 8-bit value to a unsigned 8-bit array and then convert into a string. Not totally sure on this one as the project was about 5 years ago.

paulm
Posts: 36
Joined: Mon Mar 28, 2011 9:37 pm
Contact:

Re: RS232 read string from Labview

Post by paulm »

Hi Ben,

thanks for the reply.

In Labview you have to use a "Number to Decimal String" converter to send the data over RS232. Incidentelly, I'm sending the data continuosly from Labview every 50-100mSec.

I have a couple of direct questions which may help me understand how flowcode works with strings a little better:-

1) When Flowcode sends a string via RS232, does it append a terminator character to signal the end of the string? If so what is the character it uses?
2) When Flowcode receives a string does it look for an end of string terminator character?

The reason I ask is because when Labwiew sends a number between 0-9 it sends a single character, whereas when it sends 10-99 it sends two characters and 100-255 it sends 3 characters.

If it doesn't use end of terminator characters then what is the easiest way to seperate the individual data values that are sent from Labview?

My thinking is that in Labview I could append a special character to each Number that is sent, so I could then look for that character in Flowcode in order to seperate the numbers that are sent correctly.

Thanks,
Paul

jndlogic
Posts: 6
Joined: Tue Feb 26, 2013 6:47 pm
Has thanked: 2 times
Been thanked: 1 time
Contact:

Re: RS232 read string from Labview

Post by jndlogic »

I have a similar project working. The thing is that i don't send 0-255 as a string but as a char (im using realbasic). In this case you only get one byte of data at a time, wich is easely translated to 0-255 on your display. This is a much easier approach. Im not sure if labview supports this way of sending data. I can easely write you an app in realbasic to test this way. Cheers Davy

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 read string from Labview

Post by Benj »

Hello,

Labview does support sending 0-255 as bytes because this is how I got it working for my CNC machine.

The source is available from here if your interested though you will have to sign up for access to the files.
http://www.001tech.co.uk/Forum/viewtopic.php?f=8&t=4

Labview does not send a termination character so one way to do it is to use the timeout to try and pull out the correct piece of information.

For example say you send this from Labview.

Send "ABC"
delay 100ms
Send "D"

If you set your string receive timeout to say 50 then it should only receive "ABC" or "D" or nothing if the timeout falls directly in between the 100ms delay.

One way to ensure you are getting the right data is to have a packet start character which you can verify on the embedded hardware before processing the incoming data. Another way is to add a check sum which confirms if all the data in the string is accurate. This is probably overkill for your application.

paulm
Posts: 36
Joined: Mon Mar 28, 2011 9:37 pm
Contact:

Re: RS232 read string from Labview

Post by paulm »

Hi Ben,

I managed to get it working by inserting zeros in front of digits that contained less than 3 characters within Labview:-

"00" before any digit from 0-9.
"0" before any digit from 10-99.
No 0 insertion form 100-255.

I'm curious to know if the RS232 string send macro inserts a null character (e.g. "/0") when sending a string?

Also, does the RS232 string receive macro look for the null character to seperate strings that are are in the receive buffer at the same time?

Regards,
Paul

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 read string from Labview

Post by Benj »

Hello Paul,

The send string macro will transmit bytes of a sting up until the last byte or until a null byte is reached. The null is not transmitted.

Again with receiving a string the number of bytes specified is received unless a timeout occurs. Any null bytes received will be appended to the string. If the string length is less then the variable length and a timeout occurs then a null is automatically added to the variable.

From memory Labview does not transmit any null bytes unless you force it to do so by manually sending one.

Post Reply