Based on Tim's video's there are a couple of ways to use Reactive coms to establish serial communications. This isn't an issue but rather an interpretation of how to manage a serial communication link.
Reactive Comms is an evolutionally library where there is more than one way to establish communications with serial devices. I wrote this stuff out as I worked through the video examples to understand what the action steps were.
The latest approach I see in the sample videos is using the Factory Channel Method. The following is what I have used to develop a test program to link up the reactive comms in a test program before developing my program.
//in order to create a connection you need
//step 1 is a communications string connectionString = the parameters to configure the factory //instance for serial port this would be com port configuration example
string connectionString= "Com7:9600,None,8,one,NoDTR,NoRTS"
//step 2 need to create a new factory instance using var factory = new ChannelFactory();
// the factory becomes the methodology to hold or create the data link.
var factory = new ChannelFactory();
//step 3. create a channel for the data comm connection will be established where
channel = factory.FromConnectionString(conectionString);
//the FromConnectionString parameter is passed the connectionString for the configuration.
//The older or other method was to use an endpoint for step 3 as the following
var endpoint = DeviceEndpoint.FromConnectionString("Com1");
// or the entry was the connectionString variable.
//Then the channel for step 3 would be created using an Icommunications Interface using
IcommunicationsChannel channel= new SerialCommunicationsChannel(endpoint)
//Step 4 At this point the Serial port is all wired to be opened
//Either approach works At this stage the channel is available to be opened.
//However this step can be completed later in the activity code and not the prep code.
channel.open();
//Step 5 create the observer
// After the channel is created you need a transaction observer
// if you have a sequence of data , which are called observables(t)
// so if you had a string it would Iobservable(string)
// then you have observer which subscribe to those observable strings
// the transaction observer is the observer mechanism
var observer = new TransactionObserver(channel); // need to identify what to watch so pass in channel
//Step 6 create the processor and link the processor to the observer
// Observer is going to view data from this specific channel
// this could be all that is needed to just observe data
// but now you might need to manage a sequence of transaction such as Trans 1, 2,3....n
// you then need a processor to manage the sequence of transactions called a processor.
var processor = new ReactiveTransactionProcessor(); // this defines the processor
processor.SubscribeTransactionObserver(observer); // this links the process to the observer
// Step 7 now to use a transaction to interact with the observer
// If using a terminates string we use
// TerminatedStringTransaction("string command") there are different overrides
// TerminatedStringTransaction("string command", initiator: 'startChar', terminator: 'endChar' )
var transaction = new TerminatedStringTransaction("", initiator: '$', terminator: 'z') { Timeout = TimeSpan.FromSeconds(20) };
//In this instance command to issue out the serial port is "" of blank because this example is using
//a free running time based status packet. So there is no command to issue.
//The timeout just allow the use of the timeout property of the transaction processor
// At this stage the transaction is created
//It is at this stage that a person could create a custom transaction method to handle a different way of managing the data so the var transaction stated would change to
var transaction = new MySerialTransaction("mycommand"){ Timeout = TimeSpan.FromSeconds(10) }
//where there is a method MySerialTransaction( string command) in your class
// step 8 commit the transaction to the processor
// now we need to process the data that was received by the transaction
// so the transaction would send the command string and wait for the responding date
// so we need to use processor to commit the transaction by passing the trasaction into the processor
processor.CommitTransaction(transaction);
transaction.WaitForCompletionOrTimeout();
// this specified to have the transaction wait for period of time or fail
step 9 wait for the response and process the response. use the transaction.Successful and .Response parameters to validate the responses.
if (transaction.Successful && transaction.Response.Any())
{
var response = transaction.Response.Single();
log.Info($"the responses is", response); //using an Nlog info capability and ready for any required parsing capabilities
}
Todd Benko