visual c++ - How to send integer as a string with WriteFile for serialport -


i want send integer string buffer serial port writefile. data value result sensor, data max has 2 characters.

i have tried convert itoa

for example:

 dword nbytes;  int a,b,c;  a=10; char *tempa =""; tempa = itoa(a, tempa,0); if(!writefile( hnd_serial, a, 2, &nbytes, null )){messagebox(l"write com port fail!");return;}  

this code not working.

unhandled exception @ 0x1024d496 (msvcr100d.dll) in envsconfig.exe: 0xc0000094: integer division zero. 

also have tried suggestion website: convert int string still not working to.

is there clue this?

you not using itoa properly, need allocate space string, need provide proper radix (this divide-by-zero error happening) , need use buffer, not original a value, buffer in write.

try following:

dword nbytes; int a,b,c; = 10; char tempa[64];  // randomly picked 64 characters max size itoa(a, tempa, 10); if(!writefile(hnd_serial, tempa, 2, &nbytes, null)) {     messagebox(l"write com port fail!");     return; }  

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -