NicolaAbcd

MrPLC Member
  • Content count

    16
  • Joined

  • Last visited

Community Reputation

0 Neutral

About NicolaAbcd

  • Rank
    Sparky

Profile Information

  • Country Italy

Recent Profile Visitors

1079 profile views
  1. FINS/TCP using Java

    Ok, I can not way to try the driver.... next week I tell you if it works in the factory... :) Thanks a lot.
  2. FINS/TCP using Java

    Ok good. Next week i can try in a factory. Therefore I have to send first this packet: byte[] pacchetto = new byte[20]; int errore = 0; pacchetto[0] = 70; //header -> FINSpacchetto[1] = 73;pacchetto[2] = 78;pacchetto[3] = 83;pacchetto[4] = 0; //length = 12 bytespacchetto[5] = 0;pacchetto[6] = 0;pacchetto[7] = 12;pacchetto[8] = 0; //command = 0pacchetto[9] = 0;pacchetto[10] = 0;pacchetto[11] = 0;pacchetto[12] = 0; //error code = 0pacchetto[13] = 0;pacchetto[14] = 0;pacchetto[15] = 0;pacchetto[16] = 0; //client node address automatically obtained when it is set to 0pacchetto[17] = 0;pacchetto[18] = 0;pacchetto[19] = 0; Get response of PLC that return me the client node address. after this I can send this command: byte[] pacchetto = new byte[34]; pacchetto[0] = 70; //header -> FINSpacchetto[1] = 73;pacchetto[2] = 78;pacchetto[3] = 83;pacchetto[4] = 0; //length after commandpacchetto[5] = 0;pacchetto[6] = 0;pacchetto[7] = 22;pacchetto[8] = 0; //command = 2pacchetto[9] = 0;pacchetto[10] = 0;pacchetto[11] = 2;pacchetto[12] = 0; //error code = 0pacchetto[13] = 0;pacchetto[14] = 0;pacchetto[15] = 0;//fins framepacchetto[16] = -128; //icf pacchetto[17] = 0; //rsvpacchetto[18] = 2; //gctpacchetto[19] = 0; //dnapacchetto[20] = 0; //da1pacchetto[21] = 0; //da2 pacchetto[22] = 0; //snapacchetto[23] = clientNode; //sa1pacchetto[24] = 0; //sa2pacchetto[25] = 100; //sidpacchetto[26] = 1; //mrcpacchetto[27] = 1; //srcpacchetto[28] = -126; //tipo di memoria 82 -> DMpacchetto[29] = 0; //word iniziopacchetto[30] = -116; pacchetto[31] = 0; //bit iniziopacchetto[32] = 0;pacchetto[33] = 32; //quante word And then read the response that it will contain the value of word. Right? I have done a simple class that I have attached. Can you try and tell me if thre is any error? Thanks a lot Sparky the best user in a lot forum. import java.net.*;import java.io.*;public class JavaFins { //variabili connessione Socket client = null; String ip = ""; int port = 0; //varibili per leggere e scrivere OutputStream out_data = null; PrintStream printStream = null; InputStream inputStream; byte[] buffer = null; byte clientNode = 0, serverNode = 0; JavaFins() { System.out.println("Start program... \n"); ip = "localhost"; port = 9600; } private void Connetti() { try { client = new Socket(ip, port); out_data = client.getOutputStream(); inputStream = client.getInputStream(); System.out.println("Connected to " + client.getInetAddress() + " on port: " + client.getPort() + "\n" ); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void Leggi() { byte[] pacchetto = new byte[20]; int errore = 0; pacchetto[0] = 70; //header -> FINS pacchetto[1] = 73; pacchetto[2] = 78; pacchetto[3] = 83; pacchetto[4] = 0; //length = 12 bytes pacchetto[5] = 0; pacchetto[6] = 0; pacchetto[7] = 12; pacchetto[8] = 0; //command = 0 pacchetto[9] = 0; pacchetto[10] = 0; pacchetto[11] = 0; pacchetto[12] = 0; //error code = 0 pacchetto[13] = 0; pacchetto[14] = 0; pacchetto[15] = 0; pacchetto[16] = 0; //client node address automatically obtained when it is set to 0 pacchetto[17] = 0; pacchetto[18] = 0; pacchetto[19] = 0; try { printStream = new PrintStream(client.getOutputStream(), true); //apro stream di scrittura printStream.write(pacchetto); //mando pacchetto al PLC System.out.println("Attendo risposta..."); while(true) { //aggiungere thread.slepp per non interrompere il pacchetto ? if(inputStream.available()>0 && inputStream!=null ) { inputStream.read(buffer = new byte[inputStream.available()]); break; } } if( buffer.length > 0) //se l'array di byte ricevuto è maggiore di zero { errore = buffer[15]; if( errore == 0 ) //byte di eventuali errori { clientNode = buffer[20]; //byte clientNode serverNode = buffer[23]; //byte serverNode StampoPacchetto(buffer); //stampo pacchetto } else { if(errore == 1) { System.out.println("The header is not FINS..."); } else { if( errore == 2 ) { System.out.println("The data length is too long..."); } else { if( errore == 3) { System.out.println("Command is not supported...."); } else { if( errore == 20) { System.out.println("Alla connections are in use..."); } else { if( errore == 21) { System.out.println("The specific node is already connected..."); } else { if(errore == 22) { System.out.println("Attempt to access a protected node from an unspecific ip address..."); } else { if( errore == 23) { System.out.println("Fins node address is out of range..."); } else { if(errore == 24) { System.out.println("Fins node address is being used by the client and server...."); } else { if(errore == 25) { System.out.println("All node addresses avaiable for allocation have been used..."); } } } } } } } } } } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void LeggiWord() { byte[] pacchetto = new byte[34]; pacchetto[0] = 70; //header -> FINS pacchetto[1] = 73; pacchetto[2] = 78; pacchetto[3] = 83; pacchetto[4] = 0; //length after command pacchetto[5] = 0; pacchetto[6] = 0; pacchetto[7] = 22; pacchetto[8] = 0; //command = 2 pacchetto[9] = 0; pacchetto[10] = 0; pacchetto[11] = 2; pacchetto[12] = 0; //error code = 0 pacchetto[13] = 0; pacchetto[14] = 0; pacchetto[15] = 0; //fins frame pacchetto[16] = -128; //icf pacchetto[17] = 0; //rsv pacchetto[18] = 2; //gct pacchetto[19] = 0; //dna pacchetto[20] = 0; //da1 pacchetto[21] = 0; //da2 pacchetto[22] = 0; //sna pacchetto[23] = clientNode; //sa1 pacchetto[24] = 0; //sa2 pacchetto[25] = 100; //sid pacchetto[26] = 1; //mrc pacchetto[27] = 1; //src pacchetto[28] = -126; //tipo di memoria 82 -> DM pacchetto[29] = 0; //word inizio pacchetto[30] = -116; pacchetto[31] = 0; //bit inizio pacchetto[32] = 0; pacchetto[33] = 32; //quante word //invio pacchetto che legge 150 word dal plc try { printStream = new PrintStream(client.getOutputStream(), true); //apro stream di scrittura printStream.write(pacchetto); //mando pacchetto al PLC System.out.println("Attendo risposta..."); while(true) { //aggiungere thread.slepp per non interrompere il pacchetto ? if(inputStream.available()>0 && inputStream!=null ) { inputStream.read(buffer = new byte[inputStream.available()]); break; } } if( buffer.length > 0) //se l'array di byte ricevuto è maggiore di zero { if( buffer[15] == 0 ) //byte di eventuali errori { //buffer[28] - buffer[29] ricevo MRES e SRES //buffer[30] -> inizio dei dati StampoPacchetto(buffer); //stampo pacchetto } else System.out.println("Errore pacchetto..."); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //FUNZIONE CHE MI STAMPA I BYTE DI UN PACCHETTO (ARRAY DI BYTE) public void StampoPacchetto(byte[] pacchettoDaServer) { for(byte b: pacchettoDaServer) { // print character System.out.print(b + " "); } System.out.println(" \n"); } public static void main(String args[]) { JavaFins prova = new JavaFins(); prova.Connetti(); //connetto al plc prova.Leggi(); //leggo client node address -> PAG 177 fotocopia prova.LeggiWord(); // leggo word allarmi System.out.println("Fine..."); } }Save the file like JavaFins.java after in your terminal you have to do: cd path where file is saved javac JavaFins.java java JavaFins Thanks...
  3. FINS/TCP using Java

    Mmmm...I have to change the packet that i send? I think that i have to send: header - length - cmd - errCode- node 70 73 78 83 0 0 0 12 0 0 0 2 0 0 0 0 0 0 0 80 Response PLC: header - length - cmd - errCode- node - server node 70 73 78 83 0 0 0 12 0 0 0 2 0 0 0 0 0 0 0 80 0 0 0 0 Now i can send the complete command like this: node 70 73 78 83 0 0 0 26 0 0 0 2 0 0 0 0 -128 0 2 0 0 0 0 -13 0 100 1 1 -126 0 -116 0 0 32 -> read word from word 140 to 172. Right ?
  4. FINS/TCP using Java

    I have done a test in a factory. This is the packet that I send to PLC: 70 73 78 83 0 0 0 26 0 0 0 2 0 0 0 0 -128 0 2 0 0 0 0 -13 0 100 1 1 -126 0 -116 0 0 32 -> read word from word 140 to 172. This is the response of PLC: 70, 73, 78, 83, 0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 2, -128, 0, 2, 0, 0, 0, 0, 80 Can someone help me please? Thanks.
  5. send FINS command using Java UDP/IP

    I have done a test in a factory. This is the packet that I send to PLC: 70 73 78 83 0 0 0 26 0 0 0 2 0 0 0 0 -128 0 2 0 0 0 0 -13 0 100 1 1 -126 0 -116 0 0 32 -> read word from word 140 to 172. This is the response of PLC: 70, 73, 78, 83, 0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 2, -128, 0, 2, 0, 0, 0, 0, 80 Can someone help me please? Thanks.
  6. FINS - Connection Problen

    I have done a test in a factory. This is the packet that I send to PLC: 70 73 78 83 0 0 0 26 0 0 0 2 0 0 0 0 -128 0 2 0 0 0 0 -13 0 100 1 1 -126 0 -116 0 0 32 -> read word from word 140 to 172. This is the response of PLC: 70, 73, 78, 83, 0, 0, 0, 16, 0, 0, 0, 1, 0, 0, 0, 2, -128, 0, 2, 0, 0, 0, 0, 80 Can someone help me please? Thanks.
  7. FINS - Connection Problen

    I don't know if it's ok... I hope that you can tell me if it is ok or not... tomorrow or Friday I have to do a test in a factory...
  8. FINS - Connection Problen

    This is a useful pdf https://www.kepware.com/products/kepserverex/drivers/omron-fins-ethernet/documents/omron-fins-ethernet-manual/
  9. FINS - Connection Problen

    I have two class Main (connect and send command) and Listener (receive response of plc) ... Main.java: package com.prova;import java.io.*;import java.net.*;public class Main { static final String HOST = "192.168.1.7"; static final int PORT = 9600; static Socket socket = null; static Listener listenerThread = null; static OutputStream out_stream; static DataOutput out_data; //FUNZIONE CHE MI CONNETTE INVIANDO IL PRIMO PACCHETTO private static void Connect() { byte[] fins_tcp_header = new byte[20]; fins_tcp_header[0] = (byte) 'F'; // Header fins_tcp_header[1] = (byte) 'I'; fins_tcp_header[2] = (byte) 'N'; fins_tcp_header[3] = (byte) 'S'; fins_tcp_header[4] = (byte) 0x00; // Length fins_tcp_header[5] = (byte) 0x00; fins_tcp_header[6] = (byte) 0x00; fins_tcp_header[7] = (byte) 0x0C; fins_tcp_header[8] = (byte) 0x00; // Command fins_tcp_header[9] = (byte) 0x00; fins_tcp_header[10] = (byte) 0x00; fins_tcp_header[11] = (byte) 0x00; fins_tcp_header[12] = (byte) 0x00; // Error Code fins_tcp_header[13] = (byte) 0x00; fins_tcp_header[14] = (byte) 0x00; fins_tcp_header[15] = (byte) 0x00; fins_tcp_header[16] = (byte) 0x00; // Client Node Add fins_tcp_header[17] = (byte) 0x00; fins_tcp_header[18] = (byte) 0x00; fins_tcp_header[19] = (byte) 0x00; // Client fins node addresses are automatically obtained when set to 0 //printSendData(fins_tcp_header); StampoPacchetto(fins_tcp_header); try{ out_data.write(fins_tcp_header); } catch( Exception e ) { e.printStackTrace(); } } //COMANDO DI LETTURA WORD ALLARMI private static void SendReadFinsCommand() { byte[] fins_tcp_header = new byte[16]; byte[] fins_header = new byte[10]; byte[] fins_cmnd = new byte[8]; fins_tcp_header[0] = (byte) 'F'; // Header fins_tcp_header[1] = (byte) 'I'; fins_tcp_header[2] = (byte) 'N'; fins_tcp_header[3] = (byte) 'S'; fins_tcp_header[4] = (byte) 0x00; // Length fins_tcp_header[5] = (byte) 0x00; fins_tcp_header[6] = (byte) 0x00; fins_tcp_header[7] = (byte) 0x1A; // LUNGHEZZA DAL COMANDO ALLA FINE DEL PACCHETTO fins_tcp_header[8] = (byte) 0x00; // Command fins_tcp_header[9] = (byte) 0x00; fins_tcp_header[10] =(byte) 0x00; fins_tcp_header[11] = (byte) 0x02; fins_tcp_header[12] = (byte) 0x00; // Error Code fins_tcp_header[13] = (byte) 0x00; fins_tcp_header[14] = (byte) 0x00; fins_tcp_header[15] = (byte) 0x00; fins_header[0] = (byte) 0x80; //ICF Information Control Field bit 7 Bridges (allways 1) ohter 0. fins_header[1] = (byte) 0x00; //RSV Reserved 00 Always fins_header[2] = (byte) 0x02; //GCT Gateway Count Ver.2.0 fins_header[3] = (byte) 0x00; //DNA Destination network address 00 fins_header[4] = (byte) 0x01; //DA1 Destination node address Ethernet Node 01 CPU unit fins_header[5] = (byte) 0x00; //DA2 Destination unit address Ethernet 00 CPU unit fins_header[6] = (byte) 0x00; //SNA Source network address 00 fins_header[7] = (byte) 0x02; //SA1 Source node address Fixed to 2. fins_header[8] = (byte) 0x00; //SA2 Source unit address 00 Node 00 PC fins_header[9] = (byte) 0x00; //SID Service ID. 00 to FF fins_cmnd[0] = (byte) 0x01; //MRC Command Code (01,01 read) (01,02 write) fins_cmnd[1] = (byte) 0x01; //SRC Command Code fins_cmnd[2] = (byte) 0x82; //Memory Type: DM fins_cmnd[3] = (byte) 0x00; //start word read (2 byte) - inizio dalla word 142 fins_cmnd[4] = (byte) 0x8C; fins_cmnd[5] = (byte) 0x00; //Bit word fins_cmnd[6] = (byte) 0x00; //quante word (2 byte) - 32 word fins_cmnd[7] = (byte) 0x20; //printSendData(fins_tcp_header); //printSendData(fins_header); //printSendData(fins_cmnd); StampoPacchetto(fins_tcp_header); StampoPacchetto(fins_header); StampoPacchetto(fins_cmnd); try { out_data.write(fins_tcp_header); out_data.write(fins_header); out_data.write(fins_cmnd); } catch (IOException e) { e.printStackTrace(); } } //STAMPO PACCHETTO HEX private static void printSendData(byte [] data) { int j=0; StringBuilder sb = new StringBuilder(); for (byte b : data) { j++; sb.append(String.format("%02X", b)); if (j==4){ sb.append(" "); j=0; } } System.out.println("Send: "+sb.toString()); } //FUNZIONE CHE MI STAMPA I BYTE DI UN PACCHETTO (ARRAY DI BYTE) public static void StampoPacchetto(byte[] data) { for(byte b: data) { // print character System.out.print(b + " "); } System.out.println(" \n"); } public static void main(String[] args) { try { socket = new Socket (HOST,PORT); System.out.println("Connected using IP: "+ socket.getLocalSocketAddress()+" Port: "+socket.getLocalPort()); } catch (IOException e) { e.printStackTrace(); } listenerThread = new Listener (socket); listenerThread.start(); try { out_data = new DataOutputStream(socket.getOutputStream()); } catch (IOException e1) { e1.printStackTrace(); } Connect(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } SendReadFinsCommand(); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } }}Class Listener.java : package com.prova;import java.io.DataInputStream;import java.io.IOException;import java.net.Socket;public class Listener extends Thread { Socket listener; boolean running = false; DataInputStream in_data = null; byte nodeNumber = 0; private void PrintData(byte [] buffer) { int j=0; StringBuilder sb = new StringBuilder(); for (byte b : buffer) { j++; sb.append(String.format("%02X", b)); if (j==4){ sb.append(" "); j=0; } } System.out.println("Receive: "+sb.toString()); } //FUNZIONE CHE MI STAMPA I BYTE DI UN PACCHETTO (ARRAY DI BYTE) public static void StampoPacchetto(byte[] data) { for(byte b: data) { // print character System.out.print(b + " "); } System.out.println(" \n"); } public Listener(Socket listener_socket) { listener = listener_socket; running = true; } public void run(){ while(running) { byte [] received_buffer = new byte [40]; try{ System.out.println("Listening..."); in_data = new DataInputStream(listener.getInputStream()); in_data.read(received_buffer); } catch (IOException e) { e.printStackTrace(); running = false; } StampoPacchetto(received_buffer); if (received_buffer[15] == 0x03) { running = false; try { listener.close(); } catch (IOException e) { e.printStackTrace(); } } } } public void stopListening() { running = false; }}Thanks a lot..
  10. FINS - Connection Problen

    I want to understand the logic of protocol. Can i send directly FINS READ COMMAND after inizializated socket to plc ? Or i have to send SEND FINS/TCP COMMAND after that SEND FINS COMMAND FRAME to read the words ? Thanks.
  11. FINS - Connection Problen

    I don't understand. I want to have a program that simulated PLC Omron with FINS protocol and then i can use my program written in Java to communicate with the simulator. There is a guide to follow for configure PeakHMI ? Thanks.
  12. send FINS command using Java UDP/IP

    Hi guys! There is a way to try this code? Thanks. I have to do the same thing; communicate to omron fins protocol by tcp/ip in java. Before read this post I used DataInputStream,DataOutpurSterean with ByteArrayOuputStream and ByteArrayInputStream with normal socket not datagramsocket. It use correct to use datagramsocket? Help me.. Thanks.
  13. FINS - Connection Problen

    Hi guys! I have a problem to implemented this protocol with Java. I want to read the alarm from word 142 to 172 and I send to PLC this packet: streamOut1.writeByte('F'); // HeaderstreamOut1.writeByte('I');streamOut1.writeByte('N');streamOut1.writeByte('S'); streamOut1.writeInt(26); //lenghtstreamOut1.writeInt(0x02);//cmd = 2streamOut1.writeInt(0x00); // Error Code streamOut2.writeByte(0x80); //ICF Information Control Field bit 7 Bridges (allways 1) ohter 0.streamOut2.writeByte(0x00); //RSV Reserved 00 AlwaysstreamOut2.writeByte(0x02); //GCT Gateway Count Ver.2.0 streamOut2.writeByte(0x00); //DNA Destination network address 00streamOut2.writeByte(0x01); //DA1 Destination node address Ethernet Node 01 CPU unitstreamOut2.writeByte(0x00); //DA2 Destination unit address Ethernet 00 CPU unitstreamOut2.writeByte(0x00); //SNA Source network address 00streamOut2.writeByte(0x03); //SA1 Source node address Fixed to 2.streamOut2.writeByte(0x00); //SA2 Source unit address 00 Node 00 PCstreamOut2.writeByte(0x00); //SID Service ID. 00 to FFstreamOut3.writeByte(mrcCmd); //0x01; //MRC Command Code (01,01 read) (01,02 write)streamOut3.writeByte(srcCmd); //0x01; //SRC Command CodestreamOut3.writeByte(memType); //0x82; //Memory Type: DMstreamOut3.writeByte(start); // the first word that i want to read streamOut3.writeByte(0x00); //start bit streamOut3.writeByte(nWord); //number of word that i want to readThis is the packet that i send to PLC -> 70 73 78 83 0 0 0 26 0 0 0 2 0 0 0 0 -128 0 2 0 1 0 0 3 0 0 1 1 82 -116 0 32 Please help me.. Thanks..
  14. FINS/TCP using Java

    Thanks, it works fine. I'm new in this kind of progrmmation. I want to know something about FINS protocol: In follow your code and create a my project and it is subdivided in: OmronFinsPacket.java that is a class than help me to create tcp_header (byte array - size = 16) ,fins_header (byte array - size = 10) and fins_cmd (byte array - size = 8)OmronFins.java that is the main class that contain some method ( connect,close, writeOmronFinsPacket, readOmronFinsPacket etc ) . In the main I create OmronFins object , call the method and write it into a serverSocket that it receive the OmronFinsPacket and re-send it to the client for control if i write correctly. But now I want to understand how can I test my program? And if i can use an emulator of PLC when i write to PLC OmronFinsPacket, what is the response of PLC ? Thanks.
  15. FINS/TCP using Java

    Good post!