这段时间一直在使用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;

解决方案 »

  1.   

    楼主就不要用它的什么DLL了,
    直接用SerialPort进行串口通信
    数据格式你要和机子里面的数据格式一致,
    接收完了再进行分析。
    用VB做过DT900的,估计930应该差不多
    楼主有可能的话,最好看看DT930里面的代码,应该是C的
      

  2.   

    dt930里面的代码是C的,现在上头要用这个DLL,实现在PC端的串口通信,说是自带的通信软件(multidorp,flink)弹出界面不好看,对于这个dll的东西虽然有个英文说明文档,但我还是看的云里雾里的.
      

  3.   

    yes!楼上说的不错,就是实现PC与终端的上传和下载数据功能.
    现在只是看casio就头大了,后面还要整理keyence的,反正是苦不堪言.
      

  4.   

    没用过hostcm32.dll 这个,我用的是VB中的MSComm进行的
    如果楼主能看懂点VB的话,可以看看他们附带的示例代码
      

  5.   

    VB对我来说困难较大,我在大学主要是学C#,至今也就用vs.net工具做了些小项目,对于vb就不懂了,对于"串口通信"本身我也不太懂,在网上看了一些帖子,越看越糊涂了,只是调用其封装好的函数,照例说没这么复杂啊,搞不明白是哪里出了问题.
      

  6.   

    那你还是看看MSDN中关于SerialPort的相关介绍吧,用来与DT930通信应该很容易的,
    还有,你应该有机子中C的源码,看看是什么数据格式,有些是用文件形式,有的是用数组形式进行数据交换的
      

  7.   

    数据格式是文件格式,就是上传,下载文件,对于casio的两种通信:multidorp和flink,都是传文件,对于casio 的PC通信可惜也没什么实例,要是有例子看看就好了,关于手持机方面的资料在网上似乎很少,能找到有用的东西就更难了.哎~
      

  8.   

    楼主就照着MSDN中关于SerialPort类的一个示例代码调整一下串口及波特率,然后接收数据看看正确不正确
    应该没有问题
      

  9.   

    对于SerialPort类我在网上找例子看了下,也试着写了个简单的串口通信例子,但是我现在需要使用hostcm32.dll ,它里面的函数就那几个,可能是函数调用的顺序或者方式错了吧,我也糊涂了,不知道该怎么办了.
      

  10.   

    我也在搞这个,pb通讯没问题,Delphi里有问题,也很头痛。
      

  11.   

    老大:我也遇到这样的问题通过 CSHARP 与  DT930 进行通讯时,在执行  hst_open 报异常!能否将你的源码发给参考一下啊? 
      

  12.   

    这个的源码没什么可参考的,就是引用了一下multdorp的dll文件,我就简单调用了下里面的函数,里面具体的参数我自己也是不清楚...
    现在公司要进行一个新的项目,说是这块暂时先放着了,所以我也是乐的轻松,呵呵,不好意思了,帮不了你了.
    这段时间忙着搞新项目的设计,一个头两个大....
      

  13.   

    C#可以引用C的dll文件?
    怎么引用的,请教!