ScriptLoad Method - intrepidcs API
C/C++ declare -
VB declare - VB.NET declare
- C# declare - Parameters - Return
Values - Remarks - C/C++ example
- VB example - VB.NET
example - C# example
This method downloads a script to a connected neoVI device into a specified location.
int
_stdcall icsneoScriptLoad(int hObject, const unsigned char *bin, unsigned long len_bytes, int iLocation);Visual Basic Declare
Public Declare
Function
icsneoScriptLoad Lib
"icsneo40.dll" (ByVal
hObject As
Long,
ByRef bin
As
Byte,
ByVal Len_Bytes
As
Long,
ByVal iLocation
As
Long)
As
Long
Visual Basic .NET Declare
Public
Declare
Function icsneoScriptLoad
Lib "icsneo40.dll" (ByVal
hObject As Int32,
ByRef bin
As
Byte,
ByVal Len_Bytes
As UInt32,
ByVal iLocation
As Int32)
As
Int32
C# Declare
[DllImport("icsneo40.dll")]
public
static
extern Int32
icsneoScriptLoad(Int32 hObject, ref
byte
bin, UInt32 len_bytes, Int32 iLocation);
Parameters
hObject
[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
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:
NEOVI_ERROR_DLL_NEOVI_NO_RESPONSE
= 75
NEOVI_ERROR_DLL_INVALID_SCRIPT_LOCATION = 213
NEOVI_ERROR_DLL_SDCARD_NOT_INSERTED = 214
NEOVI_ERROR_DLL_SDCARD_WRITE_ERROR = 216
NEOVI_ERROR_DLL_SCRIPT_ERROR_DOWNLOADING_SCRIPT = 220
NEOVI_ERROR_DLL_SDCARD_READ_ERROR = 217
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
Visual Basic Example
Dim
iResult As
Long
Dim DataLength As
Long
Dim CoreMiniData()
As Byte
Dim sNameOfFile As
String
Dim ByteDataIn As
Byte
Dim Counter As
Integer
'//Open file Dialog
CommonDialog.ShowOpen()
sNameOfFile = CommonDialog.FileName
'// Check for the file to exist
If Dir(sNameOfFile)
= ""
Then
lblCMStatus.Caption =
"Problem reading file"
Exit
Sub
End If
Open sNameOfFile For
Binary As 1
DataLength = LOF(1)
ReDim
CoreMiniData(0 To
DataLength - 1)
For
Counter = 0 To
DataLength - 1
Get
1, , ByteDataIn
CoreMiniData(Counter) = ByteDataIn
Next
Counter
Close(1)
iResult = icsneoScriptLoad(m_hObject, CoreMiniData(0), DataLength,
SCRIPT_LOCATION_FLASH_MEM)
If iResult = 0 Then
lblCMStatus.Caption =
"CoreMini Not Loaded"
Else
lblCMStatus.Caption =
"CoreMini loaded into hardware"
End
If
C/C++ Example:
iRetVal = icsneoScriptLoad(hObject, ucharConfigurationArrayPM, NumBinBytes,
DefaultScriptLocation);
C# Example:
Int32 iResult;
UInt32 iLength=0;
byte[] CoreMiniData=new
byte[1];
'//Helper
function
iResult = GetCoreMiniData(ref
CoreMiniData,ref
iLength);
if(iResult != 1)
{
MessageBox.Show("Problem Loading CoreMini");
return;
}
iResult = icsNeoDll.icsneoScriptLoad(m_hObject,ref
CoreMiniData[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 file
private
Int32 GetCoreMiniData(ref
byte[] DataArray,ref
UInt32 DataLength)
{
string sNameOfFile;
System.IO.FileStream ReadFileStream;
System.IO.BinaryReader ReadBinaryData;
//Open file Dialog
OpenFileDialog.ShowDialog();
sNameOfFile = OpenFileDialog.FileName;
// Check for the file
to exist
if(!System.IO.File.Exists(sNameOfFile))
return 0;
//Read data in
try
{
ReadFileStream =
new
System.IO.FileStream(sNameOfFile, System.IO.FileMode.Open);
ReadBinaryData =
new
System.IO.BinaryReader(ReadFileStream);
DataLength =
Convert.ToUInt32(ReadFileStream.Length);
DataArray =
ReadBinaryData.ReadBytes(Convert.ToInt32(DataLength));
ReadFileStream.Close();
return 1;
}
catch(System.Exception
ex)
{
return 0;
}
}
| intrepidcs API Documentation - (C) Copyright 2000-2012 Intrepid Control Systems, Inc. (www.intrepidcs.com) |
Last Updated : Friday, March 19, 2010