LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problems with data receive in TCP/IP

Hi,

I made a typical program to send and receive data with TCP/IP protocol using this. LabVIEW sends 33 bytes to a microcontroller and receives 30 bytes. The TCP Read and Write functions in LabVIEW use strings as data types. So I should convert byte array to string and vice versa. Everything is OK except the "zero" number.

When the micro sends bytes to LabVIEW, the TCP read converts it to their ASCII equivalents, i.e 65 to "A". Everything is OK, except the "0" number because its ASCII equivalent is NULL and TCP read can not interpret it. Actually when micro sends 30 bytes with zero value, TCP thinks that nothing has been sent from server and generates an error: <65: TCP Read Error>.

 

How can I overcome this issue? One solution is to convert 8-bit numbers to 3-digit number (0 to 255) and send each digit as a byte. 

0 Kudos
Message 1 of 14
(3,846 Views)

As far as I know, TCP Read does no such conversion, or it would be totally useless to send binary data.  Check the sending side to make sure things are being sent correctly.

 

What led you to this conclusion?

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 14
(3,826 Views)

Micro sends data in uint_8 data format but data transmission is done in string format. 

0 Kudos
Message 3 of 14
(3,819 Views)

@iman_h wrote:

Micro sends data in uint_8 data format but data transmission is done in string format. I think I should add some termination characters to the end of bytes, such as CRLF.


You know from your other topic that you should post some code.  i think something's messed up in the conversion, which should be really simple.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 4 of 14
(3,811 Views)

Actually I used the most simple code for TCP read and write. I've attached it.

Micro sends an array of uint_8. If I fill the array with something except 0, everything is ok. But putting a zero in array makes trouble in LabVIEW, as I said. 

0 Kudos
Message 5 of 14
(3,800 Views)

What makes you think the problem is on the LabVIEW side with VISA Read?

 

Perhaps the problem is on the microcontroller side and it doesn't know how to send out the null character?   My understanding is that in C, the string datatype is terminated with a null character.  So perhaps the microcontroller code is terminating your string prematurely.

0 Kudos
Message 6 of 14
(3,776 Views)

Yes. There may be some problems in ethernet functions in micro. Actually I don't know what is wrong. I asked if someone had similiar experience.

0 Kudos
Message 7 of 14
(3,774 Views)

I should recheck the micro program with MATLAB. If C string format has problems, there should be same problem. 

Thanks.

0 Kudos
Message 8 of 14
(3,771 Views)

I'd like to know the steps you took to conclude that it was an issue with some kind of ASCII translation issue.  Not because I want to tear it apart, but because it may give us an insight into what is really happening. 

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 9 of 14
(3,757 Views)

Hi,

I rechecked the program. The problem was in micro send function. C sprintf function can not interpret \n character. I should convert bytes to ASCII in micro. The bytes will increase in this way. I must send 69 bytes instead of 31 bytes.

Thanks.

0 Kudos
Message 10 of 14
(3,697 Views)