GetDeviceFileData

Definition

int ProcessBackupData(const unsigned char *revBuf, int fileLen, char *outBuf, int outSize)

Objetive

The files used for processing equipment backup files, for example, backup files in an SD card.

Parameter

revBuf The uploaded files.
FileLen The file length.
outBuf To receive the returning data.
outsize The max length of the receiving data

ReturnValue

The returning value is 0 or positive number for success operation. Otherwise, the operation is failed. For the error codes, please refer to the Appendix 5.

 

Ejemplo

C#

        
[DllImport("plcommpro.dll", EntryPoint = "GetDeviceFileData")]
public static extern int GetDeviceFileData(IntPtr h, ref byte buffer, ref int buffersize, string filename, string options);
private void GetDeviceFileData()
{
	Connect_Pull();
        int ret = 0;
        int buffersize = 4 * 1024 * 1024;
        byte[] buffer = new byte[buffersize];
        string filename = "Firmware"; //File name to save
        string filepath = "";
        if (IntPtr.Zero != h)
	{
		ret = GetDeviceFileData(h, ref buffer[0], ref buffersize, filename, "");
        if (ret >= 0)
		{
			SaveFileDialog saveFileDialog1 = new SaveFileDialog();
			saveFileDialog1.Filter = "txt files(*.txt)|*.txt|All files(*.*)|*.*";
			saveFileDialog1.FilterIndex = 2;
			saveFileDialog1.RestoreDirectory = true;
			saveFileDialog1.FileName = System.IO.Path.GetFileName(filename);
        if (saveFileDialog1.ShowDialog() == DialogResult.OK)
			{
				filepath = saveFileDialog1.FileName;
				FileStream fsFile = new FileStream(filepath, FileMode.Create);
				fsFile.Seek(0, SeekOrigin.Begin);
				fsFile.Write(buffer, 0, buffersize);
				fsFile.Close();
			}
        else
			{
				MessageBox.Show(filename + " is not exist!");
			}
			MessageBox.Show("succeed download file!");
		}
	}
        else
	{
		MessageBox.Show("Handle has disconnect!");
        return;
	}
	Disconnect_pull();
}

VB

        
<DllImport("plcommpro.dll", EntryPoint:="GetDeviceFileData")>
Public Shared Function GetDeviceFileData(h As IntPtr, ByRef buffer As Byte, ByRef buffersize As Integer, filename As String, options As String) As Integer
End Function
Private Sub GetDeviceFileData()
	Connect_Pull()
        Dim ret As Integer = 0
        Dim buffersize As Integer = 4 * 1024 * 1024
        Dim buffer As Byte() = New Byte(buffersize - 1) {}
        Dim filename As String = "Firmware"
        'File name to save
        Dim filepath As String = ""
        If IntPtr.Zero <> h Then
		ret = GetDeviceFileData(h, buffer(0), buffersize, filename, "")
        If ret >= 0 Then
        Dim saveFileDialog1 As New SaveFileDialog()
			saveFileDialog1.Filter = "txt files(*.txt)|*.txt|All files(*.*)|*.*"
			saveFileDialog1.FilterIndex = 2
			saveFileDialog1.RestoreDirectory = True
			saveFileDialog1.FileName = System.IO.Path.GetFileName(filename)
        If saveFileDialog1.ShowDialog() = DialogResult.OK Then
				filepath = saveFileDialog1.FileName
        Dim fsFile As New FileStream(filepath, FileMode.Create)
				fsFile.Seek(0, SeekOrigin.Begin)
				fsFile.Write(buffer, 0, buffersize)
				fsFile.Close()
        Else
				MessageBox.Show(filename & Convert.ToString(" is not exist!"))
        End If
			MessageBox.Show("succeed download file!")
        End If
        Else
		MessageBox.Show("Handle has disconnect!")
        Return
        End If
	Disconnect_pull()
End Sub