RS232 Strings

I do apologize if this is in the wrong section.
Please feel free to let me know if there is somewhere more appropriate and I will happily move it.

Okay.

I am trying to communicate over RS232 between an Ardbox(Arduino PLC) and a Panel Pilot (display).

The issue I am having is that the Panel does require everything sent to and from it to be in a string format.
As you can see in the code the Ardbox is sending via a Serial. based library.
And as it stands the prints at turning up blank both on the Panel screen and the serial monitor, apart from the "in1," (require prefix for the Panel).

I was wondering if anyone has any ideas about a better approach or has any experience with this kind of interaction.

Oh and a slight disclaimer, the code as it stands is a bit of a Frankensteins monster of chopped up attempts and borrowed code.
Please excuse it for now and i will try and get a cleaner version uploaded soon.

TimerSend.ino (1.32 KB)

The issue I am having is that the Panel does require everything sent to and from it to be in a string format.

Can you please provide a reference to the display documentation so what we can see the communication format requirements.

RS232 communications are strictly single character format. Any other requirements will be specific to the device receiving the data, which will involve a certain sequence of single characters.

Strings cause memory problems with Arduino, so use character arrays (C-strings), or simply send all the data character by character.

the Panel does require everything sent to and from it to be in a string format.

I don't know what that means. It does NOT mean that the data in your Arduino sketch has to be a "String", because that all disappears as soon as the data goes out the serial port.

I think that the cause of your problem is that your variable count isn't declared as volatile.

FYI
1)
You can not reliably print in an ISR. Under the hood, the print is also using an ISR; only when the current ISR is finished, the print can continue 'in the background' while loop() is ' running'

It should not pose an issue if you don't print too often; your comment says tthat you setup the timer overflow for 500 ms; is this correct? I'm too lazy to go through the datasheet.

In future, please post small sketches (less than 9000 bytes) in the post using code tags instead of attaching. People with cell phones can't open ino files.

Your code as it should have been posted :wink:

/* 
Example Timer1 Interrupt
Flash LED every second
*/


#define ledPin 13
#include <RS232.h>
int timer1_counter;
int count;
//String phrase = "in1,";
//char tx;
char tx = count;
String phrase = "in1,";



void setup()
{
  
  phrase = String(phrase + tx);
  count = 2;

  Serial.begin(9600);

  RS232.begin(9600);

  pinMode(ledPin, OUTPUT);

  // initialize timer1 
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;

  // Set timer1_counter to the correct value for our interrupt interval
  //timer1_counter = 64911;   // preload timer 65536-16MHz/256/100Hz
  //timer1_counter = 64286;   // preload timer 65536-16MHz/256/50Hz
  timer1_counter = 34286;   // preload timer 65536-16MHz/256/2Hz
  
  TCNT1 = timer1_counter;   // preload timer
  TCCR1B |= (1 << CS12);    // 256 prescaler 
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();             // enable all interrupts
}

ISR(TIMER1_OVF_vect)        // interrupt service routine 
{
  
  TCNT1 = timer1_counter;   // preload timer
  digitalWrite(ledPin, digitalRead(ledPin) ^ 1);
  tx = count;
  
  Serial.println(phrase);
  Serial.print("\n");
  RS232.println(phrase);
  //RS232.print(tx);
  //Serial.print(tx);
  //Serial.print("\n");
  //Serial.print(count);
  //Serial.print("\n");
  
      
}

void loop()
{
  count = count + 1;
  
}

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile:

Hello all,

Thank you so much for your responses, all very helpful.
I can only apologize for all the mistakes I had made in forum etiquette but thank you for sticking with me.

cattledog:
Can you please provide a reference to the display documentation so what we can see the communication format requirements.

There isn't a lot of documentation on this, they seem to of relied on their Youtube channel for explanations.
But here is the basic data sheet.
https://docs-emea.rs-online.com/webdocs/15ea/0900766b815eac63.pdf

jremington:
RS232 communications are strictly single character format. Any other requirements will be specific to the device receiving the data, which will involve a certain sequence of single characters.

Strings cause memory problems with Arduino, so use character arrays (C-strings), or simply send all the data character by character.

Yes you are right, I think I may have a better handle on this now and the processing is something that will have to be done on the other end. From what information I haven gotten from their technical support, all sent data must be formatted "Alias,string". I think their use of String has kind of thrown me a little.

I have managed to clean and split up sections of the code and get a bit of functionality. I think right now my issues are on the end of the panel pilot for now so I will try and contact them for more information. I will however include and update my code here in case anyone in the future attempts to get these devices to communicate in this way.
Thank you all for you help.

Basic receiving from the Panel Pilot and printing to serial

// Include Industrial Shields libraries
#include <RS232.h>

void setup() {
  // Begin serial port
	Serial.begin(9600);

  // Begin RS232 port
  RS232.begin(9600);
}

void loop() {
  // Print received byte when available
  if (RS232.available()) {
    
    ////Read RS232 port
    char rx = RS232.read();
    
    
    //Send print read value to the serial port
    Serial.print(rx);
   
  }
}

Sending characters from the the serial monitor to display on the panel pilot.
As it stands because RS232 is a single character format, if you send "Hello" then H,e and two l's will briefly flash and then o will remain on the screen. Something that needs to be fixed on the panel pilot end.

// Include Industrial Shields libraries
#include <RS232.h>

void setup() {
  // Begin serial port
	Serial.begin(115200);

  // Begin RS232 port
  RS232.begin(115200);
}


void loop() {

  
  // Wait bytes in the serial port
 if (Serial.available()) {
  
    char tx = Serial.read();
    //in1 is the alias for the panel pilot receive data
    String phrase = "in1,";
    phrase = String(phrase + tx);

    // Echo the byte to the serial port again
    Serial.write(tx);

    // And send it to the RS-232 port
    RS232.println(phrase);

  }

}

As it stands because RS232 is a single character format, if you send "Hello" then H,e and two l's will briefly flash and then o will remain on the screen. Something that needs to be fixed on the panel pilot end.

You almost certainly are not sending the proper character sequence to have the message permanently displayed. The message header will be something other than 'in1' (which suggests to me "input one character").

The only solution to this problem is to obtain the documentation for the data transmission protocol, or reverse engineer it.

Again: don't use Strings. You should be able to replace the above problematic code with

    RS232.print("in1,");
 // Echo the byte to the serial port again
    Serial.write(tx);
   RS232.println(tx);

Hi,
Have you sent an email to Lascar University, using the contact button at the bottom of this page?

Use them, they would have to have backup support for a high end product like that.

Tom.... :slight_smile:

This is a basic tutorial on the PanelPilotACE RS232 communications

You almost certainly are not sending the proper character sequence to have the message permanently displayed. The message header will be something other than 'in1' (which suggests to me "input one character").

In the video there is reference to "single raw character" and "multiple raw character" receiving modes.

At about 15 minutes into the video is Serial receive info.

At about 15 minutes into the video is Serial receive info.

That is exactly the problem with /#$/##@ instructional videos.

You have to watch the supremely, utterly idiotic thing for 15 minutes to get the one item of information you need, and could look up in 10 seconds in printed/pdf manual.

Couldn't find one on the website. So what is the matter with these people? Do they think we can't READ?

OP: if you do contact them, please recommend that they stop appealing to illiterates, and publish printed docs.

a Panel Pilot (display).

It looks like this is a "smart display." You use its IDE to define windows on the display and what sort of variable they contain, and little programs (not unlike Arduino sketches; probably more like one of the Visual Programming Languages like ArduBlocks) to tell them when/how to put data in those windows (with one of the choices "when tagged data arrives over the serial port."

So then it wants you to send data like "window1/A string of chacacters\n", which will activate the "window1" code on the display, and it can put the text "A string of characters" in the pre-defined screen area. Or convert it to a number and display on a bargraph. Or whatever.
There may be a way to set up the whole display as a single text-displaying thing; I didn't look that deeply.
Like many GUI things, they seem to have trouble documenting what's available using "merely linear" documentation. (Man, I hate trying to explain W8 or W10 to people: "move the mouse up to the upper right hand corner, at which point you should get an easy-to-understand menu. But you can't see it until after you move your mouse to the right place, so you have to know that it's there ahead of time..." Grr.)