andrewjfox Posted August 9, 2012 Share Posted August 9, 2012 Hi, I'm having some trouble with the various data types. Although variables, channels and vchannels work similarly (in theory) I'm finding certain subtle differences and can't get the right type for what I want. application: I'm storing arrays as they come in over a network to a variable for later processing. eg Data.AddValue({{128,1,3,5,7}}) Data.AddValue({{129,2,4,6,8}}) Data = {{129,2,4,6,8},{128,1,3,5,7}} then in processing loop the code looks for data with bit 7 set (data dirty bit) in first element, and clears this bit when data has been processed. if(TestBit(Data[0][0],7))Data[0][0] = ClearBit(Data[0][0],7)// do some processing on Dataendif[/CODE]The processing loop also uses the timestamp of each array, Data.Time[0], as part of the processingProblem:- If Data is V type, then AddValue sets the time of all previously added arrays in history to the same value, so I can't use the timestamps to process the data- If Data is channel, then trying to change an existing value (Data[0][0]) is the same as AddValue, so adds new entry with incorrect data, instead of changing the existing data at [0][0]- If data is variable then, again, trying to change a single element Data[0][0] stuffs up the entire historyI'd like to be able to add arrays to a channel/variable, and be able to go through the history and change individual elements. Is this possible using the functions AddValue etc, or do I need to manually manipulate a standard array? I only want a history of about 100 arraysRegardsAndrew Link to comment Share on other sites More sharing options...
AzeoTech Posted August 9, 2012 Share Posted August 9, 2012 You can't change data in a channel once its there. That basically goes for channels and V channels, so if you want to make edits, you are going to have to use a variable. Changing an element of a variable should not mess up the time stamps, but remember, the timestamps correspond to rows, the first dimension of the array only. Perhaps you can create a simple document to show the issue you are having with variables? Link to comment Share on other sites More sharing options...
andrewjfox Posted August 10, 2012 Author Share Posted August 10, 2012 I've written a small sequence to test variable history and see what is happening. I must admit it's not what I expected. (BTW I'm using latest version 5.87a) private MyArrayMyArray.AddValue(InsertTime({{128,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}}, SysTime(), 0))? MyArrayDelay(1)MyArray.AddValue(InsertTime({{129,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}}, SysTime(), 0))? MyArrayDelay(1)MyArray.AddValue(InsertTime({{130,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}}, SysTime(), 0))? MyArrayDelay(1)MyArray.AddValue(InsertTime({{131,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}}, SysTime(), 0))? MyArrayfor(private i = 0, i<4, i++) ? Format("[%d], %s, %d ",i,FormatTime(MyArray.Time[i]),MyArray[i][0])endfor// all good till hereMyArray[0][0] = ClearBit(MyArray[0][0],7)? MyArray? MyArray.Time// clearing the bit not only clears the whole array + history, but messes the timestamp as well[/CODE]Everything seems ok until I try writing to one of the array elements, then all of the data (inc history) gets wiped and the time stamps get messed up.Would greatly appreciate you pointing out my problem, if it's a code issue, or alternatively advise a better solution.RegardsAndrew Link to comment Share on other sites More sharing options...
AzeoTech Posted August 11, 2012 Share Posted August 11, 2012 There appears to be some issue with addValue() on variables. Fortunately there is an easy workaround: myarray[0] = insertTime({{128,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}},systime(),0) ? myarray delay(1) myarray[1] = myarray[0,numrows(myarray)] myarray[0] = insertTime({{129,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}},systime(),0) ? myarray delay(1) myarray[1] = myarray[0,numrows(myarray)] myarray[0] = insertTime({{130,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}},systime(),0) ? myarray delay(1) myarray[1] = myarray[0,numrows(myarray)] myarray[0] = insertTime({{131,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19}},systime(),0) Link to comment Share on other sites More sharing options...
andrewjfox Posted August 13, 2012 Author Share Posted August 13, 2012 Thanks, That seems to work well. Just to let you know, I've also had problems with ClearBit function messing up timestamped data // My array is timestamped as previous post MyArray[0][0] = ClearBit(MyArray[0][0],7) // doesn't work as expected // make sure return data is timestamped fixes problem (long winded but works) MyArray[0][0] = InsertTime(ClearBit(MyArray[0][0],7), MyArray.Time[0], 0) Thanks Andrew Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.