Andy_P

Read an array of strings from NJ to NA

16 posts in this topic

I have an array of 1000 strings in an NJ controller, and I wish to read them into an NA HMI.

To do this at the moment I am using Array.Copy within some vb code, but this seems to hang the screen as it takes way too long, if it ever completes at all.

i.e. Array.Copy(NJ_array, NA_array, 1000)

also, the docs for Array.Copy state that the destination array needs to be greater in size than the source array, which seems bizarre.

Any recommendations on how to do this more efficiently?

Share this post


Link to post
Share on other sites

Why do you need to copy the Strings? Why not just use the Variable Map in NA to get the values of the said Strings inside NJ?

Share this post


Link to post
Share on other sites

I need to read them all in at once, and this way also takes a very long time.

I am trying to populate a ListBox with the string data.

Share this post


Link to post
Share on other sites
Quote

i.e. Array.Copy(NJ_array, NA_array, 1000)

Looking at this you clearly had to map your NJ String arrays into that NJ_array variable. You already have the updated list of those strings, so I don't understand why you need to copy them again to another string array...

Quote

also, the docs for Array.Copy state that the destination array needs to be greater in size than the source array, which seems bizarre.

All Copy/Paste process eventually will use an indexing process with some kind of "for loop" inside it. I doubt the variables are being copied all at once. The size difference might have something to do with the "for loop" implementation.

 

Quote

I am trying to populate a ListBox with the string data.

Unfortunately you cannot change the Text inside ListBox object dynamically. Same goes for ComboBox/DropDown.

There is no way to do so in NA. It's kind of suck, eventhough the IDE utilizes Visual Basic, the functionality is very limited.

Share this post


Link to post
Share on other sites
19 hours ago, innoaloe said:

Unfortunately you cannot change the Text inside ListBox object dynamically. Same goes for ComboBox/DropDown.

There is no way to do so in NA. It's kind of suck, eventhough the IDE utilizes Visual Basic, the functionality is very limited.

 

Yes you can. I am doing it by:

ListBox0.SetItems(arrayOfObjects)

 

The array has to be an array of Objects, (and not strings, integers, etc.) because that is all the Compact .NET Framework in the NA supports.

Share this post


Link to post
Share on other sites

 

What is calling the array.copy sub? Can you copy the array in the background before calling the list box?

 

Share this post


Link to post
Share on other sites
18 hours ago, Andy_P said:

 

Yes you can. I am doing it by:

ListBox0.SetItems(arrayOfObjects)

 

The array has to be an array of Objects, (and not strings, integers, etc.) because that is all the Compact .NET Framework in the NA supports.

 

Weird, because I cannot find that SetItems function anywhere in a ListBox component, even on the latest NA firmware version (1.08). Can you perhaps post a screenshot when the Intellisense shows this function?

Regarding changing type to Object instead of String, wouldn't CType function work? It is used to convert / cast types without copying it to a new variable

Share this post


Link to post
Share on other sites

Intellisense doesn't show it, but trust me, it is there and it works.

This is a bug in the NA/Sysmac Studio software in my opinion. This is not the only function that is missing either.

Omron need to improve this.

Share this post


Link to post
Share on other sites

Well... that's definitely annoying. Gonna try it this afternoon, thanks.

Share this post


Link to post
Share on other sites

I couldn't find a solution to this, so I have moved all the strings from retained memory in the NJ into retained memory in the NA.

This works, as the NA can now For..Next loop through internal memory instead of reading each one from the NJ.

However, this means I now have a bit of a disconnect between the data stored in the NJ and what is now stored in the NA. This is a bit annoying, but it is a solution of sorts for my application at present.

Share this post


Link to post
Share on other sites
4 hours ago, Andy_P said:

I couldn't find a solution to this, so I have moved all the strings from retained memory in the NJ into retained memory in the NA.

This works, as the NA can now For..Next loop through internal memory instead of reading each one from the NJ.

However, this means I now have a bit of a disconnect between the data stored in the NJ and what is now stored in the NA. This is a bit annoying, but it is a solution of sorts for my application at present.

my recipe control is usually on a popup, so when when i open page the page displayed event calls my ListBox_Update sub;

Sub ListBox_Update
    Dim List_obj As Object 
    Dim array(100) As String
    Dim x As Integer
    For x = 0 To 99
        array(x) = ListItems(x)
    Next x
    List_Obj = array
    listbox0.SetItems(List_Obj)
End Sub

Haven't tried with a larger array though.

Share this post


Link to post
Share on other sites

I know it is an old thread, I am glad I found it though.

I like Chelton's solution for dynamic text display

Does anyone have a solution to increment the values for each list item entry?

It feels quite tedious to do it for 100 items in a list. I tried populating the list with excel an past it but  it does not work.

 

 

 

Share this post


Link to post
Share on other sites
On 04/08/2017 at 9:20 AM, chelton said:

my recipe control is usually on a popup, so when when i open page the page displayed event calls my ListBox_Update sub;

Sub ListBox_Update
    Dim List_obj As Object 
    Dim array(100) As String
    Dim x As Integer
    For x = 0 To 99
        array(x) = ListItems(x)
    Next x
    List_Obj = array
    listbox0.SetItems(List_Obj)
End Sub

Haven't tried with a larger array though.

Hi, 4 years later.

Is it possible to have this multi dimensional?

The combodrop list has a text and a value column when you enter it manually, is it possible programmatically add both those this way?

Share this post


Link to post
Share on other sites
On 04/08/2017 at 8:20 AM, chelton said:

my recipe control is usually on a popup, so when when i open page the page displayed event calls my ListBox_Update sub;

Sub ListBox_Update
    Dim List_obj As Object 
    Dim array(100) As String
    Dim x As Integer
    For x = 0 To 99
        array(x) = ListItems(x)
    Next x
    List_Obj = array
    listbox0.SetItems(List_Obj)
End Sub

Haven't tried with a larger array though.

Hello

Does anybody got this running on the HMI?
Because I can run it with no issues at all in the Simulation Mode in Sysmac Studio, but when I download the project to the HMI, as soon as I call the subroutine, it throws me an exception.
"SafeArrayTypeMismatchException is thrown at CallMethod. E_SYS_999: 0x80131533"

I could isolate that what is throwing the exception is the following instruction:

List_Obj = array

because is trying to assign an array of strings to an Object.

Sub ListBox_Update()              
    Dim List_obj As Object 
    Dim array(6) As String
    Dim i As Integer
        
    For i = 1 To 5
        array(i) = UserList(i)
    Next i
    
    List_Obj = array
    UsersListBox.SetItems(List_Obj)
    
End Sub

HMI Exception.jpg

Share this post


Link to post
Share on other sites

I have a similar function based on that code.

This reads from a array in the plc

 

Sub AddFromPLC()

	Do Until bHMI_UpdateEdit = False
	Loop
	
	
	Dim sPLC(99) As Object
	'sPLC = zHMI_DesignRecipes.DesignName
	
	Dim i As Integer = 0
	Dim l As Integer = 0
	Dim iCount As Integer = 0
	
	For i = 0 To 99
		sPLC(i) = zHMI_DesignRecipes.DesignName(i) ' + " " + (i+1).ToString
	
	Next
	
	DropDown1.SetItems(sPLC)
	
End Sub
 
Sub UpdateIndexInfo() 

	
	Dim sValue As String = ""
	sValue = DropDown1.SelectedIndex

	bHMI_UpdateEdit = True
	Label2.Text = sValue
	bHMI_DesignEditIndex =sValue
	
End Sub

 

Share this post


Link to post
Share on other sites

Hello Stefan009!

I didn't know I could copy String values directly into objects! It works! I leave the code bellow:

 

Sub ListBox_Update()
    
    'Limit the Qty of Users     to a valid range
    If (QtyUsers < 0)  Then 
        QtyUsers = 0
    End If
    If (QtyUsers > 20) Then
        QtyUsers = 20
    End If 
          
    Dim List_obj(QtyUsers) As Object 
    Dim i As Integer
    
    For i = 1 To QtyUsers
        List_obj(i) = UserList(i)     'UserList from PLC
    Next i
    
    List_obj(0) = "Select User:"
    UsersListBox.SetItems(List_Obj)
    UsersListBox.fontsize = 25
    
    SELECTED_USER = 0
End Sub

 

Thank you!

And a Merry Christmas!

 

Share this post


Link to post
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