用程序将数据采集器文件复制到PC电脑上

sunfor 2011-09-27 05:06:34
使用wince数据采集器产品,我想把采集器里路径为:Flash Storage\in.txt 的这个文件,直接COPY到C:\盘下,也就是说,采集器连接电脑后,运行一下这程序文件,就自动COPY采集器里的in.txt到PC上,若PC上有这个文件存在,提示是否覆盖。
请大家写一个C#或C++(VS2008版)的程序给我,最好有完整的SLN源码,因我C#及C++都不会!有源码是方便日后能改COPY的路径,多谢帮忙!
我的E_mail:sunfor@163.com
...全文
102 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunfor 2011-09-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zdbb 的回复:]
已发sln到你邮箱
[/Quote]
多谢,可以运行了!
但我没接CE设备时,他没提示,一直是个黑色的控制台窗口.

还想问下以下声明在程序有没有引用了?
// 声明要引用的API
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess,
uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
uint dwFlagsAndAttributes, IntPtr hTemplateFile);
sunfor 2011-09-28
  • 打赏
  • 举报
回复
需要用到:rapi.dll,OpenNETCF.Desktop.Communication.dll,rapi.h
可到如下地址下载:
http://download.csdn.net/detail/sunfor/3642686
只在此山中 2011-09-28
  • 打赏
  • 举报
回复
已发sln到你邮箱
sunfor 2011-09-28
  • 打赏
  • 举报
回复
网上别人的CODE,只不过我不会C#,请大家做个VS2008C#完整的SLN,并能运行就OK了.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;

namespace Project1
{

//连接CE设备
public class RAPIInit
{
public void RapiInit()
{
int ret = CeRapiInit();

if (ret != 0)
{
// 连接失败,获取失败代码
int e = CeRapiGetError();

// 抛出异常
Marshal.ThrowExceptionForHR(ret);
}

// 连接成功
// To Do
}

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
internal static extern int CeRapiGetError();

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
internal static extern int CeRapiInit();
}


public class RAPI
{
private const uint GENERIC_WRITE = 0x40000000; // 设置读写权限
private const uint GENERIC_READ = 0x80000000; //设置读权限
private const uint CREATE_ALWAYS = 2; // 创建新文件
private const short CREATE_NEWN = 1; // 创建新文件
private const short OPEN_EXISTING = 3; //打开已有的文件
private const short FILE_ATTRIBUTE_NORMAL = 0x80; // 设置文件属性
private const short INVALID_HANDLE_VALUE = -1; // 错误句柄
private String LocalFileName;
private String RemoteFileName;

IntPtr remoteFile = IntPtr.Zero;
byte[] buffer = new byte[0x1000]; // 传输缓冲区定义为4k
FileStream localFile;
SafeFileHandle localFile1;

int bytesread = 0;
int byteswritten = 0;
int filepos = 0;

public RAPI(String LocalFileName, String RemoteFileName)
{
this.LocalFileName = LocalFileName;
this.RemoteFileName = RemoteFileName;
}

//复制CE上的文件到PC机上
public void RapiFileFromCE()
{
//打开CE系统上的文件
remoteFile = CeCreateFile(RemoteFileName, GENERIC_READ, 0, 0, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);

// 检查文件是否打开成功
if ((int)remoteFile == INVALID_HANDLE_VALUE)
{
throw new Exception("Could not create remote file");
}

// 创建PC上的文件
localFile1 = CreateFile(LocalFileName, GENERIC_WRITE, 0, IntPtr.Zero, CREATE_ALWAYS, 0, IntPtr.Zero);

// 读取4K字节
do
{

if (Convert.ToBoolean(CeReadFile(remoteFile, buffer, buffer.Length,
ref bytesread, 0)))
{
// 写缓冲区数据到远程设备文件
if (!Convert.ToBoolean(WriteFile(localFile1, buffer, bytesread,
ref byteswritten, 0)))
{ // 检查是否成功,不成功关闭文件句柄,抛出异常
CeCloseHandle(remoteFile);
throw new Exception("Could not write to remote file");
}
}
} while (Convert.ToBoolean(bytesread));
}

//PC上的文件写到CE上
public void RapiFileToCE()
{
// 创建远程文件
remoteFile = CeCreateFile(RemoteFileName, GENERIC_WRITE, 0, 0, CREATE_NEWN,
FILE_ATTRIBUTE_NORMAL, 0);

// 检查文件是否创建成功
if ((int)remoteFile == INVALID_HANDLE_VALUE)
{
throw new Exception("Could not create remote file");
}

// 打开本地文件
localFile = new FileStream(LocalFileName, FileMode.Open);

// 读取4K字节
bytesread = localFile.Read(buffer, filepos, buffer.Length);
while (bytesread > 0)
{
// 移动文件指针到已读取的位置
filepos += bytesread;

// 写缓冲区数据到远程设备文件
if (!Convert.ToBoolean(CeWriteFile(remoteFile, buffer, bytesread,
ref byteswritten, 0)))
{ // 检查是否成功,不成功关闭文件句柄,抛出异常
CeCloseHandle(remoteFile);
throw new Exception("Could not write to remote file");
}
try
{
// 重新填充本地缓冲区
bytesread = localFile.Read(buffer, 0, buffer.Length);
}
catch (Exception)
{
bytesread = 0;
}
}

// 关闭本地文件
localFile.Close();

// 关闭远程文件
CeCloseHandle(remoteFile);
}


// 声明要引用的API
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess,
uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition,
uint dwFlagsAndAttributes, IntPtr hTemplateFile);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
internal static extern Boolean WriteFile(SafeFileHandle lpFileName, byte[] lpBuffer,
int nNumberOfbytesToWrite, ref int lpNumberOfbytesWritten, int lpOverlapped);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
internal static extern int CeCloseHandle(IntPtr hObject);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
internal static extern int CeCopyFile(
string lpExistingFileName,
string lpNewFileName,
Boolean bFailIfExists);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
internal static extern int CeWriteFile(IntPtr hFile, byte[] lpBuffer,
int nNumberOfbytesToWrite, ref int lpNumberOfbytesWritten, int lpOverlapped);

[DllImport("rapi.dll", CharSet = CharSet.Unicode)]
internal static extern int CeReadFile(IntPtr hFile, byte[] lpBuffer,
int nNumberOfBytesToRead, ref int lpNumberOfBytesRead, int lpOverlapped);

[DllImport("rapi.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern IntPtr CeCreateFile(
string lpFileName,
uint dwDesiredAccess,
int dwShareMode,
int lpSecurityAttributes,
int dwCreationDisposition,
int dwFlagsAndAttributes,
int hTemplateFile);
}


//测试例子代码
class Class3
{
public static void Main(String[] args)
{
String LocalFileName = @"c:\test2.txt";// @"c:\test1.txt"; // 本地计算机文件名
String RemoteFileName = @"\Program Files\CeCopyFile\test1.txt"; // 远程设备文件名
new RAPIInit().RapiInit();
//new RAPI().RapiFileToCE();
new RAPI(LocalFileName, RemoteFileName).RapiFileFromCE();
}
}

}

只在此山中 2011-09-28
  • 打赏
  • 举报
回复
用了CreateFile
数据仓库(Data Warehouse)简称DW或DWH,是数据库的一种概念上的升级,可以说是为满足新需求设计的一种新数据库,而这个数据库是需容纳更多的数据,更加庞大的数据集,从逻辑上讲数据仓库和数据库是没有什么区别的。为企业所有级别的决策制定过程,提供所有类型数据支撑的战略集合,主要是用于数据挖掘和数据分析,以建立数据沙盘为基础,为消灭消息孤岛和支持决策为目的而创建的。 数据仓库的应用 1.数据分析、数据挖掘、人工智能、机学习、风险控制、无人驾驶。 2.数据化运营、精准运营。 3.广告精准、智能投放。 随着我们从IT时代步入DT时代,数据积累量也与日俱增,同时伴随着互联网的发展,越来越多的应用场景产生,传统的数据处理、存储方式已经不能满足日益增长的需求。而互联网行业相比传统行业对新生事物的接受度更高、应用场景更复杂, 因此基于大数据构建的数据仓库先在互联网行业得到了尝试。 高性能高扩展的亿级电商全端实时数据仓库全实现(PC、移动、小程序) ,以热门的互联网电商实际业务应用场景为案例讲解,对电商数据仓库的常见实战指标以及难点实战指标进行了详尽讲解,具体指标包括:每日、月大盘收入报表、高付费用户分析报表、流量域多方位分析、营销域多方位分析、实时排行榜指标分析、用户主题分析、店铺主题时间区间分析等,数据分析涵盖全端(PC、移动、小程序)应用,与互联网企业大数据技术同步,让大家能够真正学到大数据企业级数据仓库的实战经验。本课程凝聚讲师多年一线大数据企业实际项目经验,大数据企业在职架构师亲自授课,全程实操代码,带你体验真实的大数据开发过程,代码现场调试。通过本课程的学习再加上老师的答疑,你完全可以将本案例直接应用于企业。本套课程可以满足世面上绝大多数大数据企业级的数据仓库业务场景,全部代码可以直接部署企业,支撑亿级并发数据分析。该项目代码也是具有极高的商业价值的,大家可以根据自己的业务进行修改,便可以使用。本课程包含的技术:  开发工具为:IDEA、WebStorm Flink1.9.0 Greenplum5.0.0 Hadoop2.6.0 Hbase1.0.0 Kafka2.1.0 Hive1.1.0 HDFS、MapReduce Redis、Flume Sqoop、Zookeeper MyBatis、EhCache SpringBoot2.0.2.RELEASE SpringCloud Finchley.RELEASE Binlog、Canal MySQL、MyCat Vue.js、Nodejs Highcharts课程亮点: 1.与企业对接、真实工业界产品  2.支持海量数据的分析 3.支持全端实时数据分析 4.通用数据仓库分层解决方案 5.数据库实时同步解决方案 6.主流微服务后端系统 7.电商数据仓库实战指标 8.实时加离线多方位分析 9.互联网大数据企业热门技术栈 10.分布式数据库存储解决方案 11.涵盖主流前端技术VUE+jQuery+Ajax+NodeJS 12.大数据热门技术Flink新版本13.集成SpringCloud实现统一整合方案 14.全程代码实操,提供全部代码和资料 15.提供答疑和提供企业技术方案咨询企业一线架构师讲授,代码企业直接复用,提供企业解决方案。  版权归作者所有,盗版将进行法律维权。 

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧