这段时间一直在使用multidorp通信工具提供的 hostcm32.dll ,想在PC端直接调用里面的函数实现串口通信,不过对于
INITTBL 和 CINFTBL 这两个结构体的参数设置还不太清楚,按照英文说明文档试着调用了下,在执行到函数 HST_getcinffirst
时提示::-3: Empty. No more data exists.前面几个函数(HST_open,HST_sethwnd,HST_idtblclr)执行时返回值都表示正常终止,但是到这一步我就不清楚到底是哪错了,下面贴出我的部分代码,请高手指点一下:MultiAPIFunc c = new MultiAPIFunc();
MultiAPIFunc.INITTBL inittbl;
inittbl.speed = 7;
inittbl.length = 0;
inittbl.parity = 0;
inittbl.sbit = 1;
inittbl.ptout = 100;
inittbl.ctout = 1000;
inittbl.cretry = 2;
inittbl.stopkey1 = 0;
inittbl.stopkey2 = 0; string iddata = "1";
System.IntPtr inPtr = this.Handle;
int recno = 1; MultiAPIFunc.CINFTBL cinftbl;
cinftbl.htid = "1";//
cinftbl.htdmy = "1";//
cinftbl.adv = 2;//设置优先级顺序
cinftbl.fileno = 1;//设置传输文件的数量
cinftbl.filesize = 1024;
cinftbl.jobcmd = 0;
cinftbl.datatype = 1; string msg = "The Return value:\n"
+ "\n Open the line (initialization) :" + c.HST_open(0, ref inittbl).ToString()
+ "\n Setting the destination window for receiving messages :" + c.HST_sethwnd(inPtr, "1")
+ "\n Clear ID information table before polling :" + c.HST_idtblclr().ToString()
+ "\n Add to ID information table before polling :" + c.HST_idtbladd(ref iddata).ToString()
+ "\n Polling :" + c.HST_polling(ref recno, 1).ToString()
+ "\n Fetch the number of data :" + c.HST_idtblgetidno()
+ "\n Fetch data 1st time ? :" + c.HST_idtblgetid(recno, ref iddata).ToString();
MessageBox.Show(iddata);
//在匹配数据时出现错误:-3: Empty. No more data exists.
if (c.HST_idtblgetid(recno, ref iddata) == 0)
{
msg += "\n Data fetch 1 from communication processing information storage table :" + c.HST_getcinffirst(ref cinftbl).ToString();
}
else
msg += "\n Data fetch 2 from communication processing information storage table :" + c.HST_getcinfnext(ref cinftbl).ToString(); //接收文件
//string fileRece = Application.StartupPath.Replace(@"\bin\Debug", @"\rece");
//msg += "\n File reception:" + c.HST_filerecv(ref fileRece, ref cinftbl); //发送文件
string fileSend = Application.StartupPath.Replace(@"\bin\Debug", @"\send\text.txt");
cinftbl.jobcmd = 1;
msg += "\n File send:" + c.HST_filesend(ref fileSend, ref cinftbl); msg += "\n Fetch the error detail information :" + c.HST_geterrinf().ToString(); msg += "\n Interrupt processing ?\n Processing the request of break :" + c.HST_stopreq();
msg += "\n Disconnecting communication :" + c.HST_disconnect(1, ref cinftbl);
msg += "\n Line close :" + c.HST_close(); label1.Text = msg;
INITTBL 和 CINFTBL 这两个结构体的参数设置还不太清楚,按照英文说明文档试着调用了下,在执行到函数 HST_getcinffirst
时提示::-3: Empty. No more data exists.前面几个函数(HST_open,HST_sethwnd,HST_idtblclr)执行时返回值都表示正常终止,但是到这一步我就不清楚到底是哪错了,下面贴出我的部分代码,请高手指点一下:MultiAPIFunc c = new MultiAPIFunc();
MultiAPIFunc.INITTBL inittbl;
inittbl.speed = 7;
inittbl.length = 0;
inittbl.parity = 0;
inittbl.sbit = 1;
inittbl.ptout = 100;
inittbl.ctout = 1000;
inittbl.cretry = 2;
inittbl.stopkey1 = 0;
inittbl.stopkey2 = 0; string iddata = "1";
System.IntPtr inPtr = this.Handle;
int recno = 1; MultiAPIFunc.CINFTBL cinftbl;
cinftbl.htid = "1";//
cinftbl.htdmy = "1";//
cinftbl.adv = 2;//设置优先级顺序
cinftbl.fileno = 1;//设置传输文件的数量
cinftbl.filesize = 1024;
cinftbl.jobcmd = 0;
cinftbl.datatype = 1; string msg = "The Return value:\n"
+ "\n Open the line (initialization) :" + c.HST_open(0, ref inittbl).ToString()
+ "\n Setting the destination window for receiving messages :" + c.HST_sethwnd(inPtr, "1")
+ "\n Clear ID information table before polling :" + c.HST_idtblclr().ToString()
+ "\n Add to ID information table before polling :" + c.HST_idtbladd(ref iddata).ToString()
+ "\n Polling :" + c.HST_polling(ref recno, 1).ToString()
+ "\n Fetch the number of data :" + c.HST_idtblgetidno()
+ "\n Fetch data 1st time ? :" + c.HST_idtblgetid(recno, ref iddata).ToString();
MessageBox.Show(iddata);
//在匹配数据时出现错误:-3: Empty. No more data exists.
if (c.HST_idtblgetid(recno, ref iddata) == 0)
{
msg += "\n Data fetch 1 from communication processing information storage table :" + c.HST_getcinffirst(ref cinftbl).ToString();
}
else
msg += "\n Data fetch 2 from communication processing information storage table :" + c.HST_getcinfnext(ref cinftbl).ToString(); //接收文件
//string fileRece = Application.StartupPath.Replace(@"\bin\Debug", @"\rece");
//msg += "\n File reception:" + c.HST_filerecv(ref fileRece, ref cinftbl); //发送文件
string fileSend = Application.StartupPath.Replace(@"\bin\Debug", @"\send\text.txt");
cinftbl.jobcmd = 1;
msg += "\n File send:" + c.HST_filesend(ref fileSend, ref cinftbl); msg += "\n Fetch the error detail information :" + c.HST_geterrinf().ToString(); msg += "\n Interrupt processing ?\n Processing the request of break :" + c.HST_stopreq();
msg += "\n Disconnecting communication :" + c.HST_disconnect(1, ref cinftbl);
msg += "\n Line close :" + c.HST_close(); label1.Text = msg;
直接用SerialPort进行串口通信
数据格式你要和机子里面的数据格式一致,
接收完了再进行分析。
用VB做过DT900的,估计930应该差不多
楼主有可能的话,最好看看DT930里面的代码,应该是C的
现在只是看casio就头大了,后面还要整理keyence的,反正是苦不堪言.
如果楼主能看懂点VB的话,可以看看他们附带的示例代码
还有,你应该有机子中C的源码,看看是什么数据格式,有些是用文件形式,有的是用数组形式进行数据交换的
应该没有问题
现在公司要进行一个新的项目,说是这块暂时先放着了,所以我也是乐的轻松,呵呵,不好意思了,帮不了你了.
这段时间忙着搞新项目的设计,一个头两个大....
怎么引用的,请教!