How to send Hexa string to external device


#1

hi,
i have Q24ext module, i have connected meter to wavecom through UART1. i am able to receive data from the meter but i need to send hexa string to the meter (“02 41 00 00 03”) so that i will get some more data from the device. here is my part of code, it is not working. somebody tel me how to send this string.
#define QUERY_FARE “02 41 00 00 03”
#define fcmSendData1(Y,n) adl_fcmSendData(uart1FcmHandle,(u8 *)Y,(u16)n)
void Query_FARE(u8 ID)
{
wm_memset(Rx_Str ,’\0’,Rx_Str_Len);
RxCnt =0;
fcmSendData1(QUERY_FARE,30);
}
Thanks in advance
karthikeyan


#2

For a start, I would get rid of the macro - it just confuses the issue!

Don’t use a “Magic Number” for the string length; use strlen to determine the string length - then you know it’s correct!

What return value do you get from adl_fcmSendData ?

How did you test it?
What, exactly, were your results?


#3

i dont have debug port (uart1 connected to fare meter uart2 connected to u-blox) so what i am doing is whatever data received on uart1 i am sending that data through sms.whenever keypress happens in meter, it will send data to wavecom.From wavecom through sms i am able to receive those datas.By sending the hexa string (“02 41 00 00 03”) to the meter i am unable read the data(i am getting SMS with no content). i am also not sure about how to parse hexa string.

#define QUERY_FARE “02 41 00 00 03”

every 30 seconds Query_FARE() function will be called.
void Query_FARE(u8 ID)
{

wm_memset(Rx_Str ,’\0’,Rx_Str_Len);
RxCnt =0;
fcmSendData1(QUERY_FARE,wm_strlen(QUERY_FARE));
adl_tmrSubscribe ( FALSE,6*54 , ADL_TMR_TYPE_TICK , faredata);
}
void faredata(u8 ID)
{
ascii s[50];
wm_memset(s,’\0’,sizeof(s));
wm_strcpy(s,Rx_Str);
adl_smsSend(sms_automaton_Handle_id,"+919746938076",s,ADL_SMS_MODE_TEXT);
}

UART data handler

bool Uart1DataHandler(u16 dataLen, u8 * data)
{
if(RxCnt_U1+dataLen>=Rx_Str_Len)
{
RxCnt_U1=0;
wm_memset(Rx_Str_U1,0,Rx_Str_Len);
}
wm_ibuftohexa(Rx_Str_U1,data,dataLen);
RxCnt_U1 = RxCnt_U1 + dataLen;
return TRUE;
}
regards
karthikeyan


#4

Yes, you can still have a debug port! :smiley:

See: viewtopic.php?f=53&t=2509&p=11123&hilit=external+com#p11123


#5

Yes i can have debug port,but the problem is fcmsenddata function can send u8 data or may be string to external device. but i need to send hexa string(02 41 00 00 03) with fcmsenddata function. how it can be done. :question:
Thanks&Regards
karthikeyan


#6

I think the problem is that you are trying to do too many things all at once!

I think you should start with a simple project that just sends and receives the required data using FCM;
Then, once you’re familiar with how FCM works, you can start adding the additional functionality.

The first thing you need to do is to decide precisely what you mean by “send hexa string(02 41 00 00 03)”

Do you mean:

  • You want to send the character ‘0’, followed by the character ‘2’, followed by a space, etc…
  • You want to send the value 0x02, followed by the value 0x41, followed by the value 0x00, etc…
  • Or what?

Once you are clear about what exactly you want to appear on the output wires of the UART, it should be clear how to achieve that…


#7

i dont want to send characters. i need to send the value 0x02 0x41 0x00 0x00 0x03.


#8

So that’s just u8 data, isn’t it?!

And you’ve already said that fcmSendData can send u8 data…


#9

Hiya,

This builds a constant array of characters - not a constant array of u8 bytes.

Try using something like this:

const u8 QUERY_FARE[] = { 0x02, 0x41, 0x00, 0x00, 0x03 };
const s32 QUERY_FARE_LEN = sizeof(QUERY_FARE)/sizeof(QUERY_FARE[0]);

Also note that you will NOT be able to use the wm_strlen() function to determine the length of QUERY_FARE in the example above, as wm_strlen() uses 0x00 as the end of string marker to determine length. That is why there is the second line defining QUERY_FARE_LEN.

Hope this helps.

ciao, Dave


#10

Now i am able to send the hex values. i can read the fare meter data by sending the hexa values. but some data loss happening i think i need to check arrray variable which is used in the data handler.
Thanks a lot
karthikeyan