none
detecting ack RRS feed

  • Question

  • Hi there

    I'm using CLR. I have a serial connection to send commands to a Frame Grabber Camera. After I sent a command, I receive an ACK (0x06) if the command was executed successfully and a NAK (0x15) if not.

    My question: How can I detect the ASCII sign of ACK and NAK? At the end of every sequence (System::String^) I receive, there is an ACK or a NAK. Is there a way to convert ASCII signs into its equivalent HEX numbers? Or is there an easier way to solve this problem?

    Tuesday, February 1, 2011 1:15 PM

Answers

  • Is something like this what you're looking for?

    	System::String^ ref = L"Hello\x6 World";
    	System::Char ACK = L'\x6';
    	if(ref->IndexOf(ACK) != -1) {
    		Console::WriteLine(L"ACK is there");
    	}
    

    • Proposed as answer by Pavel A Wednesday, February 2, 2011 2:56 AM
    • Marked as answer by Stiphu Wednesday, February 2, 2011 7:33 AM
    Tuesday, February 1, 2011 4:07 PM

All replies

  • Is something like this what you're looking for?

    	System::String^ ref = L"Hello\x6 World";
    	System::Char ACK = L'\x6';
    	if(ref->IndexOf(ACK) != -1) {
    		Console::WriteLine(L"ACK is there");
    	}
    

    • Proposed as answer by Pavel A Wednesday, February 2, 2011 2:56 AM
    • Marked as answer by Stiphu Wednesday, February 2, 2011 7:33 AM
    Tuesday, February 1, 2011 4:07 PM
  • Hex is not a number system that is directly supported on computers...it is actually a set of characters that represent numbers. It will actually be easier if you do not consider the serial port a character oriented device, and instead consider it to be a single byte device. Then, you just look for a byte with the value 6, or 21.Even if you are using it as a character device, the values of ACK/NACK do not change...they are still 6/21.

    ASCII differs only in string handling fuctions and in encoding, It will make no difference to your program. There is no such thing as an ASCII sign. It is the 'convenient' text oriented functions that tend to obfuscate and confuse. ASCII control characters are not generally printable, so routines that handle strings sometimes remove them. A good sanity check is to print the numeric value, and not the ASCII symbol that represents it.

    Tuesday, February 1, 2011 4:34 PM
  • I am not sure that such devices use UNICODE...usually, it is single byte...as in Ansi SBCS.

    Tuesday, February 1, 2011 5:50 PM