Jump to content

Message composer & parse message


samJones

Recommended Posts

Hi,

This is -hopefully- a relatively simple question, but I'm a bit out of my depth so apologies if I manage to confuse the situation with imprecise terminology!

I need to read (and ultimately log) the serial output of a third party device to a Unistream PLC. The device outputs six values (e.g. 5.10945e1 1.00361e2 -2.58244e2 -1.2803876e-1 8.77776e1 2.5464391e-1) as string (hexidecimal, length 70) that ends with a return (OD) and new line character (OA) e.g.

image.thumb.png.b09577b8e0f2caa006416e8fa6b8c1c8.png

I can read this string into a buffer tag using the Com Rx function and I can see in online mode that the data arrived bit tag is updating at the correct rate and that the hexidecimal values received by the buffer tag seem to respond sensibly.

image.thumb.png.a9ecc53e7910d337460af9e19c5edf70.pngimage.png.bd04046c0cd5dc91f9248fa4536cb2c8.png

However, I'm stuck trying to understand how to go about defining the contents of the buffer tag as a message in Message Composer so that it is recognised by the Parse Message function. 

image.thumb.png.21cd187520db2a0ebf79b088f8d9b5bb.pngimage.thumb.png.4cd316ec1694ba4186f10b3a849d6459.png

I would greatly appreciate any suggestions about how to do this or resources that might help me better understand my problem! I have found useful information here and in the video tutorials but I'm obviously still lacking some critical piece of knowledge! Ultimately I would like to end up with 6 data tags containing ASCII values that I can append to a .csv file created elsewhere in the program, but I'm not at this moment clear on the steps in between. Hopefully the above makes sense, if not I'll try again!

Many thanks in advance,

Sam

 

 

 

Link to comment
Share on other sites

incubationSystemV4forum.ulpr

Hi Joe,

Yes, indeed it is. The message is broadly along the lines of <data><20><data><20><data><20><data><20><data><20><data><20><OD><OA>

However I suspect I'm not specifying the elements correctly.

Please find the code attached. Any suggestions to get me back on the right track would be greatly appreciated!

Cheers,

Sam

incubationSystemV4forum.ulpr

Link to comment
Share on other sites

  • MVP 2023

When I opened this it says it was made with UniLogic v1.23.25.  You need to update your UniLogic to v1.28.26 - this is what I saved it in and there have been some improvements to the Message Composer since your version.

I edited your Message  "test message" and embedded REAL data types with tag names T1 through T6.  You already had the 20h spacers in there.

Let me know if it works.  I did not load and test it in a PLC, so I'll need you to report what happens with this code.

Joe T.

 

incubationSystemV4forum JT.ulpr

Link to comment
Share on other sites

Hey Joe,

Thank you very much for taking a look at this for me.

When I run your alterations I receive the error "Feature: message composer; File: message composer; Line: testDevice-testMessage; Description: Error, a scanned message cannot contain real types ".

However your edits have inspired me to find a solution (albeit not a very pretty one!) to my problem. Essentially I have added 65h (e) as a control character to the message in order to parse the number and exponent (because the instrument outputs in scientific notation) as integers,

e.g. <data1><65><exp1><20><data2><65><exp2><20><data3><65><exp3><20><data4><65><exp4><20><data5><65><exp5><20><data6><65><exp6><20><OD><OA>

, and then recombined the integer (T_whole), fractional (T_frac), decimal (dec) and exponent (e) parts for each to achieve the desired real number data tag (T_complete) to log e.g.

rung13.thumb.PNG.ce39c4df61aa0d3b327c0fe395646744.PNG

This seems to do the trick. I've attached the code here in case it might be of use to another lost soul in the future or someone can suggest a more efficient solution!

Cheers,

Sam

 

1865654005_incubationSystemV4forumJTSJ.ulpr

Link to comment
Share on other sites

  • MVP 2023
8 hours ago, samJones said:

"Feature: message composer; File: message composer; Line: testDevice-testMessage; Description: Error, a scanned message cannot contain real types ".

Well that's irritating.

Your solution, however, is clever.  Pretty has nothing to do with it.  I have done similar hackulations using the tools available to me to overcome the limitations of this and other brands of PLCs.

All that really matters is it works.  Make sure your add some comments to that ladder code before you save it off so you can remember what you did when you look at this a year from now.

Good job!

Joe T.

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...