This method downloads a script to a connected neoVI device into a specified location.
int _stdcall icsneoScriptLoad(void* hObject,constunsignedchar*bin,unsignedlong len_bytes,int iLocation);
Public Declare Function icsneoScriptLoad Lib “icsneo40.dll” (ByVal hObject As IntPtr, ByRef bin As Byte, ByVal Len_Bytes As UInt32, ByVal iLocation As Int32) As Int32
[in] Specifies the driver object created by OpenNeoDevice.
bin[in] An array of bytes that represent a compiled script. These bytes are contained in a header file called cmvspy.h.
This file is created by Vehicle Spy when a script is compiled. Please see Vehicle Spy documentation for details.
len_bytes
[in] Specifies the number of bytes represented by the bin parameter
iLocation
[in] Specifies the physical location to where the script will be loaded on the neoVI device. Valid values are as follows:
SCRIPT_LOCATION_FLASH_MEM = 0 (Valid only on a neoVI Fire or neoVI Red)SCRIPT_LOCATION_SDCARD = 1 (Valid only on a neoVI Fire or neoVI Red)SCRIPT_LOCATION_VCAN3_MEM = 4 (Valid only on a ValueCAN 3 device)
These values are defined in the icsnVC40.h file
Return Values
1 if the function succeeded. 0 if it failed for any reason. GetLastAPIError must be called to obtain the specific error. The errors that can be generated by this function are:
The script will be stored on the device in the specified location. If the location is SCRIPT_LOCATION_FLASH_MEM or SCRIPT_LOCATION_SDCARD the script will persist in the device in that location until cleared by ScriptClear. If the neoVI device is booted (plugged in to power) without being connected to a USB port the stored script will execute. The location SCRIPT_LOCATION_VCAN3_MEM applies only to the ValueCAN 3 device and the storage will be cleared when power is removed from the device.
Examples
int iRetVal;unsignedlong lLastErrNum;unsignedlong NumBinBytes;NumBinBytes = CM_EXE_SIZE; //from the cmvspy.h file. The length of the compiled script//ucharConfigurationArrayPM is defined in cmvspy.h.//It is a pointer to the array of compiled script bytesiRetVal =icsneoScriptLoad(hObject, ucharConfigurationArrayPM, NumBinBytes, DefaultScriptLocation);if(iRetVal ==0){printf("\nFailed to load the script into the neo device);}else{ printf("\nSuccessfully loaded the script into the neoVI");}
Int32 iResult;UInt32 iLength=0;byte[] CoreMiniData=newbyte[1];'//Helper functioniResult =GetCoreMiniData(ref CoreMiniData,ref iLength);if(iResult !=1){MessageBox.Show("Problem Loading CoreMini");return;}iResult =icsNeoDll.icsneoScriptLoad(m_hObject,refCoreMiniData[0], iLength,Convert.ToInt32(CoreMiniStoreLocation.SCRIPT_LOCATION_FLASH_MEM));if(iResult ==0){lblCMStatus.Text="CoreMini Not Loaded";}else{lblCMStatus.Text="CoreMini loaded into hardware";}//Helper function for reading the *.vs3cmbeMini fileprivateInt32GetCoreMiniData(refbyte[] DataArray,refUInt32 DataLength){string sNameOfFile;System.IO.FileStream ReadFileStream;System.IO.BinaryReader ReadBinaryData; //Open file DialogOpenFileDialog.ShowDialog(); sNameOfFile =OpenFileDialog.FileName; // Check for the file to existif(!System.IO.File.Exists(sNameOfFile)) return0; //Read data intry { ReadFileStream =newSystem.IO.FileStream(sNameOfFile,System.IO.FileMode.Open); ReadBinaryData =newSystem.IO.BinaryReader(ReadFileStream); DataLength =Convert.ToUInt32(ReadFileStream.Length); DataArray =ReadBinaryData.ReadBytes(Convert.ToInt32(DataLength));ReadFileStream.Close();return1; }catch(System.Exception ex) {return0; }}
Dim iResult As Int32
Dim iLength As UInt32
Dim CoreMiniData(1) As Byte
'//Helper function
iResult = GetCoreMiniData(CoreMiniData, iLength)
If iResult <> 1 Then MsgBox("Problem Loading CoreMini", MsgBoxStyle.OKOnly) : Exit Sub
Select Case iOpenDeviceType
Case NEODEVICE_VCAN3
iResult = icsneoScriptLoad(m_hObject, CoreMiniData(0), iLength, SCRIPT_LOCATION_VCAN3_MEM)
Case NEODEVICE_FIRE
iResult = icsneoScriptLoad(m_hObject, CoreMiniData(0), iLength, SCRIPT_LOCATION_FLASH_MEM)
Case Else
MsgBox("Hardware does not support CoreMini")
iResult = 0
End Select
If iResult = 0 Then
lblCMStatus.Text = "CoreMini Not Loaded"
Else
lblCMStatus.Text = "CoreMini loaded into hardware"
End If
'//Helper function for reading the \*.vs3cmbeMini file
Private Function GetCoreMiniData(ByRef DataArray() As Byte, ByRef DataLength As UInt32) As Int32
Dim sNameOfFile As String
Dim ReadFileStream As IO.FileStream
'//Open file Dialog
OpenFileDialog.ShowDialog()
sNameOfFile = OpenFileDialog.FileName
'// Check for the file to exist
If Not IO.File.Exists(sNameOfFile) Then Return 0
'//get the data length
DataLength = Convert.ToUInt32(FileLen(sNameOfFile))
'//Read data in
Try
ReadFileStream = New IO.FileStream(sNameOfFile, IO.FileMode.Open)
Dim ReadBinaryData As New IO.BinaryReader(ReadFileStream)
DataArray = ReadBinaryData.ReadBytes(Convert.ToInt32(DataLength))
ReadFileStream.Close()
Catch ex As Exception
ReadFileStream.Close()
Return 0
End Try
Return 1
End Function