Member Avatar for m.a.u.

Greetings everybody,

I have been developing a C++ Win. Forms application in VS2010 to acquire data from an external device continuously.

In the tutorial of the device the followings are given about commucating with device through RS-232.

The external device has a communication format of 38400 baud, 8 data bits, no parity, and 1 stop bit. And communication
link is controlled by the protocol request ENQ (05h) to determine if the receiver is available to acquire data. The
response is either ACK (06h) or NAK (15h).

But, in .NET SerialPort control, following handshaking methods are the options:

XOnXOff
RequestToSend
RequestToSendXOnXOff

I have searched the internet to find a tutorial explaning the relation between these handshaking methods and the communication signals, ENQ, ACK and NAK. But, unfortunately, I have not found anything useful, yet. Consequently, I would like to ask you if you could send me a link of tutorial or some source to take a look at.

Thanks in advance

It sounds to me like the device that you are trying to communicate with is using its own protocol (which nearly all hardware I have ever worked with does too). The manual about the device tells you how to implement an application with this protocol, but you have to implement it. You will not find a tutorial or built-in functionality for this. The manual (or "tutorial of the device", whatever that means) is telling you how to implement the protocol, you have to implement the protocol by basing yourself on that. I have done this countless times for various devices, it's just a matter of carefully reading the manual and implementing the protocols that it describes for the different tasks you need to get the device to do.

What it seems to be saying is that if you send the ENQ code (which they tell you is the hexadecimal number 05, which is single byte of value 0x05) through the serial port, and then listen for incoming data on the serial port, you should receive either a ACK code (a byte of value 0x06) if the device is ready to do stuff, or a NAK code (a byte of value 0x15) if the device has some sort of problem that prevents it from being "ready" to do work.

As far as implementing this, you first open the serial port, then configure the different parameters (baud-rate, parity, etc.), then send a single byte through the serial port (a byte with value 0x05) and then wait for data in the receiving buffer. When you get the data, it should be just one byte long, and it should have either value 0x06 (ACK) or 0x15 (NAK), and check that value and it will determine if the hand-shake was successful or not. If you do this, you will have implemented the "hand-shake" part of the protocol for this device, and you just need to do similar things for all the other functions or operations of the device (you send a code (with maybe some additional data), and listen for data on the receive buffer, which should all be following the protocol as described in the device's manual).

Serial ports are low-level ports, they don't have any built-in functionality like hand-shakes and stuff. You have to do everything manually yourself, that's what they call a "device driver", which what you are trying to write (in case you didn't realize it).

Member Avatar for m.a.u.

Greetings Mike,

Thank you for your reply. You are right about ack, nak, enq...

I tried to build a communication link between two PCs. Used usb2rs232 converters. Used .NET, C++ SerialPort object. Set everything exactly same as each other in two seperate PCs. When I tried to have the program run, nothing but infinite loop like response occurs.

What could be the reason? And solution :)

Thanks in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.