Injector Components - How to create your own

A forum where Flowcode v6 user created components can be shared, discussed and reviewed.

Moderator: Benj

User avatar
Matrix Staff
Posts: 14566
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4596 times
Been thanked: 4239 times

Injector Components - How to create your own

Postby Benj » Fri Aug 23, 2013 5:12 pm

An Injector component is a component that works with a communications component (e.g. RS232, SPI, I2C) and adds a simulation only method to parse the incoming data to provide meaningful outgoing data.

An example of this is the GPS Injector which uses it's properties to generate a recurring stream of bytes which can then be parsed using the GPS component or any other injector enabled component such as RS232.

Another example is the AT Injector which basically waits for an incoming carriage return and then spits out an approximation of what the real return string would be.

Input: AT\n
Output: AT\nOK\n

Each injector deals only in bytes so the comms component makes what it will of this.

I have started to put together a DS1307 injector which provides the functionality of a real time clock and a few bytes of RAM.

Here is the breakdown of the component so you can see what it is doing and then hopefully be able to edit and regenerate to allow any type of component injector to be made.

Main Macros.

Main - Component test routine, this code will not make it into the exported component so use this place as a space to test out the component before export.

TxByte - Stores the incoming byte into the incoming circular buffer. This macro should detect an event to then parse the incoming data as a command. In the AT component we run the parse command macro when we receive a carriage return. In the example we run the parse macro when the "Stop" bytes have been received.

ParseCommand - Runs through the data in the incoming circular buffer and calls the AddReturn macros to populate any data into the outgoing circular buffer.

AddReturnByte - Adds a single byte into the outgoing circular buffer.

AddReturnString - As above but with an array of bytes.

RxByte - Pulls out the oldest value from the outgoing circular buffer so the comms component can collect it.


The console data is automatically populated via the TxByte and RxByte macros so this should be mostly taken care of for you. The Ev_Initialise macro calls the InitialiseInjector macro which sets up the console window and handle. The only thing to look out for is the console mode, the AT uses a text mode and the DS1307 uses a byte mode to allow the contents of the RAM to be easily available. The Communications component provides the high level console so the injector console can be a bit lower level if need be.

Injector Interface

To get new injectors to appear in the Injector selection property on the comms components you need to make sure that the component name in the settings manager is set to "InjectorXXXX" where XXXX is the customisable name of the injector. When creating a new injector component you will need to assign a new component GUID by going into the advanced tab of the setting manager and then clicking Edit and New.

Confused yet? Look at the examples below, they show the source for the DS1307 component and the AT component. These are really an advanced feature and it is not our intent that everyone should be able to write these, however they should be usable by pretty much anyone. It would be great if we can build up a library of supported simulation devices for the release and then beyond.

Also there are bound to be bugs especially in the DS1307 component which I have rushed a bit to get it out. Hopefully we can work on the these and get any major bugs or headaches ironed out.

I suggest anyone attempting this first goes through the component creation example on the Wiki as these go into a lot more detail then is covered here.

Exported Component Updates (since patchset 2)
(202.1 KiB) Downloaded 407 times

Injector Component Source Files
(95.75 KiB) Downloaded 382 times
These users thanked the author Benj for the post (total 4):
kersing (Fri Aug 23, 2013 5:25 pm) • medelec35 (Fri Aug 23, 2013 5:36 pm) • dazz (Fri Aug 23, 2013 7:03 pm) • Jordy101091 (Fri Aug 23, 2013 7:21 pm)
Rating: 21.05%

User avatar
Posts: 519
Joined: Sat Jan 08, 2011 4:02 pm
Location: The Netherlands
Has thanked: 27 times
Been thanked: 190 times

Re: Injector Components - How to create your own

Postby Jordy101091 » Fri Aug 23, 2013 7:40 pm

What!! I thought this would be easy to understand, Whow but this, this is just to hard for me to understand in one night.
I think that I really need to get a cop of coffee some nice crackers and begin to study this because its so much to learn.

It's difficult to ask you ben because you put allot of work into creating this, but could you explain what you're doing here, did you wave with you magic want ore something.

Anyway I hop that I can understand this and start creating some nice components.

Regards Jordy
These users thanked the author Jordy101091 for the post:
Benj (Sat Aug 24, 2013 3:52 pm)
Rating: 5.26%
the will to learn, should not be stopped by any price

User avatar
Matrix Staff
Posts: 14566
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4596 times
Been thanked: 4239 times

Re: Injector Components - How to create your own

Postby Benj » Sat Aug 24, 2013 3:50 pm

Hi Jordy,

I always keep my magic wand handy for situations like this :wink:

I have basically been knee deep in creating/porting components in v6 pretty much full time for the last few months and trust me once you know what your doing it does get easier and you really start to see the potential. The 3D printer component pretty much dropped out in an afternoon and then one I had a maze algorithm working I could print actual 3D mazes. This means that it's hard for me to know which features I need to explain more clearly.

I could create a video to try and explain the functionality a bit more if that would help?
Edit now available from here: viewtopic.php?f=57&t=12735&p=50991#p50991

The I2C component is especially difficult as I can only currently send and receive bytes so the I2C commands start, stop, restart had to be sent as text and I had to go a long way to try and ensure that incoming data was not misinterpreted as a state change and visa versa. Maybe it would be much easier if I added a state change macro instead which then also allows for things like CS on the SPI to be implemented much simpler. The AT example should be much simpler to understand as is but is still not straightforward, especially if you are unfamiliar with circular buffer techniques.

Now that I have thought of this StateChange addition I will have a crack at getting it added and see if it helps with the overall simplicity. My job is to make this as simple as possible to use and develop your own things so please feel free to give your honest thoughts, I won't be offended I promise :D