How use fprintf or fputs to send a zero hexadecimal.

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How use fprintf or fputs to send a zero hexadecimal.

ソリューションへジャンプ
865件の閲覧回数
jesusayala
Contributor I

i'm trying to send to serial port the next 

char data[] = {0x02, 0xa3, 0x08, 0x00, 0xab}; 

fprintf(serial_fd,  string); 

But only the three first bytes was send. If change the 0x00 for other value all data is sent. 

I think that the fprintf takes the 0x00 as a end of line.  How i can send the 0x00 value using fprint or fputs function?

0 件の賞賛
返信
1 解決策
634件の閲覧回数
issekiamp
Contributor I

How about using write() function instead?

See section 2.3 and 2.9.4 of I/O Drivers User's Manual for more information.

元の投稿で解決策を見る

0 件の賞賛
返信
3 返答(返信)
634件の閲覧回数
soledad
NXP Employee
NXP Employee

Hello Jesus,

In fact if you are using "string" to send the information in the fprintf, you are going to loose the data of your array since the end of string is the NULL character which it is 0x00.

You need to send the byte to byte in a single loop to send all the data from the array


Have a great day,
Sol

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 件の賞賛
返信
635件の閲覧回数
issekiamp
Contributor I

How about using write() function instead?

See section 2.3 and 2.9.4 of I/O Drivers User's Manual for more information.

0 件の賞賛
返信
634件の閲覧回数
jesusayala
Contributor I

It works!

Thanks for your help.

:smileyhappy:

0 件の賞賛
返信