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
Ïà¹ØÎĵµ£º
C/C++Í·ÎļþÒ»ÀÀ ÊÕ²Ø
C/C++Í·ÎļþÒ»ÀÀ
C¡¢´«Í³ C++
#include <assert.h>¡¡¡¡¡¡¡¡//É趨²åÈëµã
#include <ctype.h>¡¡¡¡¡¡¡¡ //×Ö·û´¦Àí
#include <errno.h>¡¡¡¡¡¡¡¡ //¶¨Òå´íÎóÂë
#include <float.h>¡¡¡¡¡¡¡¡ //¸¡µãÊý´¦Àí
#include <fstream.h>¡¡¡¡¡¡ //ÎļþÊäÈ룯Êä³ö
#i ......
¸´Ï°Ò»Ï£¬ÃâµÃÍü¼Ç¡£
ÏÔʾ½ø³ÌÊôÐÔ- ps ÃüÁî
ps ÃüÁ¸ÃÃüÁîÊÇ×î»ù±¾Í¬Ê±Ò²ÊǷdz£Ç¿´óµÄ½ø³Ì²é¿´ÃüÁÓÃÓÚ±¨¸æ½ø³Ì±êʶ¡¢Óû§¡¢CPU ʱ¼äÏûºÄÒÔ¼°ÆäËûÊôÐÔ¡£ÀûÓÃËü¿ÉÒÔÈ·¶¨ÓÐÄÄЩ½ø³ÌÕýÔÚÔËÐм°ÔËÐеÄ״̬¡¢½ø³ÌÊÇ·ñ½áÊø¡¢½ø³ÌÓÐûÓн©ËÀ¡¢ÄÄЩ½ø³ÌÕ¼ÓÃÁ˹ý¶àµÄ×ÊÔ´µÈ¡£ps ÃüÁî¿ÉÒÔ¼à¿Øºǫ́½ø³ÌµÄ¹¤×÷Çé¿ö£¬Òò ......
¿ª·¢ÕßÔÚÏß Builder.com.cn ¸üÐÂʱ¼ä:2008-05-23×÷Õߣºlupaworld¡¡ À´Ô´:
±¾ÎĹؼü´Ê£º ǶÈëʽ GUI ǶÈëʽLinux ǶÈëʽ¿ª·¢ ǶÈëʽϵͳ
¡¡¡¡³Â¹¤³Ìʦһֱ×öLinuxµÄǶÈëʽ¿ª·¢£¬×÷ΪÔÚ¿ª·¢Ò»ÏߵŤ³Ìʦ£¬Ëû¶ÔºÜ¶àÎÊÌâµÄ¿´·¨¿ÉÄܸüÇкÏʵ¼ÊÐèÇó£¬ÓÚÊÇ£¬Í¨¹ýÓʼþ£¬¾ÍǶÈëʽ¿ª·¢·½ÃæµÄÎÊÌ⣬ÇëËû̸ÁËÒ»ÏÂ×Ô¼ºµÄ¿´·¨£º
¡¡¡¡Î ......
[/b][url]http://blog.chinaunix.net/u3/95713/showart_1931142.html[/url]
Linux¸ù¾Ý°æ±¾µÄ²»Í¬, ÎļþµÄ×éÖ¯½á¹¹µ±È»»áÓÐËù²î±ð,µ«Ö÷ÒªµÄÎļþ¼ÐÓ¦¸ÃÊÇÒ»ÑùµÄ,Á˽âÕâЩÎļþ¼ÐµÄº¬Òå,¶ÔÓÚÁ˽âLinuxÓÐ×ÅÖØÒªµÄÒâÒå.
1, / LinuxÎļþϵͳµÄÈë¿Ú£¬Ò²ÊÇ´¦ÓÚ×î¸ßÒ»¼¶µÄĿ¼£»
2, /bin ϵͳËùÐèÒªµÄÄÇЩÃüÁîλÓÚ´Ë ......
²é¿´µ±Ç°Ä¿Â¼ÏÂÎļþµÄ¸öÊý
ls -l | grep "^-" | wc -l
²é¿´µ±Ç°Ä¿Â¼ÏÂÎļþµÄ¸öÊý£¬°üÀ¨×ÓĿ¼ÀïµÄ¡£
ls -lR| grep "^-" | wc -l
²é¿´Ä³Ä¿Â¼ÏÂÎļþ¼Ð£¨Ä¿Â¼£©µÄ¸öÊý£¬°üÀ¨×ÓĿ¼ÀïµÄ¡£
ls -lR| grep "^d" | wc -l
¼òҪ˵Ã÷£º
ls -l
³¤ÁбíÊä³ö¸ÃĿ¼ÏÂÎļþÐÅÏ¢(×¢ÒâÕâÀïµÄÎļþ£¬²»Í¬ÓÚÒ»°ãµÄÎļþ£¬¿ÉÄÜÊÇÄ ......