It’s been a while since I wrote anything about this project, but I have been working hard on my Parker Controller library over the last few weeks. There were several goals I had in mind for this project before I even laid down any code, and I think I was able to get most of them knocked out.

The biggest goal I think, was to make a library that was easy to import into any existing project that required a Serial connection, and just Go. Add a few commands to set up the connection, and away you could go! Another large goal was to control how the library was used. I didn’t want to create something that was limited specifically to a Parker controller; And in addition to that, I may or may not want to use certain modules. So, a lot of work went into the theory of the library and I think its working out pretty good so far.

The last time I used a libraryy similar to this was in my old CNC bender projects such as FlexIO, so compared to those original versions, here is a list of key feature changes I made to improve the library for new projects in the future:

  • The library is now completely independent of any existing code, and can be added to an existing project with just a few simple commands, see the example code below in this post.
  • Several defines during compilation determine which parts of the library are used by your app. See Below for more specifics.
  • The following key features are present in this library, some of which are controlled by defines:
    • The base connection & setup code are contained exclusively within the defined object. There is Zero global code required.
    • The library is capable of declaring and using MULTIPLE serial objects at the same time. Yes, you are thinking correctly. It is now possible to connect to MULTIPLE connections at exactly the same time. This means that if you need more than 4 axis, or more inputs, it is more than possible to spread this out across more than one controller. You just have to adapt your project to compensate for it!
    • The library has a built-in Serial interpreter and text processing system. You can turn this off if you don’t want to use it, but it gives you a system for processing received text commands from the connection. This isn’t just limited to Parker stuff either, it works perfectly fine on any type of Serial connection. You can specify how many commands are stored internally at any time, as well as access to a number of different way of reading and interpreting those commands. Received commands are defined by text sent back from the controller with a Newline character; If the character has not been received, the data is left on the processor until one is received (and as a result, prevents mangled responses if they are only partially received from the port at the time it queries for data). If you choose not to use it, its easy to add your own code to handle this by yourself and use the built-in commands to extract the necessary data from the serial port for use in your own interpreter.
    • Custom logging options, so you can output problems and data from the connection to log files.

The following is an example of some code for a typical Serial object:

// The object is created in code anywhere you like, or in your app class
// Header as a global object. Its entirely up to you. You can also define
// Multiple objects individually or in an array.
DexSerialPort  ComPort;

// Clear out any previous settings that might get in the way
MyProject::ComPort.Clear();

// Set up the Connection. We can specify a unique Logfile ID to use for
// Each connection, along with a unique name for the connection. If 
// Multiple connections use the same log, this name will help identify
// Where messages come from.
MyProject::ComPort.SetDexLoggerID(LOG_FILE_SERIALPORT);
MyProject::ComPort.SetConnectionName("Parker 6K6");

// Set standard connection parameters for COM3
MyProject::ComPort.SetCOMPortNumber(3);
MyProject::ComPort.SetBaudRate(9600);

// Are we using the built-in command parser and processor?
#if defined(DEX_USE_SERIAL_INTERPRETER)
// We can specify how many commands are stored from the controller
// At any one time.
MyProject::ComPort.SetCommandBufferSize(150);
#else
// The project will assume you are using your own interpreter for
// Serial Port responses and let you handle it in our own way.
#endif

// Attempt to make a connection to the device
bool ConnectResult = StrutterObject::ComPort.OpenCOMPort();

// Did we connect OK?
if (ConnectResult == true) {
	// The connection was successful!! Show the About page for the 
	// Controller (about 40 lines of info)
	Strutter.ComPort.SendSerialCommand("HELP:");
}

// We can also check at any time to make sure the controller is 
// Online via code checks.
if (MyProject::ComPort.IsControllerOnline() == true) {
	// Here you can do something that our project requires!
	// Let's see if any data exists on the port for reading!

#if defined(DEX_USE_SERIAL_INTERPRETER)
	// Query the port, do a Send/Receive of anything in the buffers
	MyProject::ComPort.ProcessDataExchange();

	// Do we have any commands currently stored in the command buffer?
	uWord CommandsReceived = MyProject::ComPort.GetReceivedCommandCount();

	// Do we have anything stored?
	if (CommandsReceived > 0) {
		// At least one command is available in the command buffer
		for (uWord ShowCommands = 0; ShowCommands < CommandsReceived; ShowCommands++) {
			// Get a char version of the received command. There are many
			// Other ways to recover and interact with the commands.
			// With a received command, your code can process the response
			// Accordingly, but we will just dump them to the log here.
			dbgmsg("Command Received: '%s'", 
				MyProject::ComPort.GetReceivedCommandAsString(ShowCommands);
		}
	}

	// After all commands have been processed, empty the buffer completely
	// Before querying for the next set of received commands.
	MyProject::ComPort.ClearReceivedCommandBuffers();
#endif
}

// Finished using the port?
MyProject::ComPort.CloseCOMPort();

Example screenshot of a sample communication tool for any Serial connection (we used a 6K6 in this example):

Whats Next For This Library?

Im not sure! I want to keep working with this as it has been bugging my mind for a really long time. There were so many unfinished things on prior projects that I wanted to close this chapter. Then, I might work on a routing table or something similar. Until the next time! Feel free to leave any comments or questions below!