Send commands/data between a computer and Arduino via serial.

How would I go about implementing a system that would allow me to send commands to an Arduino from a PC via serial that would allow me to toggle io and retrieve data?

Lets say Java for the PC side, I would need to be able to call a method like toggle(pin); or digitalWrite(pin, value); and a method such as retrieveData("nameOfData") and have it return an object of the data type.

any help is appreciated.

You might take a look at Firmata, which was designed for doing this:

It has a Java client library, as well as many other programming languages.

Arcratist:
Lets say Java for the PC side, I would need to be able to call a method like toggle(pin); or digitalWrite(pin, value); and a method such as retrieveData("nameOfData") and have it return an object of the data type.

I reckon you should adopt different approaches to this depending on whether you want {A} a general solution that can be used by several PC programs for different purposes or {B} a solution for a specific project in which the PC code and the Arduino code can be tailored to that project.

The single project approach would be simpler and this Simple Python - Arduino demo should give you some ideas. The same concepts can be implemented in any other PC programming language.

Also have a look at the examples in Serial Input Basics - simple reliable ways to receive data. There is also a parse example to illustrate how to extract numbers from the received text.

The technique in the 3rd example will be the most reliable. It is what I use for Arduino to Arduino and Arduino to PC communication.

You can send data in a compatible format with code like this (or the equivalent in any other programming language)

Serial.print('<'); // start marker
Serial.print(value1);
Serial.print(','); // comma separator
Serial.print(value2);
Serial.println('>'); // end marker

I recommend that you design your system to do as much as possible of the hard work on the PC and make life as simple as possible for the Arduino.

...R

What sort of application/control is your goal? Is the arduino your main control and you will use the pc as your user interface? I've made a sort of hmi/scada app for communication with a MEGA board. Maybe it is usefull for your goal... https://www.jbsiemonsma.nl

processing a great language and programming environment based on java. It's really easy to use alongside arduino. now It's not build for extremely complex programs (even though you can definitely do that). but i can highly recommend it, especially if you're starting off.