How to connect java with plc data - java

I have a new project about plc (siemens), but I dont know how they work.
What I have to do, is by given some data from the plc I have to handle the data and to display it on a simple GUI.
The PLC (I dont know if there are different types) that I have to use is a "proximity sensor" which only capture if something is infront of it, then it hasto send some data to my program in Java and then I have to display it on the GUI (Basically some red or green circles)
I dont have to handle the behavior of the PLC, I just have to do display a red or green circle by given the data from the PLC
Questions:
I thought of Java because I know that is a powerful language, but is it the best for what I have to do?
Second if Java is the best choice, are there any librarys for working with PLC?
Third... I started to read something about some languages like:
Functional Block Diagram (FBD)
What are they for?

"The PLC(...) that I have to use is a "proximity sensor" which only capture something in front of it."
Do you mean to state here that you are connecting a proximity sensor to a PLC, reading the data from the PLC and back to your UI program OR do you want to read the proximity sensor directly back to your UI program?
If it’s the latter connect your sensor to a microcontroller and then send the data serially to your computer.
If you are using a PLC you will need some interface card (i.e. digital or analogue). Connect your sensor to the applicable card. If you want to read an S7 PLC you will need a library - libnodave is a good one.
If you are using a library like libnodave you will need to use ones of its supported languages - it includes Java but you can also use others e.g. C. You could also use Snap7.
FBD is one of the IEC61131-3 programming languages - see:
http://www.automation.com/pdf_articles/IEC_Programming_Thayer_L.pdf

The PLC should have an RS232/485 interface. All communications happen via serial communications. Java does have the Java Communications API, But before you go down that path, What is the computer that would be interfacing with the PLC device - A low power ARM SBC or a x86 PC ? The downsides of using Java is the footprint related to the JDK. If it were me, I'd stick to C/ Rust or GoLang based on the constraints of the platform.

To communicate with a Siemens plc you could use a few different options based on the exact type of PLC that you use.
A few communication protocols supported by Siemens:
opc: the industry standard for communication between PLC and other devices
libary like Snap7 http://snap7.sourceforge.net/ which has lots of supported programming languages
for the programming language you can use Java but as alternative you could use C# or vb.net in cooperation with Visual Studio for creating a simple GUI.
If you need any further information please let me know.

i had similar problem and this is how i sorted it out:
Communication protocol that most PLCs are using are either modbus, bacnet, lonworks and milion others. In your case , i assume that Siemens uses modbus.
Firstly you neet the Rs485 to usb adapter (arround 20Eur on Amazon)
you have to read registers from modbus - please use easyModbus api
This approach works fine but it is not happening in the real time as the modbus communication could run in separate threads.

This depends on the application that you want to design, if the application is based on the web, it is better to use a easymodbus TCP that sends data through TCP connection, and if you want a desktop application, it is better to use Easy Modbus RTU that Using RS485, this library it's the best.
http://easymodbustcp.net/en/
I Recommended to use this library it's also for future (Smart Phone, Desktop and Web Application using Spring Boot MVC).

Related

Using Java to send data to arduino sketch

I'm new into arduino programming and robotics, and I want to use Java to send data to the arduino sketch, to notify it when to use the robots motors. In particular, I have already written a working A* algorithm in Java and would really like to apply this to my arduino robot, so in my java code, when the best state is found, I want to then send data to arduino sketch to notify it what direction to go. Anyone have and ideas as to the best way? I've looked online but haven't anything that really answers this specific question.
Also, I realize I'll need to have the arduino connected via USB to use Java, but for now I'm fine with it
You are going to need JAVA USB API in order to send the data to the USB port where your Arduino is connected. From there you just read the input in your Arduino sketch and you are done.
You can also use a Java Serial Port library (like jssc).
Personally I use Processing (which uses Java) and it's quite easy to do Serial communication with the serial library it ships with.
Check out the SimpleWrite example (which includes example Processing-java code and Arduino code)

How to communicate with a device?

I am a web programmer and I am just wondering how software and hardware can communicate. I have basic knowledge in Java but I am not an expert.
Let's make it simple. I have a device which is just a simple lamp that can get switched on and off and it is connected via USB. My software has only one function - pressing enter.
By pressing enter I want the software to communicate with the USB port and tell it to activate the device. How would that be possible? Where do I have to start and what do I need to learn?
I understand that my question and my example sound silly but I am just trying to understand how it works.
I appreciate any help!
I think that if you using arduino or other prototyping board you might use rxtx serial library.
If I answer simply, then I should tell, you need to have microcontroller to do this by your own.
A microcontroller is a small computer on a single integrated circuit. A microcontroller contains one or more CPUs (processor cores) along with memory and programmable input/output peripherals. So, there are input, output pins for different operations you want to do with your physical hardware and also a memory to store the commands or program. That means a microcontroller is a third party which keeps communication active between the hardware and software in this case.
In the market, you can find many microcontroller integrated boards for building digital devices and interactive objects that can sense and control objects in the physical world.
To make your work easy as a beginner, I suggest you to buy an arduino board from the market. If you google it and search for arduino tutorials in youtube, you will find how they work. Hope these help you.

Combining Java + bluetooth + arduino

Today i came up with an idea to controle a arduino board or any other micro controller wirelessly using a java program. Im somewhat of an intermediate java programmer, meaning i can make basic applications. I know next to nothing about arduino, or the programming of microcontrollers in general, and i dont want to start to learn until i know i can link java with arduino, meaning running a program on the computer that, lets say, turn on a led. Ive done some research, and thats where i got the bluetooth from, but it seemed like the only videos were in spanish, and not much documentation about it, as far as i can see. I was just wondering how easy is it to link these two, is it possible, any links to tutorials of sorts, thanks. P.S. it doesn't have to be arduino, im just familier with that name, im just interested in controlling something physical through a java app, thanks.
Yes you can,
If you can program in java you will find arduino fairly easy but here is a arduino based tutorial with all the code your need:
http://playground.arduino.cc/Learning/Tutorial01#.UxClcvl_tFs
A majority of bluetooth modules will spit out serial data and this simply interacts with the RX/Tx (receive/transmit) inputs of the arduino. They are usually configured to standard board rates mainly 9600 to start.
All you have to do is spit a string out via bluetooth, an java based bluetooth example is below but you can also find bluetooth modules for PC that interact and install as a CDC (serial port).
Sending a string via bluetooth from a PC as client to a mobile as server.
Serial ports are a little easyier :)
http://www.java2s.com/Code/Java/Development-Class/COM-Port.htm
Cheers,
Chris

Easiest way to establish data communication from Android to a Eclipse program with WLAN

Now, I have some problems here:
I looked several times in Google and so on, but I can't find an "easy" way to get this done. And currently having a migraine... not helping me... though
I have a java eclipse program (Swing application to be a "controller" for production-machines).
I need to design an Android app, which needs to take data from the eclipse program in a wireless network (and also send them back).
Just found solutions like JPARSON or setting up a real server, but that is way too complicated... i don´t need?! (or want :D ) to set up a whole website with php or something...
Can someone of you help me out with a better solution? It doesn't need to be code-specific, I just want to exchange like 10 strings for these machines.
If you want to exchange data you need a communication medium. The easiest way to do this is via TCP/IP protocol suite. If you decide on having a Server-Client architecture, your serwer has to listen for what phones have to say. He can do this by listening on specified port and you would have to handle "protocol", or you can use somewhat easier approach which is to write php script, or Java Servlet. PHP script is easier becaouse there is like a gazzilion php hosting providers and it's cheap. If you would like to write your own serwer, you wold need some sort of Virtual Private Server, and deploy your app there. Plus it would be helpfull if you explained a little more your environment and what you are trying to achive.
There's built in httpserver http://docs.oracle.com/javase/6/docs/jre/api/net/httpserver/spec/index.html so you can easily implement a simple webservice in standalone java. Then just use URLConnection from android to post/get data, probably in json or your own format.

Make a USB Device, Control It In Java

I'm thinking about making a physical controller (device?) with knobs, buttons, and LEDs. I'd like to interact with it using Java (respond to the knobs, light up LEDs, etc). The reason I mention Java is two-fold: first, I know Java well1. Second, I've written the rest of the program I need to interface with in Java (though there are ways to talk to the Java program from another language).
I would like the device to connect via USB and be (computer-)platform independent.
I haven't the slightest idea of where to start, except to start reading the Arduino website. Is this my best/only option? Is there something better suited for communicating with Java?
Note: I know that Arduino has something to do with Java (not sure what), but it seems like code must be written in a subset of C.
How would I get moving on this topic?
1 - No laughter, please.
The Arduino development environment is written in Java.
But the standard language you write a program for the Arduino platform is effectively C++.
The Arduino platform is based on an Atmel AVR chip. There is at least one Java VM for AVR chips. There are other languages available for the AVR such as Forth and BASIC (although I could only find commercial versions, so I'll if you want to find them, search for "AVR BASIC").
The Arduino uses a virtual COM port to communicate between the host computer and it. A virtual COM port emulates an old style serial line but is done with USB. You can use the Java communication API to then have a Java program running on the host computer communicate with your physical device.
For some encoders and buttons, you probably want to implement a USB HID device. If you're going to produce more than a couple of them, you'll want to do a custom board. Check out V-USB, an open-source library for making USB HID devices using Atmel microcontrollers. They have a bunch of examples of projects that use this library.
You could probably make this look like a HID joystick, using the encoders to produce X/Y axis information and having the buttons act like buttons. They you could use standard Java gaming APIs to read the joystick values.
Can you expand on your need for a custom device? It seems to me that designing hardware has a pretty high barrier to entry and that most applications I can think of would be better resolved by repurposing an existing piece of game controller hardware. If you really need new hardware, then i suggest you start by googling 'USB development kit' or
'USB development board' which will get you links like this, this and this.
As for working with USB hardware from Java, I've played around with the JUSB library a bit and it looks promising, but appears to be limited to Linux only because the Windows version of the native library half of the library hasn't been written. Alternatives can by found by googling 'HID java'.
Ok, computer-platform independant? What platforms are you targetting? That would depend on the driver and support for that said platform, what does the usb device do? Is it a mass storage device...You may have to look around and see if you can find a device driver that can talk to the device...
Hope this helps,
Best regards,
Tom.
I know for the serial port there were libraries that existed for interacting with it (rs232 library). Googling for java and USB returned several answers (the first was called jUSB). That would be the first type of thing I would be looking for.
sample for java usb connection to freescale microcontroller:
http://javausbapi.blogspot.com/

Categories

Resources