Pages: 1 [2]   Go Down
Author Topic: serial not working  (Read 1957 times)
0 Members and 1 Guest are viewing this topic.
nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 127
Posts: 8517
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i read this i even used communication example of RS command in this project
Care to share?

Are you saying that the example only showed sending a '3'? Hard to believe but possible.

As for the handshaking, I haven't dealt with that for 20-odd years and I can't remember what does what these days. You could probably get away with tying a couple of lines to active levels or together, the signals in question are CD, DTR and DSR.

But without the access to the proper protocol spec I see little point in carrying on.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

0
Offline Offline
Full Member
***
Karma: 3
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  Hi,
  I also had this problem that Arduino serial is not read by some devices because it is not "real" rs232. 
  I had to get a component that would clean up the arduino serial, like this $2.50 component on ebay:
http://www.ebay.com/itm/RS232-TTL-Converter-Module-Serial-Board-MAX232CSE-Transfer-Chip-atmega16-/181006995656?pt=LH_DefaultDomain_0&hash=item2a24db90c8
Paul
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Paul ,
do you mean by not "real" rs232 the signal voltage level ? cos i checked with the PLC manufacturer and its signal is 0-5V DC
or is it a protocol matter as Rob mentioned ?
can you tell me the devices you tried to connect with
Logged

0
Offline Offline
Full Member
***
Karma: 3
Posts: 118
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

To connect to a pc or one of our devices via db9 connector I needed this device to create true TTL serial. 

http://en.wikipedia.org/wiki/Transistor%E2%80%93transistor_logic
Logged

THAILAND
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi bgmaxy,

 I just finished my communication project between Aduino Uno R3 with FX1N-232-BD RS232 COMMUNICATION BOARD (OPTION) MITSUBISHI PLC Model: FX1S-30MR. If you still need some help, please do not hesitate to post again I will give you some useful of technical information.

Regards,
Tutor-A  smiley
Logged

Tutor-A  note@Tutor-A.com
I'm Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
Welcome all to discuss, thanks.

THAILAND
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi  Graynomad,
 If you still need some help, please post again I will give you an information.
Regards,
Tutor-A
Logged

Tutor-A  note@Tutor-A.com
I'm Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
Welcome all to discuss, thanks.

THAILAND
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

#include <SoftwareSerial.h>
#include "Timer.h"
//#include <Stdint.h>
// software serial #1: TX = digital pin 10, RX = digital pin 11
SoftwareSerial portOne(10,11);

String plcString = "";
String inputPLC = "";
boolean plcComplete =false;
boolean flag_save_plc =false;
uint8_t count_words;
String words[2] ="";
int LEDpin3 = 3;
int LEDpin4 = 4;
int LEDpin5 = 5;
int LEDpin6 = 6;
int LEDpin7 = 7;
const int PBpin2 = 2;     // the number of the pushbutton pin
int PBpin2State = 0;         // variable for reading the pushbutton status
int PBpin2StatePrev = 0;   
int AI0Pin = A0;    // select the input pin for the potentiometer
int AI0Value = 0;  // variable to store the value coming from the sensor
Timer t; // Timer
String resultBuf[6];

void setup()
{

  inputPLC.reserve(32);
  plcString.reserve(128);
  words[0].reserve(32);
  words[1].reserve(32);

  count_words =0;
  pinMode(LEDpin3, OUTPUT); // initialize the LED pin as an output:
  pinMode(LEDpin4, OUTPUT); // initialize the LED pin as an output:
  pinMode(LEDpin5, OUTPUT); // initialize the LED pin as an output:
  pinMode(LEDpin6, OUTPUT); // initialize the LED pin as an output:
  pinMode(LEDpin7, OUTPUT); // initialize the LED pin as an output:
  digitalWrite(LEDpin3, LOW);
  digitalWrite(LEDpin4, LOW);
  digitalWrite(LEDpin5, LOW);
  digitalWrite(LEDpin6, LOW);
  digitalWrite(LEDpin7, LOW);
  pinMode(PBpin2, INPUT); // initialize the pushbutton pin as an input:   
  PBpin2State = digitalRead(PBpin2);   // read the initial state
//  t.every(1000, takeReading); // Timer .... msec for reading data and sending to Serial
  t.every(1000, takeReading); // Timer .... msec for reading data and sending to Serial
  t.oscillate(LEDpin7, 1000, LOW); // Pin, time mSec, initial state
 
  Serial.begin(9600);
  portOne.begin(9600);
//  portOne.begin(19200); 
//  portOne.begin(38400);
}

void loop() {
  t.update(); // Timer
// read the value from the sensor:
  AI0Value = analogRead(AI0Pin);
  PBpin2StatePrev = digitalRead(PBpin2);   // read input value and store it in val
  if (PBpin2StatePrev != PBpin2State) {          // the button state has changed!
    if (PBpin2StatePrev != LOW) {               // check if the button is pressed
      digitalWrite(LEDpin6, HIGH);   // turn LED on
//      AI0Value = analogRead(AI0Pin); 
//      portOne.println(AI0Value);
//      portOne.println("ABCDEF"); 
        SendData();
    }
    if (PBpin2StatePrev != HIGH) {              // check if the button is not pressed
      digitalWrite(LEDpin6, LOW);    // turn LED off
    }
  }
  PBpin2State = PBpin2StatePrev;                 // save the new state in our variable

// Read data from PLC
  if (portOne.available()) {
    char inByte = (char)portOne.read();
//    portOne.write(inByte);
//    portOne.print(inByte);
    if (inByte == 0x03) {           //ETX
      flag_save_plc =false;
      plcComplete =true;
      digitalWrite(LEDpin3, LOW);
      Serial.print(">");
      Serial.println(plcString);
//      portOne.print(plcString);
//      portOne.print(inByte);
    }
      else if (inByte == 0x02) {    //STX
      flag_save_plc =true;
      inputPLC ="";
      digitalWrite(LEDpin3, HIGH);
//      portOne.print(inByte);

      }
      if (flag_save_plc == true) {  //Data body
        if (inByte != 0x02) {
          plcString += inByte;
//          portOne.print(inByte);
//          portOne.print(plcString);
         }
       }
     }   
    if (plcComplete) {
      digitalWrite(LEDpin4, HIGH);
      for(int i=0; i<plcString.length(); i++) {
      if(plcString.charAt(i) != ' ') {
        words[count_words] += plcString.charAt(i);
          if (words[0].equals("D10012345")) {
            digitalWrite(LEDpin5, HIGH); 
          } else {
            digitalWrite(LEDpin5, LOW);
          } 
        } else {
          count_words++;
        }
      } //End for
// clear variable 
      count_words = 0;
      words[0] = "";
      words[1] = "";
      plcString = "";
      plcComplete = false;
    } // End plcComplete
    else
    {
      digitalWrite(LEDpin4, LOW);
    }     
//    delay(10);
 } //End loop
 
// Timer task
void takeReading()
{
  SendData();
} //End takeReading

void SendData()
{
// read the value from the sensor:
//  AI0Value = analogRead(AI0Pin); 

String StrBuf[10];

//  String StrAI0 = String(StrDataIn);
  String StrAI0 = String(AI0Value);

//String Length & Trim
//  portOne.print("StrAI0 = ");
//  portOne.println(StrAI0);
  StrAI0.trim();
//  portOne.print("StrAI0_Length = ");
  int StrAI0_Length = StrAI0.length();
//  portOne.println(StrAI0_Length);
//  portOne.println(StrDataIn);
 
  if (StrAI0_Length == 5 ) {
    StrBuf[0] = "+";
    StrBuf[1] = String(StrAI0[0]);
    StrBuf[2] = String(StrAI0[1]); 
    StrBuf[3] = String(StrAI0[2]); 
    StrBuf[4] = String(StrAI0[3]); 
    StrBuf[5] = String(StrAI0[4]);
  } else if (StrAI0_Length == 4 ) {
    StrBuf[0] = "+";
    StrBuf[1] = "0";
    StrBuf[2] = String(StrAI0[0]); 
    StrBuf[3] = String(StrAI0[1]); 
    StrBuf[4] = String(StrAI0[2]); 
    StrBuf[5] = String(StrAI0[3]);
  } else if (StrAI0_Length == 3 ) { 
    StrBuf[0] = "+";
    StrBuf[1] = "0";
    StrBuf[2] = "0";
    StrBuf[3] = String(StrAI0[0]); 
    StrBuf[4] = String(StrAI0[1]); 
    StrBuf[5] = String(StrAI0[2]); 
  } else if (StrAI0_Length == 2 ) { 
    StrBuf[0] = "+";
    StrBuf[1] = "0";
    StrBuf[2] = "0";
    StrBuf[3] = "0";
    StrBuf[4] = String(StrAI0[0]); 
    StrBuf[5] = String(StrAI0[1]);   
  } else if (StrAI0_Length == 1 ) {
    StrBuf[0] = "+";
    StrBuf[1] = "0";
    StrBuf[2] = "0";
    StrBuf[3] = "0";
    StrBuf[4] = "0";
    StrBuf[5] = String(StrAI0[0]);
  } else {
   
  } //End if StrAI0_Length
  StrBuf[6] = "D";
  StrBuf[7] = "1";
  StrBuf[8] = "0";
  StrBuf[9] = "0";

//Tx data => PLC
  portOne.print(0x02);       //STX    - D0
  portOne.print(StrBuf[0]);  //Sign   - D1
  portOne.print(StrBuf[1]);  //x1     - D2
  portOne.print(StrBuf[2]);  //x10    - D3 
  portOne.print(StrBuf[3]);  //x100   - D4
  portOne.print(StrBuf[4]);  //x1000  - D5
  portOne.print(StrBuf[5]);  //x10000 - D6
  portOne.print(StrBuf[6]);  //D      - D7
  portOne.print(StrBuf[7]);  //1      - D8
  portOne.print(StrBuf[8]);  //0      - D9
  portOne.print(StrBuf[9]);  //0      - D10
  portOne.print(0x03);       //ETX    - D11

//Serial Mornitor on P0, P1, and on Console 
  Serial.print(0x02);
  Serial.print(StrBuf[0]);
  Serial.print(StrBuf[1]);   
  Serial.print(StrBuf[2]);   
  Serial.print(StrBuf[3]);   
  Serial.print(StrBuf[4]);   
  Serial.print(StrBuf[5]);   
  Serial.print(StrBuf[6]);   
  Serial.print(StrBuf[7]);   
  Serial.print(StrBuf[8]);   
  Serial.print(StrBuf[9]);   
  Serial.print(0x03);
  Serial.println();

} //End SendData
Logged

Tutor-A  note@Tutor-A.com
I'm Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
Welcome all to discuss, thanks.

THAILAND
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all Arduino and FX PLC concerning peoples,
 I will give more details ...
 I will explain much as I can do on this text forum.
 Please note that, This is the prototype project. I must continue to do data manipulation on both sides of PLC and Arduino.
 Once I had achieve my expectation of the project I will give clearly representation such as Photo and Graphical documents on my Website soon.

 1. The Project simplified diagram of PLC and Arduino Uno R3, and  Interface diagram as below,
    1.1 Main Equipment
       1.1.1 Mitsubishi PLC
            - FX1S-30MR (CPU with DI/DO)
            - FX1N-232-BD (RS-232 Board)
       1.1.2 Maxim IC : Max232
       1.1.3 Micro-Controller : Arduino Uno R3

 [ MITSUBISHI PLC ]               [ IC Signal Converter ]          [ Micro-Controller]
 [ FX Family PLC    ]<-------->[        Max232          ]<----->[ Aduino Uno R3  ]
                            
                                            
               DB9 connector       TTL side      V.24 side
               (RX) Pin#2 --------- Pin#7  (TX)  Pin#10 ------ Pin#10 (RX)  
               (TX) Pin#3 --------- Pin#8  (RX)  Pin#11 ------ Pin#11 (TX)
               (SG) Pin#5 --------- Pin#15 (G )  Pin#15 ------ GND
               (DTR)Pin#4--/        
               (DSR)Pin#6--\      

               (RTS)Pin#7--/
               (CTS)Pin#8--\    
        
Please read the technical manual from Main Equipment maker (OEM).

 2. The Aduino Code is as above posting.
Logged

Tutor-A  note@Tutor-A.com
I'm Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
Welcome all to discuss, thanks.

THAILAND
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

 3. The Mitsubishi GX IEC Developer Application Program (Ladder diagram) is as below,

      M8000
 |---| |---------------------------------------------------(M8161)-----|

      M8002
 |---| |------------------------------------------[ MOV H81 D8120]-----|

      M8000        
 |---| |--------------------------------------[ RS D240 K8 D0 K12 ]-----|
                          |       M8123
                          |------|^|----------------------------[ PLF M0 ]-----|
                                                 |                          
                                                 |-----------------[ RST M8123 ]-----|

      M0
 |---| |--------------------------------------------[ MOV H2 D240 ]-----|
                                             |
                                             |------------------[ MOV D1 D241 ]-----|
                                             |
                                             |------------------[ MOV D2 D242 ]-----|
                                             |
                                             |------------------[ MOV D3 D243 ]-----|
                                             |
                                             |------------------[ MOV D4 D244 ]-----|
                                             |
                                             |------------------[ MOV D5 D245 ]-----|
                                             |
                                             |------------------[ MOV D6 D246 ]-----|
                                             |
                                             |------------------[ MOV H3 D247 ]-----|
                                             |
                                             |--------------------[ SET M8122 ]-----|
 
 
|----------------------------------------------------------[ END ]-----|
 
OK, It's hard to explain in text mode 555+++
Any question, please do not hesitate to ask me.

Regards,
Tutor-A
Logged

Tutor-A  note@Tutor-A.com
I'm Electrical Engineer and Programmer for PLC, HMI Software, Controllers ...
Welcome all to discuss, thanks.

Pages: 1 [2]   Go Up
Jump to: