LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Read non-printable ACSII from serial port with ComRd

Solved!
Go to solution

hi,

 

I'm currently facing an issue reading data from a power supply through serial port.

Instrument : IT6831 (http://www.itech.sh/Upload/File/20170427151442.pdf)

I can send command with no issue using ComWrt to send a 26 Bytes buffer.

I'm trying to catch the device answer.

The power supply return a 26 bytes frame, starting with : AA 00 12 ... Checksum on the last byte.

 

When I use a terminal software, I can see the device answer with non-printable characters :

brut text: ¬[00][12]Ç[00][00][00][00]
[00]Çð[07]PF[00][00]Ó.[00][00][01][00][00]
[00][00]8

 

But using ComRd, some bytes are skipped.

example:

 

char frame[26]={170,0,32,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0xCB};
char buffer [27];
int size;
int Portnum = 3;
size=ComWrt (PortNum, frame, 26);
size = ComRd(PortNum, buffer, 26);
for (i=0; i< 26; i++){
      printf("%02X ", (unsigned char)buffer[i]);
}

I should receive (in hex) AA 00 12 80 ...

I received (in hex) AA 80 ... + other bytes

 

I'm not able to decode the read frame since some bytes are skipped.

I understand that 0x00 and 0x12 are non printable characters from ASCII table, but I need to save all the return frame.

 

Could you please help be for this ?

 

I tried to retrieve data bytes by bytes, ComRdByte but that was worst ...

 

0 Kudos
Message 1 of 5
(2,889 Views)

Hi,

I have seen that binary communication using a USB to COM converter or a portable PC using a USB to COM converter internally can cause this problem. It seems that the driver frames the data on a 0x00 character. The data is not lost, but you have to check how many characters there is left in the input buffer and read them too.

 

You have not shown us your port setup. What is the timeout setting?

 

0 Kudos
Message 2 of 5
(2,859 Views)

 

Here is my port config:

#define INPUT_QUEUE_SIZE	   			1024
#define OUTPUT_QUEUE_SIZE	   			1024
#define DEFAULT_TIMEOUT					0.5

...

int error;
int parity = 1;
int dataBits = 8;
int stopBits = 1;
int PortNum = 1;
int baudRate = 9600; char deviceName = "COM10"; error = OpenComConfig (PortNum, deviceName, baudRate, parity, dataBits, stopBits, INPUT_QUEUE_SIZE, OUTPUT_QUEUE_SIZE); SetComTime (PortNum, DEFAULT_TIMEOUT);

I'm using a usb/rs232 converter. The function GetInQLen(PortNum) report false number in my case.

I know that the instrument return 26 bytes and if I wait around 4 seconds after sending a command, this function says : 25 bytes in queue.

using ComRd(portNum, buffer, 26), it ends after 25 bytes + timeout.

The 25 bytes are not matching with those expected. The 1st is OK, the 2nd should arrived in 4th position and the 3rd received could match with the 15th expected one ...

 

How can I check the numbre of characters left in the buffer ? (it seems empty for me)

Using a terminal software let me read the complete 26 bytes with no errors ...

 

0 Kudos
Message 3 of 5
(2,857 Views)
Solution
Accepted by topic author lolo3328conti

I see you are setting an odd parity for the transmission but the instrument manual claims no parity is to be used: configuring for a parity bit will mess up the transmission since 9 bits will be used to build up a character instead of 8. This may explain why you are not receiving the 26 expected characters.



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 5
(2,832 Views)

You're right. The issue was so big that I didn't catch that ...

Thanks a lot I'm now able to retrieve all expected bytes.

0 Kudos
Message 5 of 5
(2,822 Views)