How to send?


#1

Hi!
I want to send 9 bytes to serial port. I try this code but it not work. Programm started but no bytes received in hyperterminal.
But it send SMS every 90 sec. (See CODE).
How to fix this?

#include "adl_global.h"
#include "adl_sms.h"
#include "adl_fcm.h"

u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );

u8 FEvent; 
u8 SEvent;
bool MaySend;
ascii SmsText[60];
u8 readcommand[9]={0x45,0x07,0x00,0x00,0x04,0x00,0x00,0x40,0x76}; 


void ReadEasy_TimerHandler (u8 ID)
{
s8 aa;
	if (MaySend==TRUE)
	{
		aa=adl_fcmSendData(FEvent,&readcommand[0] , 9);
		adl_smsSend(SEvent, "89995557788", SmsText,ADL_SMS_MODE_TEXT);
	}
}


void Send_TimerHandler ( u8 ID )
{
    //send SMS 
}

bool SmsHandler (ascii * SmsTel, ascii * SmsTimeLength, ascii * SmsText ) 
{return TRUE;
}

void SmsCntrHandler (u8 SEvent, u16 Nb)
{}

bool FcmCntrlHandler (adl_fcmEvent_e FEvent)
{

	switch (FEvent)
	{
		case ADL_FCM_EVENT_FLOW_OPENNED:
			adl_fcmSwitchV24State(FEvent,ADL_FCM_V24_STATE_DATA);

		break;

		case ADL_FCM_EVENT_FLOW_CLOSED:
			MaySend=FALSE; 
		break;

		case ADL_FCM_EVENT_V24_DATA_MODE:
			MaySend=TRUE;
			adl_tmrSubscribe ( TRUE, 600, ADL_TMR_TYPE_100MS, Send_TimerHandler );
			adl_tmrSubscribe ( TRUE, 900, ADL_TMR_TYPE_100MS, ReadEasy_TimerHandler );
		break;

		case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
			MaySend=TRUE; 
		break;

		case ADL_FCM_EVENT_V24_AT_MODE:
		MaySend=FALSE; 
		break;

		case ADL_FCM_EVENT_RESUME:
		break;

		case ADL_FCM_EVENT_MEM_RELEASE:
		break;

	}
return TRUE;
}



bool FcmDataHandler (u16 DataLen, u8 * Data)
{
return TRUE;
}

void adl_main ( adl_InitType_e InitType )
{
    
	adl_smsSubscribe(SmsHandler, SmsCntrHandler, ADL_SMS_MODE_TEXT);
    adl_fcmSubscribe(ADL_PORT_UART1, FcmCntrlHandler, FcmDataHandler);
}

#2

Tip: While it doesn’t solve your problem, you should never compare a bool with TRUE or FALSE.
Use if (MaySend) instead of if (MaySend==TRUE) and if (!MaySend) for the reverse.


#3

Hi tobias,

may I ask why you should not do that? Is it for style reasons? I don’t understand why you should not do it - if TRUE and FALSE are allowed values for type bool, you should also be allowed to compare against these values, shouldn’t you? Also, I think TRUE and FALSE should be the only values allowed for a boolean type - but C is not very strongly typed…

Best Regards,
Jan


#4

Hmmm…

if (MaySend==TRUE)
   {
      aa=adl_fcmSendData(FEvent,&readcommand[0] , 9);
      adl_smsSend(SEvent, "89995557788", SmsText,ADL_SMS_MODE_TEXT);
   }

Modem send SMS here and I receive it on my phone. It show us that MaySend==TRUE and this part is executed. But I see no byte in terminal or port-monitor… :cry:

I try also this:

char command[9];
wm_sprintf(command,"\x45\x7\x0\x0\x4\x0\x0\x40\x76");
adl_fcmSendData(FEvent,(u8 *)command, (u16)(wm_strlen(command)));
  • doesnt solve problem. Its from sample “Duplex data”.

#5

Reading the code again, I wonder why you are using FEvent as the fcm handle to the senddata function.

You are not assigning any variable to hold the fcm handle.

And in bool FcmCntrlHandler (adl_fcmEvent_e FEvent)
You need to think about scoping rules.

I’m not sure how the code works at all as it is written.


#6

I try this:
FEvent = adl_fcmSubscribe ( ADL_FCM_FLOW_V24_UART1, …, … );
It doesn`t work. Do you mean something like this?

According to same topic maybe it a GCC problem? I don’t understand the solution of that topic.

any ideas?


#7

But ‘C’ doesn’t have a true binary data type (bool is strictly C++).

In ‘C’, zero is considered False, and any non-zero value is considered True; thus

if( a )
{
   // a is non-zero
}
else
{
   // a is zero
}

Stylistically, if you name your “boolean” variables well, it is also, IMO, clearer to read without the explicit comparison; eg ,

if( door_is_open )

#8

I do know that, but if you look at the assignments of MaySend you should be quite certain, that the compiler does not write any other values than TRUE or FALSE into that variable. At least I would hope it does not. :wink:

Best Regards,
Jan


#9

Colleague.

Lets return to the topic. I compile code without bool MaySend - it doesn’t help.

Maybe somebody post correct code to send something via FCM? :question:


#10

Have you read the last post of tobias?

Have you fixed the global / local FEvent problem??

Best Regards,
Jan


#11

I think, yes.

Now I use V24handle instead FEvent, its doesn’t matter. And this - FcmCntrlHandler (u8 event). Now global - ‘V24handle’, local - ‘event’.
I assign [b]V24handle=adl_fcmSubscribe/b;

It doesn’t help.

#include "adl_global.h"
#include "adl_fcm.h"

u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );

u8 readcommand[]={0x45,0x07,0x00,0x00,0x04,0x00,0x00,0x40,0x76}; 
s8 V24handle;
bool MaySend;

//***************************************************************************
void ReadEasy_TimerHandler (u8 ID)
{
	adl_fcmSendData(V24handle,&readcommand[0], 9);
}
//***************************************************************************
bool FcmCntrlHandler (u8 event)
{

	switch (event)
	{
		case ADL_FCM_EVENT_FLOW_OPENNED:
			adl_fcmSwitchV24State(V24handle,ADL_FCM_V24_STATE_DATA);

		break;

		case ADL_FCM_EVENT_FLOW_CLOSED:
			 
		break;

		case ADL_FCM_EVENT_V24_DATA_MODE:
			
			adl_tmrSubscribe ( TRUE, 10, ADL_TMR_TYPE_100MS, ReadEasy_TimerHandler );
		break;

		case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
			 
		break;

		case ADL_FCM_EVENT_V24_AT_MODE:
			 
		break;

		case ADL_FCM_EVENT_RESUME:
		break;

		case ADL_FCM_EVENT_MEM_RELEASE:
		break;

	}
return TRUE;
}
//***************************************************************************
bool FcmDataHandler (u16 DataLen, u8 * Data)
{
return TRUE;
}
//***************************************************************************
void adl_main ( adl_InitType_e InitType )
{
	V24handle=adl_fcmSubscribe(ADL_PORT_UART1, FcmCntrlHandler, FcmDataHandler);
}

#12

You should add debug traces (are you sure the timer is called?) and check the result code of adl_fcmSendData.

Are you running the application in target mode or with the RTE?

Best Regards,
Jan


#13

I run it in target mode.

Are debug traces available while FCM subscribed on UART? I am not sure.

I sure that timer is called. I add SMS sending in timer with the result code of adl_fcmSendData in smstext. I recieved “-3”. It mean general error code “unknown handler/ handle error”.
But what sould I do with handler in adl_fcmSendData? I have no idea.


#14

hmmmm… you are right… I don’t think the debug traces will work in fcm data mode… does your module have 2 UARTs?

Is this code the whole program, or are there other parts that maybe write to the variable readcommand[] ?


#15

It is whole code without any changes.

Fastrak 1306 (655_09gg.Q2406B). It have one UART on 15 pin D-SUB.


#16

Yes, they are.

You need to connect the Fastrack to the Target Monitoring tool, then use the ‘External Com’ in the Terminal Emulator to pass your comms through to another COM: port on the PC

See: wavecom.com/modules/movie/sc … ternal+com


#17

I prefer simple method (without traces) to watch the result of fcmSend.

void ReadEasy_TimerHandler (u8 ID)
{s8 result;
char smstext[80];
result=adl_fcmSendData(V24handle,"TEST", 4);
wm_sprintf(smstext, "result of adl_fcmSendData = %d", result);
adl_smsSend(sms_hand, "+77777777",smstext,ADL_SMS_MODE_TEXT);
}

I recieved “result of adl_fcmSendData = 0”. So, it means “OK” (No error response). But I recieved no byte in terminal.


#18

Hmmm… I don’t know about “simple”

And it certainly isn’t cheap! :open_mouth:

SMS message delivery is not guaranteed, and can be subject to delays - so, if you don’t get the message, what do you know?


#19

Well, I get traces. But in RTE mode, not in Target-mode.

#include "adl_global.h"
#include "adl_fcm.h"
#include "adl_sms.h"
#include "adl_traces.h"

u32 wm_apmCustomStack [ 256 ];
const u16 wm_apmCustomStackSize = sizeof ( wm_apmCustomStack );

s8 V24handle;

//***************************************************************************
void ReadEasy_TimerHandler (u8 ID)
{s8 result;
	result=adl_fcmSendData(V24handle,"TEST", 4);
        TRACE (( 1, "Result  %d", result));
        TRACE (( 1, "V24handle  %d", V24handle));
}
//***************************************************************************
bool FcmCntrlHandler (u8 event)
{	
	TRACE (( 1, "FcmCntrlHandler" ));

	switch (event)
	{
		case ADL_FCM_EVENT_FLOW_OPENNED:
			adl_fcmSwitchV24State(V24handle,ADL_FCM_V24_STATE_DATA);
			TRACE (( 1, "ADL_FCM_EVENT_FLOW_OPENNED" ));
		break;

		case ADL_FCM_EVENT_FLOW_CLOSED:
		TRACE (( 1, "FLOW_CLOSED" ));
		break;

		case ADL_FCM_EVENT_V24_DATA_MODE:
		TRACE (( 1, "V24_DATA_MODE" ));
			adl_tmrSubscribe ( TRUE, 10, ADL_TMR_TYPE_100MS, ReadEasy_TimerHandler );
			
		break;

		case ADL_FCM_EVENT_V24_DATA_MODE_EXT:
			 
		break;

		case ADL_FCM_EVENT_V24_AT_MODE:
		TRACE (( 1, "V24_AT_MODE" ));
		break;

		case ADL_FCM_EVENT_RESUME:
		break;

		case ADL_FCM_EVENT_MEM_RELEASE:
		break;

	}
return TRUE;
}
//***************************************************************************
bool FcmDataHandler (u16 DataLen, u8 * Data)
{
return TRUE;
}
//***************************************************************************
void adl_main ( adl_InitType_e InitType )
{
	TRACE (( 1, "Main" ));
	V24handle=adl_fcmSubscribe(ADL_PORT_UART1, FcmCntrlHandler, FcmDataHandler);
	
}

Traces:

.........
Trace		1	Main
Trace		25	Is Available 01 : 1
Trace		25	FCM subs 1 : 0
Trace		26	SMS subs : 0
Trace		21	Rel Mem 01D418CA
Trace		21	Get Mem 01D4199E
Trace		21	Rel Mem 01D4199E
Trace		1	FcmCntrlHandler
Trace		25	Switch V24 0 1 : 0
Trace		1	ADL_FCM_EVENT_FLOW_OPENNED
Trace		1	FcmCntrlHandler
Trace		1	V24_DATA_MODE
Trace		20	[ADL] tmr subs ; id 1 ; hdlr 10001000 ; val 10 ; cycl 1
Trace		25	FCM Snd Data 0 4 : 0
Trace		1	Result  0
Trace		1	V24handle  0
Trace		1	FcmCntrlHandler
......etc

"Data, from serial link manager displayed, from external COM displayed:

TESTTESTTEST.....etc

So, in RTE-mode it works fine. In Target mode - no bytes arrive to terminal.


#20

Any ideas?