DASYLab

cancel
Showing results for 
Search instead for 
Did you mean: 

RS232 data format

Solved!
Go to solution

Dear all Dasylab users. I am using Dasylab to connect TSE Syringe pump to PC. I managed to get Dasylab to communicate with my device, but I am having trouble parsing the data effectively. I've been searching the forums and think this has a very simple solution.

I'm just having trouble finding the correct command to put in the "measurement data format" box for each channel. I get a string: <STX>00P900.5MH<ETX> (in RS232 monitor)

(It means 00 channel; P status;900.5 value; MH unit) I tested plenty possibilities but nothing works. I need to get all 4 information. Status and unit to the Global string 11 and 12. I thing the correct measurement data format would be:

 

Channel 0 - "\x02" 2a

Channel 1 - $11 1a

Channel 2 - 5a

Channel 3 - $12 2a \r\n

but it doesn’t work (numbers are correct but the strings not). I use (for measurement data request) string “RAT\r\n” at Chanel 0, the other channels are empty.

 

The second problem is when I need second information. I use next Channel (Channel 4) with measurement data request RAT\r\n and measurement data format "\x02" x3 5a \r\n. I get in RS232 monitor string <STX>00P42.48<ETX>. If I use only this one channel (as Channel0) so it works correctly but it doesn’t work with the previous four channels.

0 Kudos
Message 1 of 19
(9,942 Views)

First, you can't use the same search string twice... it's ambiguous. That's the problem with the second string. 

 

I'll need to see if I can do this locally... any chance that you can use Hyperterminal or some such to log a bunch of data strings? 

Or, use the RS232 monitor to repeatedly send the data request command and then send me the print screen of that.

 

Measurement Computing (MCC) has free technical support. Visit www.mccdaq.com and click on the "Support" tab for all support options, including DASYLab.
0 Kudos
Message 2 of 19
(9,939 Views)

See attached picture.

 

I think, you cannot get the status "P" into a global string only by using the format-string of the RS232 input.

 

Using $<number> is always a variable length (like using "a"), so that would need a terminator.

But between ...P... and ...9... is none. (  <STX>00P900.5MH<ETX>  )

You cannot say $<number> 1 to tell DASYLab to write only a single letter into a global string.

 

So, you need to use the ascii/hex-value of the P (80h) as number. Use an action module to make a decision what to write into the global string that should hold the status.

M.Sc. Holger Wons | measX GmbH&Co. KG, Mönchengladbach, Germany | DASYLab, DIAdem, LabView --- Support, Projects, Training | Platinum NI Alliance Partner | www.measx.com
0 Kudos
Message 3 of 19
(9,927 Views)

Thank a lot for your help.

Using the "b" instead of "a" helps solve the problem with channel1. But problem with channel3 (UNIT) survive. The string is empty. I can use the same solution as for channel 1(may be, it is even better because I can transfer MH to ml/h) but I would like to know how to send it to the string. (I tested both $12a\r\n and $12a\r strings) It looks, that measuring one time checks the channels 0, 1 and 2 and then waits. (I have action and message box connected to input and if the measuring is correct the messages repeated each 0.5 s (this is a sampling frequency).

I know that is impossible to use the same search string twice, but I don’t know how send next question/string to the equipment. I tested use new channel and also new slave module, no success.

Now, when I have the formats:

Channel

Format

request

answer

0

"\x02" 2a

RAT \r\n

00

1

b

 

83

2

5a

 

900.5

3

b

 

77

4

b

 

72

Everything is correct. When I add one channel, one times the correct values appears at first 5 channels but then all goes wrong and measuring waits:

Channel

Format

request

answer

0

"\x02" 2a

RAT \r\n

00

1

b

 

83

2

5a

 

42.48

3

b

 

72

4

b

 

83

5

4x 5a

DIA \r\n

-

 

When I use monitor and switch repeatedly Chn.0 and Chn.5 I obtain:

undefined

(To CJ Butler: I tried to get data from HyperTerminal, but I am not able to connects the equipment.)

0 Kudos
Message 4 of 19
(9,898 Views)

The data from hyperterminal:

undefined

0 Kudos
Message 5 of 19
(9,895 Views)

The problem is, that the messages from the device do not have the same format: one has the MH unit ( <STX>00P900.5MH<ETX> ), the next lacks the unit ( <STX>00P42.48<ETX> ). Another difference is the length of the value, one has a length of 5, the other has a length of only 4.

 

You cannot use the same format string in the RS232 module to parse both types of messages.

(That would be possible if there were seperators-symbols between the parts of one message, like <STX>00-P-900.5-MH<ETX>.)

 

Try this:

Remove the data request from the RS232 input, and request the data with a RS232 output module, request the data twice! The first answer will have the message type "with-MH-unit-and-5-lengthed-value" ( <STX>00P900.5MH<ETX> ), the second answer is of type "no-unit-shorter-value" ( <STX>00P42.48<ETX> ).

 

The RS232 input will now get more channels, that will parse both received messages entirely.

In DASYLabs buffer it looks like one big message: <STX>00P900.5MH<ETX>\r\n<STX>00P42.48<ETX>\r\n.

 

You have to make sure, that the message with type "MH-unit, value-length 5" is received before the other message type.

M.Sc. Holger Wons | measX GmbH&Co. KG, Mönchengladbach, Germany | DASYLab, DIAdem, LabView --- Support, Projects, Training | Platinum NI Alliance Partner | www.measx.com
0 Kudos
Message 6 of 19
(9,890 Views)
Solution
Accepted by topic author BobPupak

I wonder if you put it all in a string, and parse the string in the Extended/Definition

 

Try "\x02"$19\x03

or,  simply 1x$19\03

 

It will have 00S42.8 

 

 

Then, create two variables,

 

first is the Channel number, and the expression is: strval(substr ( ${STR_19},1,2))

second is the Value, and the expression is: strval(substr (${STR_19} ,4  ,strlen (${STR_19})-3 ))

 

And create a second string where the expression is: substr($STR_19),3,1)

 

 

That way the value can be variable length.

 

The same technique for the second value, since the first string has been completely consumed, the second string can be parsed the same way

 

1x$20\x03

 

And set up two variables and a string for it too.

 

Then.... use the Control Group- Variable Read module to play it out into the worksheet. 

Measurement Computing (MCC) has free technical support. Visit www.mccdaq.com and click on the "Support" tab for all support options, including DASYLab.
0 Kudos
Message 7 of 19
(9,879 Views)

Thank a lot for your help. I tested the solution with strings (the second one) and it works very well. (I use it because in fact I need to get more than two strings and I feel that with the second solution I will have the results more under control.) Anyway, thank both of you. You both help me a lot.

0 Kudos
Message 8 of 19
(9,866 Views)

I have only small question: Is there any possibilities haw to transfer Letter in global strings to number? The best way would be to understand letter as ASCI number. ("E" would be 69). There is 12 letters that I need to transfer. I can use several strings with many "StrSel" functions but it is too inconvenient. Is there something like StrVal function, but with input as ASCI format?

0 Kudos
Message 9 of 19
(9,858 Views)

That would have been a useful function.... aside from suggesting that you update to DASYLab 13 and use the Script module to write a quick conversion program, the best way to do this is to set up another formula.

 

Define a variable, create the expression, something like this:

 

(${STR_1}="A")*value1  + ($STR_1="B")*value2 + ..... 

 

The test is in the ( ) and the result of the test is 0 or 1.

 

Multiply by the desired result... as long as the tests do not overlap, the output will be the one value that you want, since only one factor will test true. All the others will test false and will be multiplied by 0.

 

For a really simple test, you can use the STRSEL(, , ,) function -- the parameters are the test, the value when true and the value when false.

 

All of this will be MUCH easier with DASYLab 13 (Full or Pro versions), since you can write a Python script to simply convert the ASCII to a byte character.

 

Was this a plug for DASYLab 13? Forgive me... we put a lot of work into it, and we want to get the news out! Check out www.dasylab.com for more information.

Measurement Computing (MCC) has free technical support. Visit www.mccdaq.com and click on the "Support" tab for all support options, including DASYLab.
0 Kudos
Message 10 of 19
(9,851 Views)