Jump to content

ASCII String to MI?


Flex727

Recommended Posts

  • MVP 2023

I have a UniStream 7 that will be a MODBUS TCP/IP slave to a V1210. There are a few ASCII strings that are entered on the UniStream that need to be sent to the V1210. In the MODBUS slave setup on the UniStream, ASCII is not allowed. So, what do I need to do with this? Convert the String to numeric first? If so, what's the best way to go about this so that all the data arrives at the V1210 intact and in the correct order? I am sending 8 ten character strings over to the V1210.

Link to comment
Share on other sites

You are correct, it is not possible to directly send strings using Modbus. To use these functions you will need to use the message composer feature in UniLogic. Then on the V1210 you will need to use the FB Protocol functions to receive the strings.

 

Example webinars that step through each process can be found on our YouTube channel.

 

UniLogic Message Composer: https://www.youtube.com/watch?v=G8bWtpYDt7E

 

VisiLogic FB Protocol: https://www.youtube.com/watch?v=6jpuKTxXznw

 

 

The factor will show the place if a decimal point for the number is located in the ASCII string. For example if the input string has a numeric value of 10.50 then the result will show as 1050 since the value must be a whole number. The factors value will show 100 since the decimal represents the 100's place. If a value of 10.5 is placed in the string the result will be 105 as the whole number and the result will be 10 since the decimal represents the 10's place.

Link to comment
Share on other sites

There isn't any direct string tools that allows for an ASCII to NUM function for non number ASCII values, but you may be able to accomplish this task using the buffer tools. The Copy Buffer to Tag can be used to convert the string into a buffer tag, then the Copy Tag to Buffer function can be used to convert the buffer to an Int array. This should then allow you to link the array within Modbus where it can be directly linked to an ASCII string in the V1210.

Link to comment
Share on other sites

  • 3 weeks later...

Hi! I hope someone of you, both Kings of Uni, might be able to help... :D

The long story short - Unitronics worked hard to make protection of some piece of software a nightmare....

1) System.CPU HW Version. Serial number returns string "Serial number" (wtf?)

2) There are three at least meaningful IDs - CPU, FPGA and Flash, from which I hope, at least one changes from system to system - but to make things harder to accomplish - all are strings as well... (of course, we have function 'String to Num', but as I said Unitronics tried hard to make simple things a nightmare)

Typically I would convert them to nums, XOR them one with another, do some other trick, and, voila, have a "magic number" to compare with for each and every system, the software was put on. But not this time.

3) At least one of those IDs (the FPGA) is HEX! Thus the 'String to Num' isn't working on it.

4) Ok, I thought - let's do it the harder way - cut the string into chars (strings of lenght 1) with 'Middle of String' function (which fortunately works) and then compare them one by one with the 'hex space" ('123456789ABCDEF') which should hopefully return it's position within string, which is exactly the decimal representation of the Hex, by coincidence. BUT...

The 'Find Substring' is a "do it yourself" function, because in addition to, of course, requires parameters 'Source string' and 'Find substring' it also requires 'Index in source' (which I assume, works like - Ok give me the string, give me what to find, AND GIVE ME POSITION WHRE IT SHOULD BE, and THEN I WILL TELL YOU IF IT'S THERE).... That's not exactly a 'find', that's do-it-yourself.... Or at least I have got something wrong. But I never got any meaningful result back from the 'Find Substring' function, except 255 (which, I guess, means 'not found').

 

Anyway, Unitronics lack ANY information on Strings....

 

So, I'm stuck...

I could not get "serial number" because it isn't there;

I could not do math on hardware IDs, because these are strings;

I could not even convert them to numbers, because these are HEX, and there is no function to convert 'String containing HEX to Num';

I could not make function to convert Hex to num, because 'Find substring' is made for nothing (or at least I hadn't found a way to make it work, and there is no help describing how exactly it works).

 

HEEEELP!

Link to comment
Share on other sites

Hi,
The CPU does not return a serial number, so we just return the string "Serial Number". I would not count on the FPGA ID and other IDs to be unique (At least not the FPGA ID, since I already saw it is not unique).

 

The best unique number you can find in your system is the CPU MAC, and the Panel Mac. Mac numbers must be unique.

Those are in HEX as well. You can use the message builder in order to convert the hex string to a num (although, in this case, it will be a little complicated, since the string is in UTF-32), you can also do it in ladder, and if you are using version 1.15.70 (or newer), then you can also write it in C

 

You are totally wrong about the "Find Substring", the index is not for "WILL TELL YOU IF IT'S THERE". The index is a Start Index (like in any other programming language, which have a find substring).

 

For example:

"Hello World"

finding "o" from index 0, will result 4

 

Now that you have found that there is an o on index 4, the new index becomes 4 + 1 = 5

So now you start searching from index 5, and you get the result 7

(This way you can keep searching for the substring inside a long string which might have the substring repeating more than once).

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.