Hello,
I am trying to establish a communication between a sensor module and Arduino Yun via rs-232 port. I would like to send a code to the sensor as a string over serial. I am expecting to receive an "answer" from the sensor in the form of a string with unknown length.
The problem is that I don't know how to properly define the string of commands I want to send. Here is my code:
#include <SoftwareSerial.h>
SoftwareSerial Serialsensor(0,1);
String tr[512]={'Function Serial.GetSerialNumber(i : Integer) : Integer;', \the string I am sending
'Begin', \to the sensor
'AddIntParam(-1);',
'If SendCommand(i,6,4) Then',
'Result:=GetLongParam(1)',
'Else',
'Raise SENSORError.Create('Error reading serial number of SENSOR' +IntToStr(i));',
'End;',
'\0'};
String content = ""; \declaring the string I expect to receive from the sensor
char character; \a character from this string
void setup()
{
Serial.begin(38400);
Serialsensor.begin(38400);
}
void loop()
{
tr=Serialsensor.write(); \ I am sending the string ''tr'' over the serial
while(Serialsensor.available()) { \Reading the characters and adding them to the string
character = Serialsensor.read();
content.concat(character);
}
if (content != "") { \print the string if it is not empty
Serial.println(content);
}
}
There is a compilation error saying "no viable conversion from 'int' to 'String' " for the "tr" string.
The correctness of the code in the string ''tr'' does not matter, as I know for sure it is correct. The problem is to define it correctly, so that the sensor understands it. I suspect I have to convert it to ASCII or some other format.
Thank you in advance for your help.