I am trying to communicate with an electronic door lock over its rs232-interface. I figured out that the device works with HEX codes by sniffing the transfer from the original software with a serial monitor. Later I was able to communicate with it over Hyperterminal by entering HEX code. Now I am trying to communicate with it over the arduino board. As I am using the Serial port to see the output i am using the software serial for communication with the device. i tried first on digital ports 4/5, now the rx and tx is on 10/11.
After searching all day in the whole forum and trying out various things I need your help.
The device answers to the following HEX characters without a return/new line: 0x02 0x46 0x46 0x48 0x44 0x34 0x04
Here is my code:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
byte GetData[] = {0x02,0x46,0x46,0x48,0x44,0x34,0x04};
int i = 0;
void setup() {
Serial.begin(57600);
mySerial.begin(57600);
}
void loop()
{
char buffer[4];
if(i>30000) {
Serial.println("Sending...");
for (int i=0; i<sizeof(GetData); i++){
sprintf(buffer, "%02X ", GetData[i]);
mySerial.write(buffer);
Serial.print(buffer);
}
Serial.println("");
i=0;
}
if (mySerial.available()) {
Serial.println("data");
int inByte = mySerial.read();
Serial.write(inByte);
}
if (Serial.available()) {
int inByte = Serial.read();
mySerial.write(inByte);
}
i++;
}
I can trigger some output by using the transponder, letting the door lock print an event over rs232. But there also I couldn’t get the content right yet… (i did get some numbers, hex values… but not the code that I found when I was sniffing, so I definitely would know the correct content…)
BTW: I just connected RX, TX and GND - that’s enough right?
The device settings should also be right. (57600baud / 8 data bits / 1 stopbit / no parity) that’s how software serial is working as far as I know.
I really hope you can get my some further. Thanks a lot in advance.
Dave
have you tried to get it to work at 9600 baud?
57600 baud is pretty high for SWSer.
SW serial is good in sending but for reading it is less useful as you must be reading when the data comes in.
So I expect that the staement Serial.available() will not work as there is never a byte available....
The device specification defined the 57600 baud. So I have to keep this i guess...
When I move a transponder card to the reader the device gives out a serial message, which appears on the serial monitor, but sadly not in readable content... so i guess the answer to my HEX request should arrive also as it will be sent after i sent the last hex value... right?
I adjusted the code a bit to get the full stream when holding the transponder card to the reader of the device. Also I replaced the UNO with a MEGA to test it with the second serial pins. no change though...
Output with the request I send and the content I get when placing the transponder card to the reader to force a serial message from the device. the correct content would be:
02 36 46 43 54 33 30 33 33 46 30 45 34 37 41 33 44 04 (instead of that 6350469389102...)
Changing baud rate or other settings do not impact it. I also moved the Serial to Serial2 of the MEGA, still same problem.
I tried to send the input coming to the arduino right back to the laptop and end up getting different values as the once that were sent, the same values each time at least.... I am pretty frustrated now and leave it as it is right now... I need a beer.
When I communicate arduino <-> laptop over serial, I get constant but weird outputs…
I send the numbers 1-5 and don’t even get some following numbers… At least every ‘1’ gives me the same output, when I send it several times.
It is like the arduino is talking a different language? baud rate, control bits and length is all correct…
wow... what a great effort you guys put into my problem!! thank you very much Matt and Rob....
I'll check this out as soon as I am at home! I'll get back to you with some more examples, if needed.
I now try to send data from the Serial input from the arduino (monitor input over normal arduino usb connection) to the pc:
when i send 'A' i receive on the pc the two hex values '5f 79' constantely...
When i send like 20 'B' i receive mostly 'AF 1E', but also a few '2F 79' and '2F 1E'....
Now as I am using the MEGA i got the possibility to specify the settings... but it doesn't help. Same output.
Ok, at least I could sort out the reason for this. When I put down the baud rate to 9600 i constantely get 'AF 1E' when sending 'B' on the arduino. The high transfer rate seems to be the problem for this. But it isn't solving the problem...
NewSoftSerial was integrated in SoftwareSerial.... But this helped me. I do not understand the code yet, but I am able to receive ASCII values when sending chars... finally