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
}
查看全文
相关阅读:
rtmp_specification_1.0
RTSP Spectification
FFMPEG 入门
Spring Cloud Gateway + Spring Oauth 2.0 整合(服务端与资源端分离)
深入浅出 Spring Cache 使用与整合(附源码解析)
Java集合之ArrayList源码分析
SpringBoot+Mybatis+MybatisPlus 入门整合(三)
SpringBoot+Mybatis+Generator 逆向工程使用(二)
SpringBoot+Mybatis整合入门(一)
SpringBoot+SpringData 整合入门
原文地址:https://www.cnblogs.com/ziyan22/p/1258698.html
最新文章
Git忽略特殊文件
Git创建和删除标签
Git远程推送和抓取分支
Git储藏工作现场
Git解决冲突
Git创建合并和删除分支
Git添加和克隆远程库
Git版本回退和撤销修改
Git修改和提交文件
Git删除和恢复文件
热门文章
Git创建版本库和添加文件
Git安装
python+Selenium之操作滚动条
【NPDP笔记】第七章 产品生命周期管理
【NPDP笔记】第五章 工具与度量
【NPDP笔记】第六章 市场研究
【NPDP笔记】第三章 新产品流程
【NPDP笔记】第四章 文化组织与团队
【NPDP笔记】第二章 组合管理
【NPDP笔记】第一章 新产品开发战略
Copyright © 2011-2022 走看看