CentOS5.4 LinuxÏÂModbus TCP IPÐÒéC++µÄÒ»¸öСÀý×Ó
///////////////////////////////////////////////////////////////////////////
/*
ReadCoilsº¯Êý£º
¶Á¼ÌµçÆ÷µÄ״̬ £¬ ³É¹¦·µ»Øture¡£
send Êý¾Ý³¤¶È=12
recv Êý¾Ý³¤¶È=10
unsigned short int addr ¶Á¼ÌµçÆ÷µÄÆðʼµØÖ·(¼ÌµçÆ÷±àºÅ-1) ¡£
×¢Ò⣺1~8¸ö¼ÌµçÆ÷£¬ÆðʼµØÖ·´Ó0¿ªÊ¼
unsigned short int len ¶ÁÈ¡¼ÌµçÆ÷µÄ¸öÊý£¬×î´ó8.
debug_state Èç¹ûΪ1 ´òÓ¡³öµ÷ʽÐÅÏ¢
ubool *paraDO ¶Á³öµÄ¼ÌµçÆ÷״̬
SOCKET s_bnc,fd_set fds,timeval tv ÊǸ¨ÖúµÄÍøÂç½Ó¿Ú²ÎÊý
*/
///////////////////////////////////////////////////////////////////////////
inline bool ReadCoils(unsigned short int addr, byte & coilstate, SOCKET_INT s_bnc)
{
cmd_len = 12;
byte cmd_code = 1; //ÃüÁî´úÂ룺01£¬¶Á¼ÌµçÆ÷
byte *cmd_string ;
byte *echo_string ;
cmd_string = new byte[cmd_len] ;
echo_string = new byte[cmd_len] ;
cmd_string[ 0] = 0 ; // modbus ÐÒé¹æ¶¨±êʾ
cmd_string[ 1] = 0 ;
cmd_string[ 2] = 0 ;
cmd_string[ 3] = 0 ;
cmd_string[ 4] = 0 ; // length ¸ßλ²¿·Ö ÃüÁîµÄºóÐø×Ö½ÚÊýÁ¿
cmd_string[ 5] = 6 ; // length µÍλ²¿·Ö ÃüÁîµÄºóÐø×Ö½ÚÊýÁ¿
cmd_string[ 6] = 0 ; // Unit Identifier :identification of a remote slave connected on a serial line or on other buses.
cmd_string[ 7] = cmd_code ;
cmd_string[ 8] = (unsigned char) (addr >> 8);
cmd_string[ 9] = (unsigned char) addr;
cmd_string[10] = 0; //(unsigned char) (len >> 8);
cmd_string[11] = 8; //(unsigned char) len ;
int iret;
fd_set fds;
struct timeval tv;
tv.tv_sec = SLEEP ; //³¬Ê±µÈ´ýʱ
tv.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(s_bnc, &fds);
/* wait for permission to send(µÈ´ýÊÇ·ñ¿Éдwrite)*/
iret = select(s_bnc +1, NULL, &fds, NULL, &tv); /*write*/
if (iret=0)
{
if(debug_state) printf("Timer over!n");
close(s_bnc);
return false ;
}
else if (iret<0)
{
if(debug_state) printf("select is err! n");
close(s_bnc);
return false ;
}
/*send дÈëÊý¾Ý */
iret = send(s_bnc, (char *)cmd_string, cmd_len , 0);
if
Ïà¹ØÎĵµ£º
ѧϰ¹ý¡¶Èí¼þ¹¤³Ì¡·°É.Èí¼þ¹¤³Ì¿ÉÊÇÿһ¸ö³ÌÐòÔ±"±ØÐÞ"µÄ¿Î³Ì°¡.Èç¹ûÄãûÓÐѧϰ¹ý, ½¨ÒéÄãÈ¥¿´Ò»¿´. ÔÚÕâÒ»ÕÂÀïÃæ,ÎÒÃÇÒ»ÆðÀ´´ÓÈí¼þ¹¤³ÌµÄ½Ç¶ÈѧϰÍøÂç±à³ÌµÄ˼Ïë.ÔÚÎÒÃÇд³ÌÐò֮ǰ, ÎÒÃǶ¼Ó¦¸Ã´ÓÈí¼þ¹¤³ÌµÄ½Ç¶È¹æ»®ºÃÎÒÃǵÄÈí¼þ,ÕâÑùÎÒÃÇ¿ª·¢Èí¼þµÄЧÂʲŻá¸ß. ÔÚÍøÂç³ÌÐòÀïÃæ,Ò»°ãµÄÀ´Ëµ¶¼ÊÇÐí ......
¿ª·¢ÕßÔÚÏß Builder.com.cn ¸üÐÂʱ¼ä:2008-05-23×÷Õߣºlupaworld¡¡ À´Ô´:
±¾ÎĹؼü´Ê£º ǶÈëʽ GUI ǶÈëʽLinux ǶÈëʽ¿ª·¢ ǶÈëʽϵͳ
¡¡¡¡³Â¹¤³Ìʦһֱ×öLinuxµÄǶÈëʽ¿ª·¢£¬×÷ΪÔÚ¿ª·¢Ò»ÏߵŤ³Ìʦ£¬Ëû¶ÔºÜ¶àÎÊÌâµÄ¿´·¨¿ÉÄܸüÇкÏʵ¼ÊÐèÇó£¬ÓÚÊÇ£¬Í¨¹ýÓʼþ£¬¾ÍǶÈëʽ¿ª·¢·½ÃæµÄÎÊÌ⣬ÇëËû̸ÁËÒ»ÏÂ×Ô¼ºµÄ¿´·¨£º
¡¡¡¡Î ......
WindowsϵͳÆäʵºÍLinuxϵͳÓÐÏàËƵĵط½£¬WindowsϵͳÎļþ¡¢Ä¿Â¼µÄÊôÐÔÓÐÖ»¶Á¡¢Òþ²Ø£¬¶øLinux Ò²Ò»Ñù¡£
¡¡¡¡LinuxÖУ¬Ã¿Ò»¸öÎļþ¶¼¾ßÓÐÌض¨µÄÊôÐÔ¡£Ö÷Òª°üÀ¨ÎļþÀàÐͺÍÎļþȨÏÞÁ½¸ö·½Ãæ¡£¿ÉÒÔ·ÖΪ5ÖÖ²»Í¬µÄÀàÐÍ£ºÆÕͨÎļþ¡¢Ä¿Â¼Îļþ¡¢Á´½ÓÎļþ¡¢É豸Îļþ
ºÍ¹ÜµÀÎļþ¡£ÉϺ£Êý¾Ý»Ö¸´
¡¡¡¡ËùνµÄÎļþȨÏÞ£¬ÊÇÖ¸¶ÔÎļþµÄ·ÃÎ ......
À´×Ô£ºhttp://www.linuxsir.org/main/?q=node/137#1.2
ÕªÒª£º ±¾ÎÄÊÇfind ÃüÁîµÄÏêϸ˵Ã÷£¬¿É¹óµÄÊÇÕë¶Ô²ÎÊý¾ÙÁ˺ܶàµÄʵÀý£¬´óÁ¿µÄÀýÖ¤£¬ÈóõѧÕ߸üΪÈÝÒ×Àí½â£»±¾ÎÄÊÇzhyflyÐÖÌùÔÚÂÛ̳ÖУ»ÎÒ¶Ô±¾ÎĽøÐÐÁËÔÙ´ÎÕûÀí£¬Îª·½±ã´ó¼ÒÔĶÁ£»
Ŀ¼
°æȨÉùÃ÷
Ç°ÑÔ£º¹ØÓÚfindÃüÁî
Ò»¡¢find ÃüÁî¸ñʽ
1¡¢findÃüÁîµÄÒ»°ã ......