📄 application.c
字号:
/*******************************************************************************
Written by: Haemish Kyd
It is hereby certified that the author of this code specified above
has made reference only to information that is in the public domain
or is available to FieldServer Technologies via a duly signed
Non-Disclosure Agreement. This code is guaranteed free and clear of
any claim upon it by any Third Party.
The basis for this certification includes:
Original work performed by Eddie Hague.
Copyright (c) 1991-2003, FieldServer Technologies.
1991 Tarob Court, Milpitas, CA 95035, USA
(408) 262 2299
********************************************************************************
Versions
1.00aA 15 Oct 04 HLK Created
1.00aB 09 Nov 04 HLK Beautified and organised
*******************************************************************************/
#include <fst.h>
#include <ProtoMod.h>
#if DIAGNOSTICS == 'Y'
extern UINT16 main_data_array[MX_DATA_ARRAY];
#endif
/*============================================================================*/
#ifdef OPTION_SERVER
VOID idle_modbus( VOID )
{
static BYTE modbus_state=0;
static BYTE basic_function=0;
static MAP_DESC_TYP *temp_md;
BYTE rc_poll;
#if DIAGNOSTICS == 'Y'
{
BYTE i;
//server diagnostic code
for (i=1;i<(BYTE)9;i++)
{
main_data_array[9+i]=main_data_array[i];
}
for (i=0;i<(BYTE)4;i++)
{
main_data_array[20+i]=main_data_array[24+i];
}
//end of diagnostic code
}
#endif
switch ( modbus_state )
{
case 0:
/******************************************************************/
/* WAIT FOR A MESSAGE TO ARRIVE AND CHECK FOR COMPLETNESS */
/******************************************************************/
rc_poll = modbusPollReceiveComplete() ;
if ( rc_poll==(BYTE)(CMPLT_COMPLETE) )
{
modbus_state++;
}
else if ( rc_poll==(BYTE)(CMPLT_NO_HOPE) )
{
modbus_state=4;
}
break;
case 1:
/******************************************************************/
/* MESSAGE IS COMPLETE, CHECK ADDRESS AND PARSE */
/******************************************************************/
if ( modbusCheckAddress() )
{
basic_function=modbusParseMessage();
clr_rx();
modbus_state++;
}
else
{
clr_rx();
modbus_state=0;
}
break;
case 2:
/******************************************************************/
/* STORE OR FETCH DATA FROM SYSTEM */
/******************************************************************/
if (basic_function==(BYTE)(READ))
{
temp_md=modbusFetchData();
}
else if (basic_function==(BYTE)(WRITE))
{
temp_md=modbusStoreData();
}
modbus_state++;
break;
case 3:
/******************************************************************/
/* RESPOND TO MODBUS MESSAGE APPROPRIATELY */
/******************************************************************/
modbusRespond (temp_md) ;
modbus_state=0;
break;
case 4:
/******************************************************************/
/* IF THERE IS AN ERROR REMOVE ONE CHARACTER AND TRY AGAIN */
/******************************************************************/
modbusGiveUpCharacter();
modbus_state=0;
break;
default:
break;
}
}
#endif
/*============================================================================*/
#ifdef OPTION_CLIENT
VOID idle_modbus(VOID)
{
static MAP_DESC_TYP *temp_md;
static BYTE modbus_state=0;
static UINT32 start_time;
BYTE rc_poll,i;
#if DIAGNOSTICS == 'Y'
//client diagnostic code
for (i=1;i<(BYTE)9;i++)
{
main_data_array[i]=main_data_array[9+i];
}
for (i=0;i<(BYTE)4;i++)
{
main_data_array[24+i]=main_data_array[20+i];
}
//end of diagnostic code
#endif
switch ( modbus_state )
{
case 0:
/******************************************************************/
/* CHECK FOR THE NEXT MESSAGE TO SEND */
/******************************************************************/
temp_md=check_for_next_modbus_message ();
if ( temp_md )
{
modbus_state++;
}
break;
case 1:
/******************************************************************/
/* SEND THE POLL */
/******************************************************************/
poll_modbus( temp_md );
start_time=get_milliseconds();
modbus_state++;
break;
case 2:
/******************************************************************/
/* GET THE PACKET AND MAKE SURE IT IS COMPLETE */
/******************************************************************/
rc_poll=modbusPacketResponseComplete();
if ( rc_poll==(BYTE)CMPLT_COMPLETE )
{
modbus_state++;
break;
}
/******************************************************************/
/* IF NO RESPONSE RECEIVED TIME OUT AND SEND NEXT POLL */
/******************************************************************/
if ((get_milliseconds()-start_time)>=(UINT32)MB_POLL_TIMEOUT)
{
modbus_state=0;
}
break;
case 3:
/******************************************************************/
/* PARSE THE RESPONSE AND STORE THE DATA */
/******************************************************************/
parse_reponse_and_store_data ();
clr_rx() ;
modbus_state++;
break;
case 4:
/******************************************************************/
/* POLL DELAY */
/******************************************************************/
if ((get_milliseconds()-start_time)>=(UINT32)MB_POLL_DELAY)
{
modbus_state=0;
}
default:
break;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -