zoukankan
html css js c++ java
PDA mc1000收发类
using
System;
using
System.Text;
using
System.Collections;
using
System.Windows.Forms;
using
OpenNETCF.Desktop.Communication;
//
myRapi
namespace
KelvinHelper.MCTeminals
{
public
class
myRapi
{
private
const
string
MSG_CONNECT
=
"
请把PDA设备放入通讯底座,开启PDA设备,准备通讯!
"
;
private
const
string
MSG_SUCCESS
=
"
文件拷贝成功!\r\n源文件名:'{0}'\r\n目标文件名:'{1}'
"
;
private
const
string
MSG_FAIL
=
"
试图连接PDA设备失败。\r\n错误原因:
"
;
private
static
string
GetFileName(
string
FullName)
{
return
FullName.Substring(FullName.LastIndexOf(
"
\\
"
)
+
1
);
}
//
拷贝多个文件
//
scrs:PC机上源文件文件列表
//
dest:终端设备目标文件目录
/**/
/*
例子:
System.Collections.ArrayList files = new System.Collections.ArrayList();
files.Add(@"E:\cai\Mc1000\sqlce_data_import\bin\Debug\goods.txt");
files.Add(@"E:\cai\Mc1000\sqlce_data_import\bin\Debug\plucode.txt");
myRapi.CopyFilesToDevice(files, "\\", textBox1);
this.Cursor = Cursors.Default;
*/
public
static
bool
CopyFilesToDevice(ArrayList scrs,
string
dest,
object
sender)
{
bool
b
=
false
;
int
i
=
0
;
RAPI myRapi
=
new
RAPI();
try
{
myRapi.Connect(
false
,
1
);
if
(
!
myRapi.DevicePresent)
{
myRapi.Dispose();
if
(sender
!=
null
)
((TextBox)sender).Text
+=
MSG_CONNECT
+
"
\r\n
"
;
}
else
{
for
(i
=
0
; i
<
scrs.Count; i
++
)
{
string
destfile
=
dest
+
GetFileName((
string
)scrs[i]);
myRapi.CopyFileToDevice((
string
)scrs[i], destfile,
true
);
if
(sender
!=
null
)
((TextBox)sender).Text
+=
string
.Format(MSG_SUCCESS, (
string
)scrs[i], destfile)
+
"
\r\n
"
;
}
//
end for
myRapi.Disconnect();
myRapi.Dispose();
if
(sender
!=
null
)
((TextBox)sender).Text
+=
"
***** 拷贝文件完毕!*****
"
+
"
\r\n
"
;
MessageBox.Show(MSG_SUCCESS,
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
b
=
true
;
}
//
end if myRapi.Connect()
}
catch
(OpenNETCF.Desktop.Communication.RAPIException ex)
{
if
(sender
!=
null
)
((TextBox)sender).Text
+=
MSG_FAIL
+
ex.Message
+
"
\r\n
"
;
b
=
false
;
}
return
b;
}
//
end CopyFilesToDevice
//
覆盖拷贝到终端里
//
scr:终端机器里文件名
//
dest:PC机里文件全名
//
例子: myRapi.CopyFileToDevice("C:\\Goods.txt","\\Goods.txt");
public
static
bool
CopyFileToDevice(
string
scr,
string
dest)
{
bool
b
=
false
;
RAPI myRapi
=
new
RAPI();
try
{
myRapi.Connect(
false
,
1
);
if
(
!
myRapi.DevicePresent)
{
myRapi.Dispose();
MessageBox.Show(MSG_CONNECT,
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
myRapi.CopyFileToDevice(scr, dest,
true
);
myRapi.Disconnect();
myRapi.Dispose();
MessageBox.Show(
string
.Format(MSG_SUCCESS, scr, dest),
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
b
=
true
;
}
}
catch
(OpenNETCF.Desktop.Communication.RAPIException ex)
{
MessageBox.Show(MSG_FAIL
+
ex.Message,
"
错误
"
, MessageBoxButtons.OK, MessageBoxIcon.Error);
b
=
false
;
}
return
b;
}
//
end CopyFileToDevice
//
覆盖拷贝到桌面里
//
scr:终端机器里文件名
//
dest:PC机里文件全名
//
例子: myRapi.CoptyFileFormDevice("\\Stock.txt","C:\\Stock.txt");
public
static
bool
CopyFileFromDevice(
string
scr,
string
dest)
{
bool
b
=
false
;
RAPI myRapi
=
new
RAPI();
try
{
myRapi.Connect(
false
,
1
);
if
(
!
myRapi.DevicePresent)
{
myRapi.Dispose();
MessageBox.Show(MSG_CONNECT,
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
myRapi.CopyFileFromDevice(dest, scr,
true
);
myRapi.Disconnect();
myRapi.Dispose();
MessageBox.Show(
string
.Format(MSG_SUCCESS, scr, dest),
"
提示
"
, MessageBoxButtons.OK, MessageBoxIcon.Information);
b
=
true
;
}
}
catch
(OpenNETCF.Desktop.Communication.RAPIException ex)
{
MessageBox.Show(MSG_FAIL
+
ex.Message,
"
错误
"
, MessageBoxButtons.OK, MessageBoxIcon.Error);
b
=
false
;
}
return
b;
}
//
end CopyFileFromDevice
//
测试连接
//
成功返回:true
//
失败返回:false
public
static
bool
TestConnect()
{
bool
b
=
false
;
RAPI myRapi
=
new
RAPI();
try
{
myRapi.Connect(
false
,
1
);
if
(
!
myRapi.DevicePresent)
{
myRapi.Dispose();
//
MessageBox.Show("请用ActiveSync将您的PC机和PDA设备连接好。",
//
"提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
b
=
false
;
}
else
{
myRapi.Dispose();
b
=
true
;
}
}
catch
(OpenNETCF.Desktop.Communication.RAPIException ex)
{
MessageBox.Show(
"
试图连接PDA设备失败。\r\n错误原因:
"
+
ex.Message,
"
错误
"
, MessageBoxButtons.OK, MessageBoxIcon.Error);
b
=
false
;
}
return
b;
}
//
end TestConnect
}
//
end class myRapi
}
查看全文
相关阅读:
js拖动窗口 用层模拟可移动的小窗口
tar命令详解
linux内核编译过程的最终总结版
用C#写ASP.NET搜索蜘蛛代码程序
ID 为 333 的事件被添加到基于 Windows Server 2003 的计算机上的系统日志中的补丁下载地址
简单实用的C#分词源代码(含词库素材下载)
CSS截取固定长度字符串
javascript 常用代码技巧大收集
C# 特性(Attribute)
关于iis HTTPERR日志
原文地址:https://www.cnblogs.com/ziyan22/p/1258698.html
最新文章
windows下使用MinGW+msys编译ffmpeg
采集音频和摄像头视频并实时H264编码及AAC编码
word2010中如何去掉标题前面的小黑点
COM 自动化和连接点
ATL 复制策略和CAdapt
MFC对COM的支持
Win32 网络编程基本函数
Visual C++位图操作(1)
COM Tip(2)
COM Tip(1)
热门文章
Visual C++ 2011527
com 枚举器
Visual C++ 201166
nginx配置文件中的location中文详解
offsetTop,clientX,clientTop,clientWidth,offsetWidth 坐标,一次弄明白
批量删除一些数据的一个存储过程
javascript数组操作大全,数组方法总汇,速记
备份 Windows 7 key 激活文件 实现重装自行激活的批处理
Ubuntu Server Nginx 下配置 mono 下运行 asp.net mvc
在.NET使用JSON作为数据交换格式
Copyright © 2011-2022 走看看