Reading and displaying values read from arduino to windows interface

Hi all I have a project to read an analog input from an arduino and display it in a windows interface the interface will communicate with pc serial port. I did this using a Mitsubishi Plc and in this case to read a specific value a hexadecimal package should be sent to the plc then this latter sends a hexadecimal value that will be read, converted and displayed on a pc interface. My problem is what is the structure of this package in arduino(if it exists) Is there any documentation about this????

My problem is what is the structure of this package in arduino

Can you please give more details of the "package" to which you refer ?

I mean the following: in the case of a plc,to read a specific data we need to send a package of this structure: 02 045 ......03XX Where 02 is the start transmission char 03 is the end transmission char and xx is the check sum. The returned value from the plc is then sent from the plc to the windows software. Is it the same case in arduino? How can we ask arduino to send a value to windows software to display it??

Thanks very much i will try this

Madani: I mean the following: in the case of a plc,to read a specific data we need to send a package of this structure: 02 045 ......03XX Where 02 is the start transmission char 03 is the end transmission char and xx is the check sum. The returned value from the plc is then sent from the plc to the windows software. Is it the same case in arduino? How can we ask arduino to send a value to windows software to display it??

This is rather confusing.

Do you mean that your PC sends "02 045 ......03XX" TO the PLC and the PLC then responds? You have not told us anything about the data in the response message.

Do you mean that you want to write an Arduino program that also responds to that message and sends back data that the PC thinks has come from the PLC?

Or do you mean that you have a completely free hand to design a system in which a PC program sends a message of your design to an Arduino which also responds with a message of your own design.

Either should be possible.

For the latter this Python - Arduino demo may give you some ideas.

...R

In the project i did with the plc, i wrote aplc program that the plc is execution in a loop and an other software witch is upposed to act as an HMI develloped with Delphi. This kind of commands are made to activate some internal relayx in the plc or to ask for a specific value that the plc sends to the pc in a haxa decimal format the general syntax is 02xxxx03aa the data are the xxxx value. Actually the thing i want is: make arduino read analog data and send them to the interface where they will be displayed

If you are trying to establish communication with a Mitsubishi PLC, I would recommend either capturing the communication from your existing setup (with the Windows PC) (if that does exist) -OR- have a look at the Communication Protocol Reference manual.

http://dl.mitsubishielectric.com/dl/fa/document/manual/plc/sh080008/sh080008w.pdf

Unless you need compatibility with the PC application that communicates with the PLC, I suggest that you read Robin2's Serial Input Basics - updated and apply the principles in there. I'm aware that you're sending from the Arduino, but the principles stay the same.

Else you have to be very clear in your description; the numbers (not characters) 2 and 3 are defined in the ascii table. This will basically imply that you were transferring text from the PLC and not binary data.

I've done a fair bit of communication with PLC's and it is most certainly a binary 2 (0x02 STX) and not a textual "2"

Madani: Actually the thing i want is: make arduino read analog data and send them to the interface where they will be displayed

It is still not clear to me if you want the Arduino to emulate a PLC or not. And that seems to be the key piece of this jigsaw.

...R

In the case mitsubishi Plc the Stx corresponds to 02 and ETX corresponds to 03 ofcourse all data ara written in Hexa decimal and translated according to an ASCII code table. Any way if you wish we can discuss about this in an other topic. Indeed i want to do the same thing with the arduino pc sends a request to arduino and arduino replys by sending values to pc. The values i want to read are current values from analog inputs. The read values will be sent to pc whitch displays the result. The pc will play the role of an HMI.

How about reading the analogRead reference? Comes woth example that reads an analog pin and sends the info to the pc.

If you're going to use an Arduino, what do you need the plc translating to the PC for? Ditch the plc, go direct between Arduino and PC. You made the plc, you know the PC side of it.

Arduino Uno can run USB to PC as a COM port up to 250000 baud. That is 40 microseconds per char serial.

Arduino Uno is capable of doing 1 or more useful things in that time, 640 cpu cycles worth. It can translate text into data faster than that. It can index through tables and follow binary tree links faster than that. It is capable of doing what the plc does as long as connect through USB is not a problem.

OTOH, can the plc run an ADC chip?

Madani: In the case mitsubishi Plc the Stx corresponds to 02 and ETX corresponds to 03 ofcourse all data ara written in Hexa decimal and translated according to an ASCII code table. Any way if you wish we can discuss about this in an other topic. Indeed i want to do the same thing with the arduino pc sends a request to arduino and arduino replys by sending values to pc. The values i want to read are current values from analog inputs. The read values will be sent to pc whitch displays the result. The pc will play the role of an HMI.

Yes, those are ASCII escape codes used to handshake data and mark clear begins and ends. In your case the middle is binary data, not text. If you send integer data, it's stored low byte to high byte order in RAM and the bits are low to high.... but you can read high to low and swap the bits in 8 cycles.

Arduino analog read returns an integer, 0 to 1023. Does that need to get turned into something else? Not a problem. Worse case, you make a lookup table with 1024 2-byte binary values in flash and read them off a byte at a time to the PC. Reading a byte in flash takes 3 cycles, we have 640, that is worst case. Si?

Madani: Indeed i want to do the same thing with the arduino pc sends a request to arduino and arduino replys by sending values to pc.

You are still managing to be unclear.

It is perfectly possible to do what is described in the piece I have quoted without knowing anything at all about PLCs. In fact it would not be particularly difficult. This Python - Arduino demo could get you started.

However if you want to create a system in which your PC talks to the Arduino thinking that it is talking to a specific PLC things will be a bit more complicated.

Which do you want?

...R

Robin2: However if you want to create a system in which your PC talks to the Arduino thinking that it is talking to a specific PLC things will be a bit more complicated.

But it should be a lot easier if you are the person who programmed the PLC.

GoForSmoke: But it should be a lot easier if you are the person who programmed the PLC.

Of course. But first we need to get the OP to tell us what he actually wants to do. :)

...r

Without details the OP wants to read analog input and send it to the PC through a PLC , we're not informed of the PLC-PC connection but the OP is intimate with it.

I suggested using the same board that reads the analog might also connect with the PC.

The message packet format, STX byte byte byte ... byte ETX chksum is standard protocol. It's what the OP wants help getting the Arduino to send properly. The data bytes are the analog read data in some binay format, possibly raw ints in low-high byte order. The PLC is described as running a state machine to read, process and send on to the PC but again, scant details.

GoForSmoke: The message packet format, STX byte byte byte ... byte ETX chksum is standard protocol. It's what the OP wants help getting the Arduino to send properly.

I am not convinced that it is, although it might be.

From some of the things he has said I got the impression he just wants to do with a PC and Arduino what is also possible with a PC and a PLC. That could be done very simply without any need for the special codes required by the PLC.

But I have tried a few times to get him to say which he needs.

...R

I'm also not so sure that OP wants to implement that PLC protocol.