LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

I am trying to send "00000000" (aka. null value) in the serial port

I am trying to send a null character in a string out to the serial port through asynchronous transmission, using CVI 7.1.  The null value is the very first character in the string.  Is there a way to have the serial driver send that value out?  Below is a section of my code. 


 Fmt(cDataPacketW, "%s<%c%c%c%c",     cWord[1], cWord[2],cWord[3],cWord[4]);               
cmd_written = ComWrt (comport_A, cDataPacketW, 4);
ProcessSystemEvents();                                    


The first character cWord[1] has a value of "0".  However, when I try sending out the string, I get 0 bytes written. 

0 Kudos
Message 1 of 10
(4,797 Views)
Could you try this modified lines?
 
cDataPacketW[0] = cWord[1];
cDataPacketW[1] = cWord[2];
cDataPacketW[2] = cWord[3];
cDataPacketW[3] = cWord[4];
cmd_written = ComWrt (comport_A, cDataPacketW, 4);

 
Or simply, supposing cWord is a character array,
cmd_written = ComWrt (comport_A, cWord + 1, 4);

 

Message Edited by Roberto Bozzolo on 02-16-2006 07:07 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 10
(4,789 Views)
If it is "char cWord[]" and cWord[0] = 0, but you want to write ASCII '0'  you have to do

Fmt(cDataPacketW, "%s<%c%c%c%c",     cWord[1]+'0', cWord[2]+'0',cWord[3]+'0',cWord[4]+'0');

because you now just write an 'empty' string (cDataPacketW[0]==0) and hence get 0 chars written.
-----------------------
/* Nothing past this point should fail if the code is working as intended */
0 Kudos
Message 3 of 10
(4,780 Views)

Well, he could simply use

Fmt (cDataPacketW, "%4c", cWord + 1);
cmd_written = ComWrt (1, cDataPacketW, 4);

But, Gary, I tried with your exact code and get 4 bytes written, so in my opinion the problem lies elsewhere.

Message Edited by Roberto Bozzolo on 02-16-2006 10:23 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 10
(4,775 Views)
Thank you all for the very quick reply.  I forgot to post a line I had in my code to the earlier message.  I used "stringsize = StringLength (cDataPacketW)", to determine the size of cDataPacketW and placing that value into the comWrt() function.  I corrected the code by placing an if statement to monitor that none of the cWord was an ascii null, and default the write size to x - 'size of string'.  Thanks again.



0 Kudos
Message 5 of 10
(4,756 Views)

Hello GaryZ21 ,

Did you solve this problem at this moment.

I also face this problem now.  I can not convert the 0x81 0x81 0x00 0x00 0x32  to correct  string. just received the first two words, because the string define the 0x00 is the end of string char.

If you solved this problem, Could you show me how to do? Thanks.

0 Kudos
Message 6 of 10
(4,570 Views)
Joseph, the most probable cause of your problem is some function detecting the nul byte as and-of-string and  stopping there. We could be able to help you if you post the part of your code in which you are preparing the string to send to the com port, including variable definitions.

Message Edited by Roberto Bozzolo on 12-21-2006 07:01 AM



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 7 of 10
(4,560 Views)
Hello, Roberto Bozzolo
 
Thanks for your reply.
 
I want to communicate with one equipment with RS232 port  and sent out  those command.
Below is some parts of my program. Pls help me to check how to do for this string.
 
"
 char Commands[10];    //define
        Commands[0]=0x81;
        Commands[1]=0x81;
        Commands[2]=0x52;
        Commands[3]=0x00;
        Commands[4]=0x00;
        Commands[5]=0x00;
        Commands[6]=0x53;
        Commands[7]=0x00;  
   
 OpenComConfig (1, "", 9600, 0, 8, 2, 512, 512);
 ComWrt (1, Commands,strlen (Commands));
 Delay(0.2);
 Read_Count = GetOutQLen (1);
 Delay(1);
 ComRd (1, Read_Buffer, 10);
 
"
0 Kudos
Message 8 of 10
(4,556 Views)

You are having problems due to the use of strlen () instructions that stops at the first nul byte it finds. To transmit all bytes in the buffer you need to pass the exact number of bytes to ComWrt function: in your case this statement should work correctly:

ComWrt  (1,  Commands, 8);



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 9 of 10
(4,550 Views)
Hello, Roberto Bozzolo
 
Thanks again.
 
Now it's working.
 
 
0 Kudos
Message 10 of 10
(4,547 Views)