中国自动化学会专家咨询工作委员会指定宣传媒体
免费注册 登录 广告服务 | 客服中心
您现在所在的是:

电脑编程

抖音 德嘉 泓格论坛 FLIR红外热像论坛
工控论坛首页 电脑编程 → 浏览主题: [求助] FX-0N的编程口通讯(Linux)
发表新帖 回复该主题
回帖:1个,阅读:1784 [上一页] [1] [下一页]
* 帖子主题:

[求助] FX-0N的编程口通讯(Linux)

分享到
933
RIKUMKK
文章数:5
年度积分:50
历史总积分:933
注册时间:2004/5/12
发站内信
发表于:2004/6/8 15:30:00
#0楼
我用Linux(Red  Hat)编了下面的程序,用于FX-0N的编程口通讯(通过PLC的编程口向PLC发送STX110F6043412CDABETX49   和   STX1011301FFETXE6   两条字符串)。程序运行结果,屏幕显示正常,PLC没收到数据。
 用同一程序向另一台PC机(超级终端)发送两条与上面完全相同的字符串,超级终端接收正常。
 用VB编的程序向PLC发送两条与上面完全相同的字符串,PLC接收正常,说明连线应该没问题。
 不知何故,还望各位指点。在此先谢过。

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <string.h>
main()
{
  int bSend;
  int cSend;
  int fd;
  char strC[19];
  char strB[13];
  strC[0] = '\x02';
  strC[1] = '\x31';
  strC[2] = '\x31';
  strC[3] = '\x30';
  strC[4] = '\x46';
  strC[5] = '\x36';
  strC[6] = '\x30';
  strC[7] = '\x34';
  strC[8] = '\x33';
  strC[9] = '\x34';
  strC[10] = '\x31';
  strC[11] = '\x32';
  strC[12] = '\x43';
  strC[13] = '\x44';
  strC[14] = '\x41';
  strC[15] = '\x42';
  strC[16] = '\x03';
  strC[17] = '\x34';
  strC[18] = '\x39';
  strC[19] = '\0';

  strB[0] = '\x02';
  strB[1] = '\x31';
  strB[2] = '\x30';
  strB[3] = '\x31';
  strB[4] = '\x31';
  strB[5] = '\x33';
  strB[6] = '\x30';
  strB[7] = '\x31';
  strB[8] = '\x46';
  strB[9] = '\x46';
  strB[10] = '\x03';
  strB[11] = '\x45';
  strB[12] = '\x36';
  strB[13] = '\0';

  fd =open("/dev/ttyS0",O_RDWR|O_SYNC|O_NOCTTY);
     if (fd==-1)
        {
       perror("OPEN ERROR1");
         }

  struct termios options;
  tcgetattr(fd,&options);
  cfsetispeed(&options,B9600);
  cfsetospeed(&options,B9600);
  options.c_cflag |= (CLOCAL | CREAD);
  tcsetattr(fd, TCSAFLUSH, &options);
  options.c_cflag &=~PARENB;
  options.c_cflag &=~CSTOPB;
  options.c_cflag &=~CSIZE;
  options.c_cflag |= CS7;
  options.c_oflag |= OPOST;

  bSend = write(fd,strC,sizeof(strC));

         if(bSend == -1)
         {
        printf("Write Error!\n");
         }
         else
         {
         printf("Write OK!\n");
         }
   printf("%d\n",bSend);
   puts(strC);

close(fd);

sleep(1);

  fd =open("/dev/ttyS0",O_RDWR|O_SYNC|O_NOCTTY);
         if (-1==fd)
        {
       perror("OPEN ERROR2");
         }


   cSend = write(fd,strB,sizeof(strB));
   printf("%d\n",cSend);
   puts(strB);


close(fd);
}
933
RIKUMKK
文章数:5
年度积分:50
历史总积分:933
注册时间:2004/5/12
发站内信
发表于:2004/6/16 20:15:00
#1楼
原因找到了,还是串口初始化参数设置有误。
 小弟初学Linux,还望各位多多指点。
工控学堂推荐视频:

关于我们 | 联系我们 | 广告服务 | 本站动态 | 友情链接 | 法律声明 | 非法和不良信息举报

工控网客服热线:0755-86369299
版权所有 工控网 Copyright©2024 Gkong.com, All Rights Reserved

46.8003