Hi again,
For a project at school I have to control a motorcontroller via an RS232 shield on the arduino. For the RS232 I use a Seeed shield so softwareSerial. I can send the commands no problem, calculating the CRC is fine. Now, my problem is that I have two types of messages I have to send, a servo signal and a data request. Those messages return a ACK (6 bytes) and an overview of the status (rpm, current, temp... 66 bytes) of the controller respectively. I don't know how to handle the reading part. I want to do the following:
- send status request
- read status request or NACK, resend status request if needed, I need to process the data later
- send servo signal
- read ACK/NACK and resend servo signal if needed
the return messages are always in a format as follows:
feedback: '?', 65, 'S', databytes, CRC
servo ACK: '?', 5, S, Signal_L, Signal_H, CRC
NACK: '?', 3, '?', CRC
so a '?' followed by the number of bytes excluding the CRC followed by an 'S' if recieved and then the data
How do I read all these incomming messages and act accordingly?
Hmmm. Very strange. You KNOW you are sending properly how? If you can't handle the received ACK/NAK, then perhaps you don't know the device received a proper message, after all.
How have you tried to handle ACK/NAK and what is wrong?
Paul
thanks for the reply!
I know I'm sending it properly cause thats existing code from my predecessor, he needed to just send the request and get the data back. I'm writing a script now to test the servo_signal on monday.
My issue is: My predecessor just needed to send 1 message and get 1 back (he didn't bother with the ACK, I need to send 2 different messages and get 3 different messages back (ACK, Data and NACK). I want to make it as reliable as possible, hence the checking of the ACK. But I have little to no idea how to write something that does that.
Write out on paper the exact characters of each type of message you will receive. Line up the first character of each message under each other.
The first character of a NAK is obviously a NAK.
Same for the ACK.
Now, what is left? The data message.
You MUST read the entire message before you can do anything with it, then the first character tells you what to do.
That doesn't seem so hard, does it?
Paul