You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old November 14th, 2017, 04:57 AM   #1
moamed
Member
Egypt

moamed is offline
 
Join Date: Jun 2016
Location: Egypt
Posts: 23
Read Many CHAR using INPUT_CHAR FB Unity Pro ???

Hi Guys

We work in a project using premium CPU TSX P57 4634M
and we want to connect to new device (AminoSys, Evonik) and
the supplier recommend to use PCMCIA card, character mode

So we have to use INPUT_CHAR to read data from this device
it's first time to me to use this function and I read a lot of information about it
but I don't know how to read many different Chars using one Function

I mean in Read_Var Block we receive data in array and every register data stored in one INT of array

but in INPUT_CHAR we receive in one String variable

To illustrate what i mean in attached files there is pic show the 22 different byte we need to reed


Thanks in advance
Attached Images
File Type: jpg Capture.jpg (86.7 KB, 39 views)

Last edited by moamed; November 14th, 2017 at 05:25 AM.
  Reply With Quote
Old November 14th, 2017, 06:40 AM   #2
chud
Member
South Africa

chud is offline
 
chud's Avatar
 
Join Date: Oct 2007
Location: KALAHARI
Posts: 850
You will have to manually extract each bytes values and move them into your own string variables. Then convert them to integers to actually do some calculations or compares etc.
Thats the downside of serial character mode or ascii
You can use functions like delete_int or concat etc. Have a look in your library for string functions.
Manual coding awaits you
  Reply With Quote
Old November 14th, 2017, 06:47 AM   #3
moamed
Member
Egypt

moamed is offline
 
Join Date: Jun 2016
Location: Egypt
Posts: 23
Thanks Chud for your reply
  Reply With Quote
Old November 14th, 2017, 09:50 AM   #4
moamed
Member
Egypt

moamed is offline
 
Join Date: Jun 2016
Location: Egypt
Posts: 23
Quote:
Originally Posted by chud View Post
You will have to manually extract each bytes values and move them into your own string variables. Then convert them to integers to actually do some calculations or compares etc.
Thats the downside of serial character mode or ascii
You can use functions like delete_int or concat etc. Have a look in your library for string functions.
Manual coding awaits you
But now there is a problem that the max length of the String is 16 digit or CHAR
where in my case the device send at lest 22 digit this mean I have to receive it in more than one String ????????
  Reply With Quote
Old November 14th, 2017, 11:45 AM   #5
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 924
Nope. Default string lenght is 16chars. You can have longer string variables if you configure data type string[22] or string[50] and so on.

On animation view string can still show 16characters also for longer string types but with string blocks you see that there is every character.

You maybe can construct array of string (array 1..11 of string[2]) and Unity divides string to different bytes. (This is wild guess, I haven't tested)

Last edited by Lare; November 14th, 2017 at 11:51 AM.
  Reply With Quote
Old November 14th, 2017, 12:05 PM   #6
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 924
Tested with simulator.

On variable editor

string_test1, ARRAY[1..11] OF string[2], %MW0

Works easily. there is 11 different elements.
On communiation block you use string_test (Full array)
Characters are divided to string_test1[1] / %MW0, string_test1[2] /MW1 .. string_test1[11] /%MW10 variables.

You can also defide string without address.


Also string_test2, string[22], %MW0 gives same result, but now you can only use %MWx addresses on program side.
On variable side you can have string_int variable with %MWx addressing,. String is converted to numerical result automatically.


string_test3, ARRAY[1..22] OF string[1], %MW0
This divides string to 22 different chars.

string_test4, ARRAY[1..11] OF string[2]
This divides string to 11 different chars, no %MW memory used

Lot of choices
  Reply With Quote
Old November 15th, 2017, 06:01 AM   #7
chud
Member
South Africa

chud is offline
 
chud's Avatar
 
Join Date: Oct 2007
Location: KALAHARI
Posts: 850
"On variable side you can have string_int variable with %MWx addressing,. String is converted to numerical result automatically."

Very nice never knew that.saves some time
  Reply With Quote
Old November 15th, 2017, 09:34 AM   #8
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 924
Quote:
Originally Posted by chud View Post

Very nice never knew that.saves some time
It works because on Unity you can have several different name and type variables with same memory address (%MW or %M)

Haven't used it, but it should convert to hex based number.
Only disadvantage is that it uses %MW side adressing and values are transferred between different variables on backgroud and it isn't showed on logic code.
Also Unity gives warning of multiple use of memory address (You can disable warning from settings)


Another way is maybe to use variables with alias naming.

3rd way is to use array of strings and converting string to numerical values with blocks. Using arrays save time, because there is no need to divide string to different parts with string block commands.

Because Unity is symbol name based PLC, using string with arrays (without any %MW adressing) is maybe best.
Even that using %MW "indirectly" also works
(using %MW is more for old PL7 which was memory based PLC)

Last edited by Lare; November 15th, 2017 at 09:44 AM.
  Reply With Quote
Old November 19th, 2017, 03:49 AM   #9
moamed
Member
Egypt

moamed is offline
 
Join Date: Jun 2016
Location: Egypt
Posts: 23
Thanks Guys I really appreciate your time
  Reply With Quote
Old November 21st, 2017, 08:51 AM   #10
moamed
Member
Egypt

moamed is offline
 
Join Date: Jun 2016
Location: Egypt
Posts: 23
Quote:
Originally Posted by Lare View Post
Tested with simulator.

On variable editor

string_test1, ARRAY[1..11] OF string[2], %MW0

Works easily. there is 11 different elements.
On communiation block you use string_test (Full array)
Characters are divided to string_test1[1] / %MW0, string_test1[2] /MW1 .. string_test1[11] /%MW10 variables.

You can also defide string without address.


Also string_test2, string[22], %MW0 gives same result, but now you can only use %MWx addresses on program side.
On variable side you can have string_int variable with %MWx addressing,. String is converted to numerical result automatically.


string_test3, ARRAY[1..22] OF string[1], %MW0
This divides string to 22 different chars.

string_test4, ARRAY[1..11] OF string[2]
This divides string to 11 different chars, no %MW memory used

Lot of choices
I'm Sorry sir but I try to do what you mention but Function (INPUT_CHAR) didn't accept Array of strings tags, it accepted only String tags

Like attached Pic

Idea of Array of String will be very helpful as in this case each byte or Char will automatically stored in element of array

So I hope it work but it didn't

Did I do any thing wrong ???????
Attached Images
File Type: jpg INPUT_CHAR2.jpg (71.5 KB, 14 views)
  Reply With Quote
Old November 21st, 2017, 01:30 PM   #11
Lare
Member
Finland

Lare is offline
 
Join Date: Jan 2006
Location: Finland
Posts: 924
I haven't tested this with character read and write blocks.

Simulator showed that it would work, now with real M340 CPU I see that there is coping problem between different string formats.

If string has first value 'abc' it will copy to different object.
If I change value to 'abcd' if will also copy to second string (both strings have %MW address)
Now if I change value to 'aa' it copies to 'aacd', old characters which isn't there anymore stays on second string

Looks like you need to code with long way, concat, delete, etc.
  Reply With Quote
Old November 22nd, 2017, 07:16 AM   #12
chud
Member
South Africa

chud is offline
 
chud's Avatar
 
Join Date: Oct 2007
Location: KALAHARI
Posts: 850
or use the gest management bits to clear the data (move) you are writing to 1st before writing the next time
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Topics
Thread Thread Starter Forum Replies Last Post
Schneider Momentum & Unity Pro MATT116 LIVE PLC Questions And Answers 2 February 24th, 2015 09:57 AM
Schneider Unity Pro - DFB / DDT / Arrays majorv LIVE PLC Questions And Answers 9 February 16th, 2015 06:12 PM
Unity Pro XL 5.0 and Windows 2008 R2 kutuz LIVE PLC Questions And Answers 3 July 21st, 2011 03:04 PM
Schneider - Unity Pro - Citect etc BobB LIVE PLC Questions And Answers 11 January 15th, 2010 03:13 PM
Unity Pro XL - read only variable issue SCADA_Dude LIVE PLC Questions And Answers 5 March 28th, 2008 06:18 AM


All times are GMT -5. The time now is 11:58 AM.


.