LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

mathscript node to mathscript window and array---doubt

Dear Friends,

How to import and export a variable and Arrays from Math script Node to Mathscript window ...
Is there anyway to do like this..(available in matlab)

one more doubt.....

I am reading a data from serial port one byte at time.....
I need to save data into an array and check the  array data with predefined format(we decided format and sending the format on the serial port)......
my doubt is whether the array get's initalized every time..when i enter the mathscript window again and again since mathscript node is inside the while loop.....
I am unable to compare the array data with the formats.....so i feel that whether the array contains the value or not...

how to confirm that array is having the  received data...which i saved

or else how to save 4byte of data of string types(fetched once...4 bytes at once ..by giving in bytes to read option in serial port vi)  ............... given as input to the math script node to an array which can save 4 bytes of data .............................

below is the code

persistent  bHeader
persistent  ubIndex
ubTemp=input

 if bHeader ==0
                 if ubTemp == 89
                        ubIndex= 0
                        bHeader = 1                              
                   end

else
              ubIndex= ubIndex +1
              ubReceivedata(ubIndex) = ubTemp      
               if  ubIndex == 3
                       ubIndex = 0
                       bHeader = 0               
                 end
end      

 ubChecksum = ubRecieveData(1) + ubRecieveData(2) + ubRecieveData(3)
 
if   ubChecksum == 0

               if ubRecieveData(1) == 76
                        duLen1 = ubRecieveData(2)

                             elseif   ubRecieveData(1) == 69
                                    duLen2 = ubRecieveData(2)

                             elseif   ubRecieveData(1) == 78
                                       duLen3 = ubRecieveData(2)
                              
                               elseif ubRecieveData(1) == 71
                                            duLen4 = ubRecieveData(2)
                                            duLength = duLen1 * 16777216 + duLen2 * 65536 + uwLen3 * 256 +  ubLen4 
       
                              elseif   ubRecieveData(1) == 80
                                           uwTemp1 = ubRecieveData(2);

                               elseif  ubRecieveData(1) == 66
                                            ubTemp2 = ubRecieveData(2);                 
                                            uwpackageSpeed = uwTemp1 * 256 + ubTemp2;

                                 elseif  ubRecieveData(1) == 68
                                          uwTemp1 = ubRecieveData(2);

                                 else  ubRecieveData(1) == 65
                                          ubTemp2 = ubRecieveData(2);                 
                                         uwDrumSpeed = uwTemp1 * 256 + ubTemp2;

                   end

end


kindly send ur suggestions

regards
rajasekar
0 Kudos
Message 1 of 2
(2,375 Views)

Hi Rajasekar,

Good question.  I had never done this till today, but this is at least one way to do it.  You can create your variables in the mathscript node and mathscript Window and bring them back and forth by using the load and save commands.

For example create something in Mathscript Window.  Go to File-> Save Data... and save the file to a .mlv file.  Then open the mlv in Mathscript Node by using "load '<file path>'" in the first line of the node.  Tested it and it worked for me.  You can also use the "save <file path>" to get it back to the Mathscript window.

I am not really sure what you are trying to do in the second part of your question.  How exactly are you initializing the mathscript node, and where exactly do you think the error is occuring?

Brian K.
0 Kudos
Message 2 of 2
(2,353 Views)