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
Ïà¹ØÎĵµ£º
Ò». ʹÓà Network Time Protocol (NTP) ·þÎñÆ÷
1.1 ·þÎñÆ÷¿ÉÁ´½ÓÍâÍøÊ±
# crontab -e
¼ÓÈëÒ»ÐУº
*/1 * * * * ntpdate 210.72.145.44   ......
ʲôÊÇÒ첽ͨѶ£¿
¾ÍÊÇͨѶÈÎÒâÒ»·½¿ÉÒÔÈÎÒâ·¢ËÍÏûÏ¢£¬ÓÐÏûÏ¢À´µ½Ê±»áÊÕµ½ÏµÍ³Ìáʾȥ½ÓÊÕÏûÏ¢¡£
ÕâÀïÒªÓõ½selectº¯Êý¡£Ê¹Óò½ÖèÈçÏ£º
1¡¢ÉèÖÃÒ»¸ö¼¯ºÏ±äÁ¿£¬ÓÃÀ´´æ·ÅËùÓÐÒªÅжϵľä±ú£¨file descriptors£º¼´ÎÒÃǽ¨Á¢µÄÿ¸ösocket¡¢ÓÃopen´ò¿ªµÄÿ¸öÎļþµÈ£©
2¡¢°ÑÐèÒªÅжϵľä±ú¼ÓÈëµ½¼¯ºÏÀï
3¡¢ÉèÖÃÅжÏʱ¼ä
4¡¢¿ª ......
1.bootsect.s
±¾ÎĵÄÄ¿µÄ£¬ÔÚ½«linux kernelµÄboot²¿·Ý×öÒ»¸ö½éÉÜ£¬ÒòΪ±ÊÕß¾õµÃºÜÉÙÓÐÕâÑùµÄ
¡¡¡¡ÎÄÕÂÀ´½éÉÜÒ»¸ö²Ù×÷ϵͳ×î×ʼµÄÒ»²½----°Ñkernel±¾ÉíÔØ ......
²é¿´µ±Ç°Ä¿Â¼ÏÂÎļþµÄ¸öÊý
ls -l | grep "^-" | wc -l
²é¿´µ±Ç°Ä¿Â¼ÏÂÎļþµÄ¸öÊý£¬°üÀ¨×ÓĿ¼ÀïµÄ¡£
ls -lR| grep "^-" | wc -l
²é¿´Ä³Ä¿Â¼ÏÂÎļþ¼Ð£¨Ä¿Â¼£©µÄ¸öÊý£¬°üÀ¨×ÓĿ¼ÀïµÄ¡£
ls -lR| grep "^d" | wc -l
¼òҪ˵Ã÷£º
ls -l
³¤ÁбíÊä³ö¸ÃĿ¼ÏÂÎļþÐÅÏ¢(×¢ÒâÕâÀïµÄÎļþ£¬²»Í¬ÓÚÒ»°ãµÄÎļþ£¬¿ÉÄÜÊÇÄ ......