NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
wheels1950
Posts: 10
0 Kudos
Accepted Solution

Analysing RS-232 ascii data

I have a need to compare incoming RS-232 ascii data to tables or arrays for accuracy. I can generate the data using the RS-232 module but I'm not sure what to do with the incoming data. The commands and the incoming data vary. The data comes in to a string variable. Becuase it varies with the command I'm not sure how to compare it to a lookup table etc.

 

JLW

Active Participant
CJ_Butler__DASYLab_Pro
Posts: 740

Re: Analysing RS-232 ascii data

Is it all string data? Or is it numeric data?

 

If it's string data, then DASYLab is probably not the best tool to use. 

 

If numeric, I'm wondering why you are using strings? 

 

I have to find a serial port and a loopback connector... I'll run the worksheet with it, and see if I can understand more.

- cj
Member
wheels1950
Posts: 10
0 Kudos

Re: Analysing RS-232 ascii data

Its all string data so far from the serial port. I was thinking of using the strVal command in the expression area to retrieve a number. Or I could try to parse the number out of the serial data coming back from the port. You probably no the parsing commands to retrieve the numeric data from the ascii returns.

 

Where is the info to learn how to parse the incoming data? Have not found that yet. All I need to do is compare either the string data or numeric data (better) to a know value or range of values (pass/fail) and I'm done.

Active Participant
CJ_Butler__DASYLab_Pro
Posts: 740
0 Kudos

Re: Analysing RS-232 ascii data

I'm just so excited about this solution that I'm posting it.

 

There are two ways, one is to only parse the incoming strings for the Current values. That left you feeling like it wasn't a complete solution. 

 

Your current application sends out a series of command strings, and then copies the device responses to Global Strings... 2 or more for each command sent. 

 

All of the lines that have data include the phrase "Current = " before the number and <space>( after it. Because this is well defined, and you can bracked the number, you can extract the value from the string.

 

You can define a global variable to parse the string to find the number using the Define Global String-->Definition function.

 

strval (substr ( ${STR_3}, strind (  ${STR_3}, "Current = ")+10,strind (  ${STR_3}, " (") -${VAR_1}-3 ) )

 

 

To find the help for this, get into the definition dialog for the global variable, click the String Functions button at the bottom and click the Help button in that dialog.

 

See the attached... 

- cj
Active Participant
CJ_Butler__DASYLab_Pro
Posts: 740

Re: Analysing RS-232 ascii data

To find the relevant help for the RS232 module, put the mouse cursor into the Measurement Data Format field in the dialog box -- then click Help.

You'll see the help for that parameter.

 

PrintScreen-0031.jpg

- cj
Member
wheels1950
Posts: 10
0 Kudos

Re: Analysing RS-232 ascii data

I get an operator error when I try to paste this command

Active Participant
CJ_Butler__DASYLab_Pro
Posts: 740

Re: Analysing RS-232 ascii data

There is an error in my formula... it relies on a variable that isn't really defined.

 

So,

 

strval (substr ( ${STR_3}, strind (  ${STR_3}, "Current = ")+10,strind (  ${STR_3}, " (") -strind (  ${STR_3}, "Current = ")+10 ) )

 

the syntax is:

 

substr ( string, start, length)

 

strind ( string, search string) -- gives you a number that is the start of the search string, so you need to add to it to advance to the end of the search string

 

strval (string) - turns a string into a number

 

So, to deconstruct the formula

 

Find the location of the number, in this case, it's immediately after "Current = ", so search for that string, and add 10 to advance beyond it.

Find the location of the following parenthesis, search for "("

Compute the length of the number by subtracting the position of the parenthesis from the position of the start of the number

 

xxxxxxx Current = 42.0 (ampsx10)<CR>

 

             ^              ^      ^

             A             B     C

 

A is strind (  ${STR_3}, "Current = ")

 

B = A + 10, or strind (  ${STR_3}, "Current = ")+10

 

C = strind (  ${STR_3}, " (")


length of B = C- B, or C-A+10

 

So, using this notation, the above formula is

 

STRVAL ( SUBSTR ( STRING, A+10, C-A+10) )

 


- cj
Member
wheels1950
Posts: 10

Re: Analysing RS-232 ascii data

way to go!!

Member wok
Member
wok
Posts: 12
0 Kudos

Re: Analysing RS-232 ascii data

dear friend,i am working on a project where i have a gwinstek GDM-396 multimeter to be conneted to an RS 232 port.

watever voltage is recorded from the multimeter should be trasmitted on a waveform chart in labview. i have written a labview program but i am always getting a 0 output.i have already set the parameters(parity,baud rate...) of the multimeter in the labview also. i am quite new to labview. help me please to get that output voltage in labview.

please find attached my program.i am using labview 7.0.

thanks

Member
Blake-C
Posts: 60
0 Kudos

Re: Analysing RS-232 ascii data

Wok,

 

Here is a list of the third party drivers that National Instruments provides:

 

http://search.ni.com/nisearch/app/main/p/bot/no/ap/tech/lang/en/pg/1/sn/ssnav:idr/q/instek/

 

Hopefully that will help. I didn’t see a driver specifically for the GDM-396 but it’s possible that one of the other drivers might work. You’ll need to know the specific commands that are used with the GDM-396 in order to operate with the meter. I would suspect that those commands are in the user manual that you received with the meter or could be found near the product page.

(http://www.gwinstek.com/en/product/productdetail.aspx?pid=39&mid=80&id=204)

 

These commands are written to your VISA Write “write buffer”. You could create a control on the front panel to operate between these commands.

Blake C.
Applications Engineer
National Instruments
www.ni.com/support
By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page